KickJava   Java API By Example, From Geeks To Geeks.

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


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

31 public class AddressingOutHandlerTest extends TestCase implements AddressingConstants {
32     /**
33      * Eran Chinthaka (chinthaka@apache.org)
34      */

35     private AddressingOutHandler outHandler;
36     private MessageContext msgCtxt;
37     private TestUtil testUtil;
38
39     public AddressingOutHandlerTest(String JavaDoc testName) {
40         super(testName);
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44         super.setUp();
45         outHandler = new AddressingOutHandler();
46         testUtil = new TestUtil();
47
48     }
49
50     public void testAddToSOAPHeader() throws Exception JavaDoc {
51         EndpointReference epr = new EndpointReference(WSA_TO, "http://www.to.org/service/");
52         epr.setInterfaceName(new QName JavaDoc("http://www.from.org/service/port/", "Port", "portNS"));
53         epr.setServiceName(new ServiceName(new QName JavaDoc("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 JavaDoc(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 JavaDoc {
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 JavaDoc("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 JavaDoc("http://reference.org","Reference4", "myRef"), "Value 400");
89         referenceValues.addReferenceValue(new QName JavaDoc("http://reference.org","Reference3", "myRef"), "Value 300");
90         epr.setReferenceParameters(referenceValues);
91
92         epr.setServiceName(new ServiceName(new QName JavaDoc("http://www.from.org/service/", "Service", "serviceNS"), "port"));
93
94         epr.setInterfaceName(new QName JavaDoc("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