KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > handlers > addressing > AddressingInHandlerTest


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 /**
13  * Copyright 2001-2004 The Apache Software Foundation.
14  * <p/>
15  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
16  * use this file except in compliance with the License. You may obtain a copy of
17  * the License at
18  * <p/>
19  * http://www.apache.org/licenses/LICENSE-2.0
20  * <p/>
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
23  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
24  * License for the specific language governing permissions and limitations under
25  * the License.
26  * <p/>
27  */

28 public class AddressingInHandlerTest extends TestCase {
29     /**
30      * Eran Chinthaka (chinthaka@apache.org)
31      */

32
33     AddressingInHandler inHandler;
34     TestUtil testUtil = new TestUtil();
35     private static final String JavaDoc testFileName = "soapmessage.xml";
36
37     private String JavaDoc action = "http://ws.apache.org/tests/action";
38     private String JavaDoc messageID = "uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5";
39     private String JavaDoc fromAddress = "http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous";
40
41     /**
42      * @param testName
43      */

44     public AddressingInHandlerTest(String JavaDoc testName) {
45         super(testName);
46     }
47
48     protected void setUp() throws Exception JavaDoc {
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 JavaDoc 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