KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dom4j > xpath > TestObject


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: TestObject.java,v 1.1 2003/07/07 10:30:30 per_nyfelt Exp $
8  */

9
10 package test.dom4j.xpath;
11
12 import junit.framework.Test;
13 import junit.framework.TestSuite;
14 import junit.textui.TestRunner;
15 import org.dom4j.Node;
16 import org.dom4j.XPath;
17 import test.dom4j.AbstractTestCase;
18
19 /** Test harness for numeric XPath expressions
20   *
21   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
22   * @version $Revision: 1.1 $
23   */

24 public class TestObject extends AbstractTestCase {
25
26     protected static boolean VERBOSE = true;
27
28     protected static String JavaDoc[] paths = {
29         "name(/.)",
30         "name()"
31     };
32
33
34     public static void main( String JavaDoc[] args ) {
35         TestRunner.run( suite() );
36     }
37
38     public static Test suite() {
39         return new TestSuite( TestObject.class );
40     }
41
42     public TestObject(String JavaDoc name) {
43         super(name);
44     }
45
46     // Test case(s)
47
//-------------------------------------------------------------------------
48
public void testXPaths() throws Exception JavaDoc {
49         Node element = document.selectSingleNode( "//author" );
50         int size = paths.length;
51         for ( int i = 0; i < size; i++ ) {
52             testXPath( document, paths[i] );
53             testXPath( element, paths[i] );
54         }
55     }
56
57     // Implementation methods
58
//-------------------------------------------------------------------------
59
protected void testXPath(Node node, String JavaDoc xpathText) {
60         XPath xpath = node.createXPath( xpathText );
61         Object JavaDoc object = xpath.evaluate( node );
62
63         log( "Searched path: " + xpath + " found: " + object );
64
65         if ( VERBOSE ) {
66             log( " xpath: " + xpath );
67             log( " for: " + node );
68         }
69     }
70 }
71
72
73
74
75 /*
76  * Redistribution and use of this software and associated documentation
77  * ("Software"), with or without modification, are permitted provided
78  * that the following conditions are met:
79  *
80  * 1. Redistributions of source code must retain copyright
81  * statements and notices. Redistributions must also contain a
82  * copy of this document.
83  *
84  * 2. Redistributions in binary form must reproduce the
85  * above copyright notice, this list of conditions and the
86  * following disclaimer in the documentation and/or other
87  * materials provided with the distribution.
88  *
89  * 3. The name "DOM4J" must not be used to endorse or promote
90  * products derived from this Software without prior written
91  * permission of MetaStuff, Ltd. For written permission,
92  * please contact dom4j-info@metastuff.com.
93  *
94  * 4. Products derived from this Software may not be called "DOM4J"
95  * nor may "DOM4J" appear in their names without prior written
96  * permission of MetaStuff, Ltd. DOM4J is a registered
97  * trademark of MetaStuff, Ltd.
98  *
99  * 5. Due credit should be given to the DOM4J Project
100  * (http://dom4j.org/).
101  *
102  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
103  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
104  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
105  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
106  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
107  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
108  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
109  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
110  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
111  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
112  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
113  * OF THE POSSIBILITY OF SUCH DAMAGE.
114  *
115  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
116  *
117  * $Id: TestObject.java,v 1.1 2003/07/07 10:30:30 per_nyfelt Exp $
118  */

119
Popular Tags