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.Element; 16 import org.ozoneDB.xml.dom4j.O3DocumentHelper; 17 18 import java.io.FileInputStream ; 19 20 21 26 public class TestElementByID extends AbstractTestCase { 27 28 29 protected static String INPUT_XML_FILE = "xml/test/elementByID.xml"; 30 31 public static void main( String [] args ) { 32 TestRunner.run( suite() ); 33 } 34 35 public static Test suite() { 36 return new TestSuite( TestElementByID.class ); 37 } 38 39 public TestElementByID(String name) { 40 super(name); 41 } 42 43 44 public void testElementByID() throws Exception { 47 String id = "message"; 48 49 Element element = (Element) document.selectSingleNode( "//*[@ID='" + id + "']" ); 51 assertTrue( "Found element by ID: " + id, element != null ); 52 assertEquals( "ID is equal", id, element.attributeValue( "ID" ) ); 53 54 element = document.elementByID( id ); 56 57 assertTrue( "Found element by ID: " + id, element != null ); 58 assertEquals( "ID is equal", id, element.attributeValue( "ID" ) ); 59 60 log( "Found element: " + element.getText() ); 61 62 element = document.elementByID( "DoesNotExist" ); 63 64 assertTrue( "Found no element", element == null ); 65 } 66 67 protected void setUp() throws Exception { 68 document = O3DocumentHelper.parse(new FileInputStream (INPUT_XML_FILE)); 70 } 71 } 72 73 74 75 76 120 | Popular Tags |