KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dom4j > TestIndexedElement


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: TestIndexedElement.java,v 1.1 2003/07/07 10:30:29 per_nyfelt Exp $
8  */

9
10 package test.dom4j;
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.Node;
17 import org.dom4j.util.IndexedDocumentFactory;
18
19 import java.util.List JavaDoc;
20
21 /** A test harness for the IndexedElement implementation
22   *
23   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
24   * @version $Revision: 1.1 $
25   */

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

134
Popular Tags