1 16 package org.apache.axis2.om.factory; 17 18 import org.apache.axis2.om.*; 19 import org.apache.axis2.soap.*; 20 import org.apache.axis2.soap.impl.llom.SOAPConstants; 21 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants; 22 23 29 public class OMLinkedListImplFactoryTest extends AbstractTestCase { 30 public OMLinkedListImplFactoryTest(String testName) { 31 super(testName); 32 } 33 34 SOAPFactory omFactory; 35 OMNamespace namespace; 36 String nsUri = "http://www.apache.org/~chinthaka"; 37 String nsPrefix = "myhome"; 38 39 protected void setUp() throws Exception { 40 super.setUp(); 41 omFactory = OMAbstractFactory.getSOAP11Factory(); 42 namespace = omFactory.createOMNamespace(nsUri, nsPrefix); 43 } 44 45 public void testCreateOMElementWithNoBuilder() { 46 OMElement omElement = omFactory.createOMElement("chinthaka", namespace); 47 assertTrue("Programatically created OMElement should have done = true ", omElement.isComplete()); 48 49 } 50 51 public void testCreateOMElement() { 52 try { 53 OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(getTestResourceFile("soap/whitespacedMessage.xml")); 54 OMElement documentElement = omBuilder.getDocumentElement(); 55 OMElement child = omFactory.createOMElement("child", namespace, documentElement, omBuilder); 56 assertTrue("OMElement with a builder should start with done = false ", !child.isComplete()); 57 assertTrue("This OMElement must have a builder ", child.getBuilder() instanceof OMXMLParserWrapper); 58 59 } catch (Exception e) { 60 e.printStackTrace(); } 62 } 63 64 public void testCreateOMNamespace() { 65 assertTrue("OMNamespace uri not correct", nsUri.equals(namespace.getName())); assertTrue("OMNamespace prefix not correct", nsPrefix.equals(namespace.getPrefix())); } 68 69 public void testCreateText() { 70 OMElement omElement = omFactory.createOMElement("chinthaka", namespace); 71 String text = "sampleText"; 72 OMText omText = omFactory.createText(omElement, text); 73 assertTrue("Programatically created OMText should have done = true ", omText.isComplete()); 74 assertTrue("Programatically created OMText should have correct text value ", text.equals(omText.getText())); 75 76 } 77 78 public void testCreateSOAPBody() { 79 try { 80 OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(getTestResourceFile("soap/minimalMessage.xml")); 81 SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement(); 82 SOAPBody soapBodyOne = omFactory.createSOAPBody(soapEnvelope); 83 assertTrue("Programatically created SOAPBody should have done = true ", soapBodyOne.isComplete()); 84 soapBodyOne.detach(); 85 SOAPBody soapBodyTwo = omFactory.createSOAPBody(soapEnvelope, omBuilder); 86 assertTrue("SOAPBody with a builder should start with done = false ", !soapBodyTwo.isComplete()); 87 assertTrue("This SOAPBody must have a builder ", soapBodyTwo.getBuilder() instanceof OMXMLParserWrapper); 88 89 90 } catch (Exception e) { 91 e.printStackTrace(); } 93 } 94 95 public void testCreateSOAPEnvelope() { 96 try { 97 OMNamespace soapNamespace = omFactory.createOMNamespace(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI, SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX); 98 SOAPEnvelope soapEnvelopeTwo = omFactory.createSOAPEnvelope(); 99 assertTrue("Programatically created SOAPEnvelope should have done = true ", soapEnvelopeTwo.isComplete()); 100 SOAPEnvelope soapEnvelope = omFactory.createSOAPEnvelope(OMTestUtils.getOMBuilder(getTestResourceFile("soap/minimalMessage.xml"))); 101 assertTrue("SOAPEnvelope with a builder should start with done = false ", !soapEnvelope.isComplete()); 102 assertTrue("This SOAPEnvelope must have a builder ", soapEnvelope.getBuilder() instanceof OMXMLParserWrapper); 103 104 105 } catch (Exception e) { 106 e.printStackTrace(); } 108 } 109 110 public void testCreateSOAPHeader() { 111 try { 112 OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(getTestResourceFile("soap/minimalMessage.xml")); 113 SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement(); 114 SOAPHeader soapHeader = omFactory.createSOAPHeader(soapEnvelope); 115 assertTrue("Programatically created SOAPHeader should have done = true ", soapHeader.isComplete()); 116 soapHeader.detach(); 117 SOAPHeader soapHeaderTwo = omFactory.createSOAPHeader(soapEnvelope, omBuilder); 118 assertTrue("SOAPHeader with a builder should start with done = false ", !soapHeaderTwo.isComplete()); 119 assertTrue("This SOAPHeader must have a builder ", soapHeaderTwo.getBuilder() instanceof OMXMLParserWrapper); 120 121 122 } catch (Exception e) { 123 e.printStackTrace(); } 125 } 126 127 public void testCreateSOAPHeaderBlock() { 128 try { 129 OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(getTestResourceFile("soap/soapmessage.xml")); 130 SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement(); 131 SOAPHeader soapHeader = soapEnvelope.getHeader(); 132 SOAPHeaderBlock soapHeaderBlock = omFactory.createSOAPHeaderBlock("soapHeaderBlockOne", namespace, soapHeader); 133 assertTrue("Programatically created SOAPHeaderBlock should have done = true ", soapHeaderBlock.isComplete()); 134 SOAPHeaderBlock soapHeaderBlockTwo = omFactory.createSOAPHeaderBlock("soapHeaderBlockOne", namespace, soapHeader, omBuilder); 135 assertTrue("SOAPHeaderBlock with a builder should start with done = false ", !soapHeaderBlockTwo.isComplete()); 136 assertTrue("This SOAPHeaderBlock must have a builder ", soapHeaderBlockTwo.getBuilder() instanceof OMXMLParserWrapper); 137 138 139 } catch (Exception e) { 140 e.printStackTrace(); } 142 } 143 144 public void testCreateSOAPFault() { 145 try { 146 OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(getTestResourceFile("soap/soapmessage.xml")); 147 SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement(); 148 SOAPBody soapBody = soapEnvelope.getBody(); 149 SOAPFault soapFault = omFactory.createSOAPFault(soapBody, new Exception (" this is just a test ")); 150 assertTrue("Programatically created SOAPFault should have done = true ", soapFault.isComplete()); 151 soapFault.detach(); 152 SOAPFault soapFaultTwo = omFactory.createSOAPFault(soapBody, omBuilder); 153 assertTrue("SOAPFault with a builder should start with done = false ", !soapFaultTwo.isComplete()); 154 assertTrue("This SOAPFault must have a builder ", soapFaultTwo.getBuilder() instanceof OMXMLParserWrapper); 155 156 157 } catch (Exception e) { 158 e.printStackTrace(); } 160 } 161 162 163 } 164 | Popular Tags |