1 package org.apache.axis2.om; 2 3 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory; 4 5 import javax.xml.stream.XMLInputFactory; 6 import javax.xml.stream.XMLStreamReader; 7 import java.io.ByteArrayInputStream ; 8 9 26 public class StaxParserTest extends AbstractTestCase { 27 28 XMLStreamReader parser1; 29 XMLStreamReader parser2; 30 XMLStreamReader parser3; 31 String xmlDocument = "<purchase-order xmlns=\"http://openuri.org/easypo\">" + 32 "<customer>" + 33 " <name>Gladys Kravitz</name>" + 34 " <address>Anytown, PA</address>" + 35 " </customer>" + 36 " <date>2005-03-06T14:06:12.697+06:00</date>" + 37 "</purchase-order>"; 38 39 public StaxParserTest(String testName) { 40 super(testName); 41 } 42 43 protected void setUp() throws Exception { 44 parser1 = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream (xmlDocument.getBytes())); 46 47 OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getSOAP11Factory(), 48 XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream (xmlDocument.getBytes()))); 49 parser2 = builder.getDocumentElement().getXMLStreamReader(); 50 51 OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getSOAP11Factory(), 52 XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream (xmlDocument.getBytes()))); 53 parser3 = builder2.getDocumentElement().getXMLStreamReaderWithoutCaching(); 54 55 } 56 57 public void testParserEventsWithCache() throws Exception { 58 59 assertEquals(parser1.getEventType(),parser2.getEventType()); 60 61 while(parser1.hasNext()){ 62 63 int parser1Event = parser1.next(); 64 int parser2Event = parser2.next(); 65 assertEquals(parser1Event,parser2Event); 66 67 } 68 69 70 } 71 72 public void testParserEventsWithoutCache() throws Exception { 73 74 assertEquals(parser1.getEventType(),parser3.getEventType()); 75 76 while(parser1.hasNext()){ 77 int parser1Event = parser1.next(); 78 int parser2Event = parser3.next(); 79 assertEquals(parser1Event,parser2Event); 80 } 81 82 83 } 84 85 public void testParserEvents2WithCache() throws Exception { 86 while(parser1.hasNext()){ 87 int parser1Event = parser1.getEventType(); 88 int parser2Event = parser2.getEventType(); 89 parser1.next(); 90 parser2.next(); 91 assertEquals(parser1Event,parser2Event); 92 } 93 94 95 } 96 } 97 104 105 107 108 109 | Popular Tags |