1 package org.apache.axis2.handlers.addressing; 2 3 import junit.framework.TestCase; 4 import org.apache.axis2.addressing.AddressingConstants; 5 import org.apache.axis2.addressing.EndpointReference; 6 import org.apache.axis2.addressing.MessageInformationHeadersCollection; 7 import org.apache.axis2.handlers.util.TestUtil; 8 import org.apache.axis2.soap.SOAPEnvelope; 9 import org.apache.axis2.soap.SOAPHeader; 10 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder; 11 12 28 public class AddressingInHandlerTest extends TestCase { 29 32 33 AddressingInHandler inHandler; 34 TestUtil testUtil = new TestUtil(); 35 private static final String testFileName = "soapmessage.xml"; 36 37 private String action = "http://ws.apache.org/tests/action"; 38 private String messageID = "uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5"; 39 private String fromAddress = "http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous"; 40 41 44 public AddressingInHandlerTest(String testName) { 45 super(testName); 46 } 47 48 protected void setUp() throws Exception { 49 super.setUp(); 50 inHandler = new AddressingInHandler(); 51 } 52 53 54 public void testExtractAddressingInformationFromHeaders() { 55 try { 56 StAXSOAPModelBuilder omBuilder = testUtil.getOMBuilder(testFileName); 57 58 SOAPHeader header = ((SOAPEnvelope) omBuilder.getDocumentElement()).getHeader(); 59 MessageInformationHeadersCollection messageInformationHeadersCollection = 60 inHandler.extractCommonAddressingParameters(header, null,header.getHeaderBolcksWithNSURI(AddressingConstants.Submission.WSA_NAMESPACE), AddressingConstants.Submission.WSA_NAMESPACE); 61 62 if(messageInformationHeadersCollection == null){ 63 fail("Addressing Information Headers have not been retrieved properly"); 64 } 65 assertEquals("action header is not correct", messageInformationHeadersCollection.getAction(), action); 66 assertEquals("action header is not correct", messageInformationHeadersCollection.getMessageId(), messageID); 67 68 assertFromEPR(messageInformationHeadersCollection.getFrom()); 69 70 } catch (Exception e) { 71 e.printStackTrace(); 72 fail(" An Exception has occured " + e.getMessage()); 73 } 74 } 75 76 private void assertFromEPR(EndpointReference fromEPR){ 77 assertEquals("Address in EPR is not valid", fromEPR.getAddress(), fromAddress); 78 } 79 80 81 82 83 } 84 | Popular Tags |