KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > xpath > SortByTest


1 /*
2  * Copyright 2001-2005 (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
8 package org.dom4j.xpath;
9
10 import junit.textui.TestRunner;
11
12 import java.io.File JavaDoc;
13 import java.util.List JavaDoc;
14
15 import org.dom4j.AbstractTestCase;
16 import org.dom4j.io.SAXReader;
17
18 /**
19  * Test harness for the sorting version of the selectNodes() function
20  *
21  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan </a>
22  * @version $Revision: 1.3 $
23  */

24 public class SortByTest extends AbstractTestCase {
25     public static void main(String JavaDoc[] args) {
26         TestRunner.run(SortByTest.class);
27     }
28
29     // Test case(s)
30
// -------------------------------------------------------------------------
31
public void testXPaths() throws Exception JavaDoc {
32         List JavaDoc list = document.selectNodes("//SPEAKER", "NAME");
33
34         log("Number of SPEAKER instances: " + list.size());
35
36         List JavaDoc noDuplicates = document.selectNodes("//SPEAKER", ".", true);
37
38         log("Number of distinct SPEAKER instances: " + noDuplicates.size());
39
40         log("Number of distinct SPEAKER instances: " + noDuplicates.size());
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44         super.setUp();
45         document = new SAXReader().read(new File JavaDoc("xml/much_ado.xml"));
46     }
47 }
48
49 /*
50  * Redistribution and use of this software and associated documentation
51  * ("Software"), with or without modification, are permitted provided that the
52  * following conditions are met:
53  *
54  * 1. Redistributions of source code must retain copyright statements and
55  * notices. Redistributions must also contain a copy of this document.
56  *
57  * 2. Redistributions in binary form must reproduce the above copyright notice,
58  * this list of conditions and the following disclaimer in the documentation
59  * and/or other materials provided with the distribution.
60  *
61  * 3. The name "DOM4J" must not be used to endorse or promote products derived
62  * from this Software without prior written permission of MetaStuff, Ltd. For
63  * written permission, please contact dom4j-info@metastuff.com.
64  *
65  * 4. Products derived from this Software may not be called "DOM4J" nor may
66  * "DOM4J" appear in their names without prior written permission of MetaStuff,
67  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
68  *
69  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
70  *
71  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
72  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
74  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
75  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
76  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
77  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
78  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
79  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
80  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
81  * POSSIBILITY OF SUCH DAMAGE.
82  *
83  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
84  */

85
Popular Tags