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