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