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.Document; 16 import org.dom4j.Element; 17 import org.dom4j.Node; 18 import org.dom4j.io.SAXReader; 19 import test.dom4j.AbstractTestCase; 20 21 26 public class TestSelectSingleNode extends AbstractTestCase { 27 28 29 public static void main( String [] args ) { 30 TestRunner.run( suite() ); 31 } 32 33 public static Test suite() { 34 return new TestSuite( TestSelectSingleNode.class ); 35 } 36 37 public TestSelectSingleNode(String name) { 38 super(name); 39 } 40 41 public void testSelectSingleNode() throws Exception { 44 Node node = document.selectSingleNode("/properties/client/threadsafe"); 45 assertTrue( "Found a valid node", node != null ); 46 47 Element server = (Element) document.selectSingleNode( "/properties/server" ); 48 assertTrue( "Found a valid server", server != null ); 49 50 server = (Element) document.getRootElement().selectSingleNode( "/properties/server" ); 51 assertTrue( "Found a valid server", server != null ); 52 53 server = (Element) document.selectSingleNode( "properties/server" ); 55 assertTrue( "Found a valid server", server != null ); 56 57 Element connection = (Element) server.selectSingleNode( "db/connection" ); 59 assertTrue( "Found a valid connection", connection != null ); 60 } 61 62 63 public void testSteensBug() throws Exception { 64 Document document = new SAXReader().read( "xml/schema/personal.xsd" ); 65 66 assertNotNull( document.selectSingleNode( "/xs:schema/xs:element[@name='person']" ) ); 67 68 Element root = document.getRootElement(); 69 70 assertNotNull( root.selectSingleNode( "/xs:schema/xs:element[@name='person']" ) ); 71 } 72 73 protected void setUp() throws Exception { 76 document = new SAXReader().read( "xml/test/jimBrain.xml" ); 77 } 78 } 79 80 81 82 83 127 | Popular Tags |