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.Node; 16 import org.dom4j.XPath; 17 import org.ozoneDB.xml.dom4j.O3DocumentHelper; 18 import test.dom4j.AbstractTestCase; 19 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 28 public class TestBoolean extends AbstractTestCase { 29 30 protected static boolean VERBOSE = true; 31 32 protected static String [] paths = { 33 ".[name()='author']", 34 ".[.='James Strachan']", 35 ".[name()='XXXX']", 36 ".[.='XXXX']", 37 "name()='author'", 38 "name()='XXXX'", 39 ".='James Strachan'", 40 ".='XXXX'" 41 }; 42 43 44 public static void main( String [] args ) { 45 TestRunner.run( suite() ); 46 } 47 48 public static Test suite() { 49 return new TestSuite( TestBoolean.class ); 50 } 51 52 public TestBoolean(String name) { 53 super(name); 54 } 55 56 public void testXPaths() throws Exception { 59 int size = paths.length; 60 for ( int i = 0; i < size; i++ ) { 61 testXPath( paths[i] ); 62 } 63 } 64 65 protected void testXPath(String xpathExpression) { 68 XPath xpath = O3DocumentHelper.createXPath( xpathExpression ); 69 assertTrue( "No xpath object was created", xpath != null ); 70 71 log( "Evaluating xpath: " + xpath ); 72 73 List list = document.selectNodes("//author"); 74 for ( Iterator iter = list.iterator(); iter.hasNext(); ) { 75 Node node = (Node) iter.next(); 76 testXPath(node, xpath); 77 } 78 } 79 80 protected void testXPath(Node node, XPath xpath) { 81 List list = xpath.selectNodes( node ); 82 83 log( "Searched path: " + xpath + " found: " + list.size() + " result(s)" ); 84 85 if ( VERBOSE ) { 86 System.out.println( list ); 87 } 88 } 89 } 90 91 92 93 94 138 | Popular Tags |