1   /*
2    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
3    *
4    * This software is open source.
5    * See the bottom of this file for the licence.
6    *
7    * $Id: TestPriority.java,v 1.3 2004/06/25 08:03:50 maartenc Exp $
8    */
9   
10  package org.dom4j.rule;
11  
12  import junit.framework.Test;
13  import junit.framework.TestCase;
14  import junit.framework.TestSuite;
15  import junit.textui.TestRunner;
16  
17  import org.dom4j.DocumentFactory;
18  
19  /*** Tests the priority behaviour of Pattern.
20    *
21    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
22    * @version $Revision: 1.3 $
23    */
24  public class TestPriority extends TestCase
25  {
26      public TestPriority(String name) {
27          super( name );
28      }
29      
30      public static void main(String[] args) {
31          TestRunner.run( suite() );
32      }
33      
34      public static Test suite() {
35          return new TestSuite( TestPriority.class );
36      }
37      
38      public void testNameNode() throws Exception {
39          testPriority( "foo", 0 );
40      }
41      
42      public void testQNameNode() throws Exception {
43          //testPriority( "foo:bar", 0 );
44      }
45      
46      public void testFilter() throws Exception {
47          testPriority( "foo[@id='123']", 0.5 );
48      }
49      
50      public void testURI() throws Exception {
51          testPriority( "foo:*", -0.25);
52      }
53      
54      public void testAnyNode() throws Exception {
55          testPriority( "*", -0.5 );
56      }
57      
58      protected void testPriority(String expr, double priority) throws Exception {
59          System.out.println( "parsing: " + expr );
60          
61          Pattern pattern = DocumentFactory.getInstance().createPattern( expr );
62          double d = pattern.getPriority();
63          
64          System.out.println( "expr: " + expr + " has priority: " + d );
65          System.out.println( "pattern: " + pattern );
66          
67          assertEquals( "expr: " + expr, new Double(priority), new Double(d) );
68      }
69  }
70  
71  
72  
73  
74  /*
75   * Redistribution and use of this software and associated documentation
76   * ("Software"), with or without modification, are permitted provided
77   * that the following conditions are met:
78   *
79   * 1. Redistributions of source code must retain copyright
80   *    statements and notices.  Redistributions must also contain a
81   *    copy of this document.
82   *
83   * 2. Redistributions in binary form must reproduce the
84   *    above copyright notice, this list of conditions and the
85   *    following disclaimer in the documentation and/or other
86   *    materials provided with the distribution.
87   *
88   * 3. The name "DOM4J" must not be used to endorse or promote
89   *    products derived from this Software without prior written
90   *    permission of MetaStuff, Ltd.  For written permission,
91   *    please contact dom4j-info@metastuff.com.
92   *
93   * 4. Products derived from this Software may not be called "DOM4J"
94   *    nor may "DOM4J" appear in their names without prior written
95   *    permission of MetaStuff, Ltd. DOM4J is a registered
96   *    trademark of MetaStuff, Ltd.
97   *
98   * 5. Due credit should be given to the DOM4J Project - 
99   *    http://www.dom4j.org
100  *
101  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
102  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
103  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
104  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
105  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
106  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
107  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
108  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
109  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
110  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
111  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
112  * OF THE POSSIBILITY OF SUCH DAMAGE.
113  *
114  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
115  *
116  * $Id: TestPriority.java,v 1.3 2004/06/25 08:03:50 maartenc Exp $
117  */