KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

121
Popular Tags