KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dom4j > rule > TestPriority


1 /*
2  * Copyright 2001 (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.1 2003/07/07 10:30:30 per_nyfelt Exp $
8  */

9
10 package test.dom4j.rule;
11
12 import junit.framework.Test;
13 import junit.framework.TestCase;
14 import junit.framework.TestSuite;
15 import junit.textui.TestRunner;
16 import org.dom4j.DocumentFactory;
17 import org.dom4j.rule.Pattern;
18
19 /** Tests the priority behaviour of Pattern.
20   *
21   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
22   * @version $Revision: 1.1 $
23   */

24 public class TestPriority extends TestCase
25 {
26     public TestPriority(String JavaDoc name) {
27         super( name );
28     }
29
30     public static void main(String JavaDoc[] 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 JavaDoc {
39         testPriority( "foo", 0 );
40     }
41
42     public void testQNameNode() throws Exception JavaDoc {
43         //testPriority( "foo:bar", 0 );
44
}
45
46     public void testFilter() throws Exception JavaDoc {
47         testPriority( "foo[@id='123']", 0.5 );
48     }
49
50     public void testURI() throws Exception JavaDoc {
51         testPriority( "foo:*", -0.25);
52     }
53
54     public void testAnyNode() throws Exception JavaDoc {
55         testPriority( "*", -0.5 );
56     }
57
58     protected void testPriority(String JavaDoc expr, double priority) throws Exception JavaDoc {
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 JavaDoc(priority), new Double JavaDoc(d) );
68     }
69 }
70
Popular Tags