1 9 10 package test.dom4j; 11 12 import junit.framework.Test; 13 import junit.framework.TestSuite; 14 import junit.textui.TestRunner; 15 import org.dom4j.Document; 16 import org.dom4j.Node; 17 import org.dom4j.util.IndexedDocumentFactory; 18 19 import java.util.List ; 20 21 26 public class TestIndexedElement extends AbstractTestCase { 27 28 protected static boolean VERBOSE = true; 29 30 public static void main( String [] args ) { 31 TestRunner.run( suite() ); 32 } 33 34 public static Test suite() { 35 return new TestSuite( TestIndexedElement.class ); 36 } 37 38 public TestIndexedElement(String name) { 39 super(name); 40 } 41 42 public void testXPaths() throws Exception { 45 testXPath( "//author" ); 46 } 47 48 protected void testXPath(String xpath) { 51 List list = document.selectNodes( xpath ); 52 53 log( "Searched path: " + xpath ); 54 log( "Found : " + list.size() + " result(s)" ); 55 56 log( "Results" ); 57 if ( list == null ) { 58 log( "null" ); 59 } 60 else { 61 log( "[" ); 62 for ( int i = 0, size = list.size(); i < size; i++ ) { 63 Object object = list.get(i); 64 String text = "null"; 65 if ( object instanceof Node ) { 66 Node node = (Node) object; 67 text = node.asXML(); 68 } 69 else if ( object != null ) { 70 text = object.toString(); 71 } 72 log( " " + text ); 73 } 74 log( "]" ); 75 } 76 log( "..........................................." ); 77 78 assertTrue( "Found some results", list.size() > 0 ); 79 } 80 81 82 protected Document createDocument() { 83 return IndexedDocumentFactory.getInstance().createDocument(); 84 } 85 } 86 87 88 89 90 134 | Popular Tags |