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