1 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.Namespace; 16 import org.dom4j.XPath; 17 import org.dom4j.io.SAXReader; 18 import org.dom4j.tree.AbstractNamespace; 19 import org.ozoneDB.xml.dom4j.O3DocumentHelper; 20 import test.dom4j.AbstractTestCase; 21 22 import java.io.File ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 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 public void testDummy() throws Exception { 58 } 59 60 68 69 protected void testXPath(String xpathText) { 72 XPath xpath = O3DocumentHelper.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 AbstractNamespace objects", object instanceof Namespace ); 88 89 AbstractNamespace namespace = (AbstractNamespace) 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 151 | Popular Tags |