1 16 package org.apache.axis2.om.impl.builder; 17 18 import org.apache.axis2.om.*; 19 import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder; 20 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory; 21 22 import javax.xml.stream.XMLInputFactory; 23 import java.io.FileReader ; 24 import java.util.Iterator ; 25 26 public class StAXOMBuilderTest extends AbstractTestCase { 27 StAXOMBuilder stAXOMBuilder; 28 FileReader testFile; 29 private OMElement rootElement; 30 31 34 public StAXOMBuilderTest(String testName) { 35 super(testName); 36 } 37 38 protected void setUp() throws Exception { 39 testFile = new FileReader (getTestResourceFile("non_soap.xml")); 40 stAXOMBuilder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getSOAP11Factory(), XMLInputFactory.newInstance().createXMLStreamReader(testFile)); 41 } 42 43 public void testGetRootElement() throws Exception { 44 rootElement = stAXOMBuilder.getDocumentElement(); 45 assertTrue("Root element can not be null", rootElement != null); 46 assertTrue(" Name of the root element is wrong", rootElement.getLocalName().equalsIgnoreCase("Root")); 47 OMNode omnode = rootElement.getFirstChild(); 49 while (omnode instanceof OMText) { 50 omnode = omnode.getNextSibling(); 51 } 52 Iterator children = ((OMElement) omnode).getChildren(); 53 int childrenCount = 0; 54 while (children.hasNext()) { 55 OMNode node = (OMNode) children.next(); 56 if (node instanceof OMElement) 57 childrenCount++; 58 } 59 assertTrue(childrenCount == 5); 60 } 61 } | Popular Tags |