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 23 public class TestParseText extends AbstractTestCase { 24 25 protected String xmlText = "<root> <author name='James'> <location>London</location> </author> </root>"; 26 27 public static void main( String [] args ) { 28 TestRunner.run( suite() ); 29 } 30 31 public static Test suite() { 32 return new TestSuite( TestParseText.class ); 33 } 34 35 public TestParseText(String name) { 36 super(name); 37 } 38 39 public void testDocument() throws Exception { 42 assertTrue( "Document is not null", document != null ); 43 44 Element root = document.getRootElement(); 45 46 assertTrue( "Root element is not null", root != null ); 47 48 Element author = root.element( "author" ); 49 50 assertTrue( "Author element is not null", author != null ); 51 52 String name = author.attributeValue( "name"); 53 54 assertEquals( "Name attribute matches", name, "James" ); 55 56 String location = document.valueOf( "/root/author/location" ); 57 58 assertEquals( "Location element matches", location, "London" ); 59 } 60 61 protected void setUp() throws Exception { 64 document = O3DocumentHelper.parseText( xmlText ); 65 } 66 67 } 68 69 70 71 72 116 | Popular Tags |