KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestNamespace.java,v 1.2 2003/11/02 18:31:28 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.Namespace;
16 import org.dom4j.XPath;
17 import org.dom4j.io.SAXReader;
18 import org.dom4j.tree.AbstractNamespace;
19 import org.ozoneDB.xml.dom4j.O3DocumentHelper;
20 import test.dom4j.AbstractTestCase;
21
22 import java.io.File JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 /** Test harness for the namespace axis
27   *
28   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
29   * @version $Revision: 1.2 $
30   */

31 public class TestNamespace extends AbstractTestCase {
32
33     protected static boolean VERBOSE = false;
34
35     protected static String JavaDoc[] paths = {
36         "namespace::*",
37         "/Template/Application1/namespace::*",
38         "/Template/Application1/namespace::xplt",
39         "//namespace::*"
40     };
41
42
43     public static void main( String JavaDoc[] args ) {
44         TestRunner.run( suite() );
45     }
46
47     public static Test suite() {
48         return new TestSuite( TestNamespace.class );
49     }
50
51     public TestNamespace(String JavaDoc name) {
52         super(name);
53     }
54
55     // Test case(s)
56
//-------------------------------------------------------------------------
57
public void testDummy() throws Exception JavaDoc {
58     }
59
60 /*
61     public void testXPaths() throws Exception {
62         int size = paths.length;
63         for ( int i = 0; i < size; i++ ) {
64             testXPath( paths[i] );
65         }
66     }
67 */

68
69     // Implementation methods
70
//-------------------------------------------------------------------------
71
protected void testXPath(String JavaDoc xpathText) {
72         XPath xpath = O3DocumentHelper.createXPath(xpathText);
73         List JavaDoc list = xpath.selectNodes( document );
74
75         log( "Searched path: " + xpathText + " found: " + list.size() + " result(s)" );
76
77         if ( VERBOSE ) {
78             log( "xpath: " + xpath );
79             log( "results: " + list );
80         }
81
82         for ( Iterator JavaDoc iter = list.iterator(); iter.hasNext(); ) {
83             Object JavaDoc object = iter.next();
84
85             log( "Found Result: " + object );
86
87             assertTrue( "Results should be AbstractNamespace objects", object instanceof Namespace );
88
89             AbstractNamespace namespace = (AbstractNamespace) object;
90
91             log( "Parent node: " + namespace.getParent() );
92
93             assertTrue( "Results should support the parent relationship", namespace.supportsParent() );
94             assertTrue( "Results should contain reference to the parent element", namespace.getParent() != null );
95             assertTrue( "Results should contain reference to the owning document", namespace.getDocument() != null );
96         }
97     }
98
99     protected void setUp() throws Exception JavaDoc {
100         document = new SAXReader().read( new File JavaDoc( "xml/testNamespaces.xml" ) );
101     }
102 }
103
104
105
106
107 /*
108  * Redistribution and use of this software and associated documentation
109  * ("Software"), with or without modification, are permitted provided
110  * that the following conditions are met:
111  *
112  * 1. Redistributions of source code must retain copyright
113  * statements and notices. Redistributions must also contain a
114  * copy of this document.
115  *
116  * 2. Redistributions in binary form must reproduce the
117  * above copyright notice, this list of conditions and the
118  * following disclaimer in the documentation and/or other
119  * materials provided with the distribution.
120  *
121  * 3. The name "DOM4J" must not be used to endorse or promote
122  * products derived from this Software without prior written
123  * permission of MetaStuff, Ltd. For written permission,
124  * please contact dom4j-info@metastuff.com.
125  *
126  * 4. Products derived from this Software may not be called "DOM4J"
127  * nor may "DOM4J" appear in their names without prior written
128  * permission of MetaStuff, Ltd. DOM4J is a registered
129  * trademark of MetaStuff, Ltd.
130  *
131  * 5. Due credit should be given to the DOM4J Project
132  * (http://dom4j.org/).
133  *
134  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
135  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
136  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
137  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
138  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
139  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
140  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
141  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
142  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
143  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
144  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
145  * OF THE POSSIBILITY OF SUCH DAMAGE.
146  *
147  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
148  *
149  * $Id: TestNamespace.java,v 1.2 2003/11/02 18:31:28 per_nyfelt Exp $
150  */

151
Popular Tags