KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestSelectSingleNode.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.Document;
16 import org.dom4j.Element;
17 import org.dom4j.Node;
18 import org.dom4j.io.SAXReader;
19 import test.dom4j.AbstractTestCase;
20
21 /** Tests the selectSingleNode method
22   *
23   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
24   * @version $Revision: 1.1 $
25   */

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

127
Popular Tags