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