1 17 package org.apache.excalibur.xml.dom.test; 18 19 import java.io.StringReader ; 20 21 import org.apache.avalon.excalibur.testcase.ExcaliburTestCase; 22 import org.apache.avalon.framework.component.ComponentException; 23 import org.apache.excalibur.xml.dom.DOMParser; 24 import org.w3c.dom.Document ; 25 import org.w3c.dom.Element ; 26 import org.w3c.dom.Node ; 27 import org.xml.sax.InputSource ; 28 29 32 public class DefaultDOMParserTestCase extends ExcaliburTestCase 33 { 34 35 private static final String CONTENT = 36 "<?xml version=\"1.0\"?>" + 37 "<test:root xmlns:test=\"http://localhost/test\">" + 38 "<test:element1/>" + 39 "<test:element2/>" + 40 "</test:root>"; 41 private static final StringReader IN = new StringReader ( CONTENT ); 42 43 public DefaultDOMParserTestCase( String name ) 44 { 45 super( name ); 46 } 47 48 public void testCreateDOMHandler() 49 { 50 try 51 { 52 final DOMParser parser = (DOMParser)manager.lookup( DOMParser.ROLE ); 53 54 final Document document = parser.parseDocument( new InputSource ( IN ) ); 55 56 final Element root = document.getDocumentElement(); 57 assertEquals( "Wrong root element", "test:root", root.getNodeName() ); 58 assertEquals( "Wrong namespace uri", "http://localhost/test", root.getNamespaceURI() ); 59 60 final Node element1 = root.getFirstChild(); 61 assertEquals( "Child is not an element", Node.ELEMENT_NODE, element1.getNodeType() ); 62 assertEquals( "Wrong first element", "test:element1", element1.getNodeName() ); 63 64 final Node element2 = root.getLastChild(); 65 assertEquals( "Child is not an element", Node.ELEMENT_NODE, element2.getNodeType() ); 66 assertEquals( "Wrong last element", "test:element2", element2.getNodeName() ); 67 } 68 catch ( ComponentException e ) 69 { 70 fail( "Failed to lookup components: " + e.getMessage() ); 71 } 72 catch ( Exception e ) 73 { 74 fail( "Failed to create handler: " + e.getMessage() ); 75 } 76 } 77 78 } 79 | Popular Tags |