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