1 16 package org.apache.axis2.om; 17 18 import org.apache.axis2.soap.SOAPEnvelope; 19 import org.apache.axis2.soap.SOAPFactory; 20 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder; 21 22 import javax.xml.stream.XMLInputFactory; 23 import javax.xml.stream.XMLStreamReader; 24 import java.io.File ; 25 import java.io.FileReader ; 26 import java.util.Iterator ; 27 28 31 public class OMTest extends AbstractTestCase { 32 private SOAPEnvelope envelope; 33 private SOAPFactory fac; 34 35 38 public OMTest(String testName) { 39 super(testName); 40 } 41 42 protected void setUp() throws Exception { 43 File file = getTestResourceFile("soap/sample1.xml"); 44 XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new FileReader (file)); 45 fac = OMAbstractFactory.getSOAP11Factory(); 46 OMXMLParserWrapper builder = new StAXSOAPModelBuilder(parser); 47 envelope = (SOAPEnvelope) builder.getDocumentElement(); 48 } 49 50 53 public void testNullInChilderen() { 54 isNullChildrenThere(envelope); 55 } 56 57 60 public void test4MissingNamespaces() { 61 isNameSpacesMissing(envelope); 62 } 63 64 public void isNullChildrenThere(OMElement omeleent) { 65 Iterator it = omeleent.getChildren(); 66 while (it.hasNext()) { 67 OMNode node = (OMNode) it.next(); 68 assertNotNull(node); 69 if (node.getType() == OMNode.ELEMENT_NODE) { 70 isNullChildrenThere((OMElement) node); 71 } 72 } 73 } 74 75 public void isNameSpacesMissing(OMElement omeleent) { 76 OMNamespace omns = omeleent.getNamespace(); 77 assertNotNull(omns); 78 assertNotNull(omns.getName()); 79 Iterator it = omeleent.getChildren(); 80 while (it.hasNext()) { 81 OMNode node = (OMNode) it.next(); 82 if (node != null && node.getType() == OMNode.ELEMENT_NODE) { 83 isNameSpacesMissing((OMElement) node); 84 } 85 } 86 } 87 88 public void testRootNotCompleteInPartialBuild() throws Exception { 89 assertFalse("Root should not be complete", envelope.isComplete()); 90 } 91 92 97 public void testFirstChildDetach() throws Exception { 98 OMElement root = envelope; 99 assertFalse("Root should not be complete", root.isComplete()); 100 OMNode oldFirstChild = root.getFirstChild(); 101 assertNotNull(oldFirstChild); 102 oldFirstChild.detach(); 103 OMNode newFirstChild = root.getFirstChild(); 104 assertNotNull(newFirstChild); 105 assertNotSame(oldFirstChild, newFirstChild); 106 } 107 108 public void testAdditionOfaCompletelyNewElement() throws Exception { 110 111 142 } 143 } 144 | Popular Tags |