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.Text; 16 import test.dom4j.AbstractTestCase; 17 18 import java.util.Iterator ; 19 import java.util.List ; 20 21 26 public class TestText extends AbstractTestCase { 27 28 protected static boolean VERBOSE = true; 29 30 protected static String [] paths = { 31 "text()", 32 "//author/text()" 33 }; 34 35 36 public static void main( String [] args ) { 37 TestRunner.run( suite() ); 38 } 39 40 public static Test suite() { 41 return new TestSuite( TestText.class ); 42 } 43 44 public TestText(String name) { 45 super(name); 46 } 47 48 public void testXPaths() throws Exception { 51 int size = paths.length; 52 for ( int i = 0; i < size; i++ ) { 53 testXPath( paths[i] ); 54 } 55 } 56 57 protected void testXPath(String xpath) { 60 List list = document.selectNodes(xpath); 61 62 log( "Searched path: " + xpath + " found: " + list.size() + " result(s)" ); 63 64 if ( VERBOSE ) { 65 System.out.println( list ); 66 } 67 68 for ( Iterator iter = list.iterator(); iter.hasNext(); ) { 69 Object object = iter.next(); 70 71 log( "Found Result: " + object ); 72 73 assertTrue( "Results should be Text objects", object instanceof Text ); 74 75 Text text = (Text) object; 76 77 assertTrue( "Results should support the parent relationship", text.supportsParent() ); 78 assertTrue( "Results should contain reference to the parent element", text.getParent() != null ); 79 assertTrue( "Results should contain reference to the owning document", text.getDocument() != null ); 80 } 81 } 82 } 83 84 85 86 87 131 | Popular Tags |