1 16 package org.apache.axis2.om; 17 18 import org.apache.axis2.om.impl.llom.OMNavigator; 19 import org.apache.axis2.soap.SOAPEnvelope; 20 import org.apache.axis2.soap.SOAPFactory; 21 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder; 22 23 import javax.xml.stream.XMLInputFactory; 24 import javax.xml.stream.XMLOutputFactory; 25 import javax.xml.stream.XMLStreamReader; 26 import java.io.File ; 27 import java.io.FileOutputStream ; 28 import java.io.FileReader ; 29 30 public class OMNavigatorTest extends AbstractTestCase { 31 private SOAPEnvelope envelope = null; 32 private OMXMLParserWrapper builder; 33 private File tempFile; 34 private OMOutput omOutput; 35 36 public OMNavigatorTest(String testName) { 37 super(testName); 38 } 39 40 protected void setUp() throws Exception { 41 XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance(). 42 createXMLStreamReader(new FileReader (getTestResourceFile("soap/soapmessage1.xml"))); 43 SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); 44 builder = new StAXSOAPModelBuilder(xmlStreamReader); 45 envelope = (SOAPEnvelope) builder.getDocumentElement(); 46 tempFile = File.createTempFile("temp", "xml"); 47 omOutput = new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream (tempFile))); 48 50 51 } 52 53 public void testnavigatorFullyBuilt() throws Exception { 54 assertNotNull(envelope); 55 envelope.serializeWithCache(omOutput); 57 58 OMNavigator navigator = new OMNavigator(envelope); 60 OMNode node = null; 61 while (navigator.isNavigable()) { 62 node = navigator.next(); 63 assertNotNull(node); 64 } 65 } 66 67 public void testnavigatorHalfBuilt() { 68 assertNotNull(envelope); 69 OMNavigator navigator = new OMNavigator(envelope); 71 OMNode node = null; 72 while (navigator.isNavigable()) { 73 node = navigator.next(); 74 assertNotNull(node); 75 } 76 } 77 78 public void testnavigatorHalfBuiltStep() { 79 assertNotNull(envelope); 80 81 OMNavigator navigator = new OMNavigator(envelope); 83 OMNode node = null; 84 while (!navigator.isCompleted()) { 85 if (navigator.isNavigable()) { 86 node = navigator.next(); 87 } else { 88 builder.next(); 89 navigator.step(); 90 node = navigator.next(); 91 } 92 assertNotNull(node); 93 94 } 95 96 } 97 98 protected void tearDown() throws Exception { 99 omOutput.flush(); 100 tempFile.delete(); 101 } 102 103 } 104 | Popular Tags |