KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestBoolean.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 org.ozoneDB.xml.dom4j.O3DocumentHelper;
18 import test.dom4j.AbstractTestCase;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22
23 /** Test harness for the boolean expressions
24   *
25   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
26   * @version $Revision: 1.1 $
27   */

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

138
Popular Tags