1 package org.apache.axis2.handlers.addressing; 2 3 import junit.framework.TestCase; 4 import org.apache.axis2.addressing.*; 5 import org.apache.axis2.addressing.miheaders.RelatesTo; 6 import org.apache.axis2.context.MessageContext; 7 import org.apache.axis2.handlers.util.TestUtil; 8 import org.apache.axis2.om.OMAbstractFactory; 9 import org.apache.axis2.om.impl.llom.util.XMLComparator; 10 import org.apache.axis2.soap.SOAPEnvelope; 11 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder; 12 13 import javax.xml.namespace.QName ; 14 15 31 public class AddressingOutHandlerTest extends TestCase implements AddressingConstants { 32 35 private AddressingOutHandler outHandler; 36 private MessageContext msgCtxt; 37 private TestUtil testUtil; 38 39 public AddressingOutHandlerTest(String testName) { 40 super(testName); 41 } 42 43 protected void setUp() throws Exception { 44 super.setUp(); 45 outHandler = new AddressingOutHandler(); 46 testUtil = new TestUtil(); 47 48 } 49 50 public void testAddToSOAPHeader() throws Exception { 51 EndpointReference epr = new EndpointReference(WSA_TO, "http://www.to.org/service/"); 52 epr.setInterfaceName(new QName ("http://www.from.org/service/port/", "Port", "portNS")); 53 epr.setServiceName(new ServiceName(new QName ("http://www.from.org/service/", "Service", "serviceNS"), "port")); 54 55 AnyContentType anyContentType = new AnyContentType(); 56 for (int i = 0; i < 5; i++) { 57 anyContentType.addReferenceValue(new QName (Submission.WSA_NAMESPACE, "Reference" + i), "Value " + i * 100); 58 59 } 60 61 epr.setReferenceParameters(anyContentType); 62 63 SOAPEnvelope defaultEnvelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope(); 64 65 defaultEnvelope.getHeader().declareNamespace(Submission.WSA_NAMESPACE, "wsa"); 66 MessageContext msgCtxt = new MessageContext(null); 67 msgCtxt.setTo(epr); 68 msgCtxt.setEnvelope(defaultEnvelope); 69 outHandler.invoke(msgCtxt); 70 71 StAXSOAPModelBuilder omBuilder = testUtil.getOMBuilder("eprTest.xml"); 72 XMLComparator xmlComparator = new XMLComparator(); 73 assertTrue(xmlComparator.compare(omBuilder.getDocumentElement(), defaultEnvelope)); 74 } 75 76 public void testHeaderCreationFromMsgCtxtInformation() throws Exception { 77 MessageInformationHeadersCollection mIHeaders = new MessageInformationHeadersCollection(); 78 79 AnyContentType referenceValues = new AnyContentType(); 80 81 EndpointReference epr = new EndpointReference(WSA_FROM, "http://www.from.org/service/"); 82 referenceValues.addReferenceValue(new QName ("Reference2"), "Value 200"); 83 epr.setReferenceParameters(referenceValues); 84 mIHeaders.setFrom(epr); 85 86 epr = new EndpointReference(WSA_TO, "http://www.to.org/service/"); 87 referenceValues = new AnyContentType(); 88 referenceValues.addReferenceValue(new QName ("http://reference.org","Reference4", "myRef"), "Value 400"); 89 referenceValues.addReferenceValue(new QName ("http://reference.org","Reference3", "myRef"), "Value 300"); 90 epr.setReferenceParameters(referenceValues); 91 92 epr.setServiceName(new ServiceName(new QName ("http://www.from.org/service/", "Service", "serviceNS"), "port")); 93 94 epr.setInterfaceName(new QName ("http://www.from.org/service/port/", "Port", "portNS")); 95 mIHeaders.setTo(epr); 96 97 epr = new EndpointReference(WSA_REPLY_TO, "http://www.replyTo.org/service/"); 98 mIHeaders.setReplyTo(epr); 99 100 mIHeaders.setMessageId("123456-7890"); 101 mIHeaders.setAction("http://www.actions.org/action"); 102 103 RelatesTo relatesTo = new RelatesTo("http://www.relatesTo.org/service/", "TestRelation"); 104 mIHeaders.setRelatesTo(relatesTo); 105 106 msgCtxt = new MessageContext(null); 107 msgCtxt.setMessageInformationHeaders(mIHeaders); 108 msgCtxt.setEnvelope(OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope()); 109 outHandler.invoke(msgCtxt); 110 111 XMLComparator xmlComparator = new XMLComparator(); 112 assertTrue(xmlComparator.compare(msgCtxt.getEnvelope(), testUtil.getOMBuilder("OutHandlerTest.xml").getDocumentElement())); 113 } 114 } 115 | Popular Tags |