KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestText.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.Text;
16 import test.dom4j.AbstractTestCase;
17
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21 /** Test harness for the text() function
22   *
23   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
24   * @version $Revision: 1.1 $
25   */

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

131
Popular Tags