KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > engine > ServiceDispatchingTest


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis2.engine;
18
19 //todo
20

21 import javax.xml.namespace.QName JavaDoc;
22
23 import junit.framework.TestCase;
24
25 import org.apache.axis2.Constants;
26 import org.apache.axis2.addressing.AddressingConstants;
27 import org.apache.axis2.addressing.EndpointReference;
28 import org.apache.axis2.context.MessageContext;
29 import org.apache.axis2.context.ServiceContext;
30 import org.apache.axis2.description.ServiceDescription;
31 import org.apache.axis2.integration.TestingUtils;
32 import org.apache.axis2.integration.UtilServer;
33 import org.apache.axis2.om.OMAbstractFactory;
34 import org.apache.axis2.om.OMElement;
35 import org.apache.axis2.om.OMNamespace;
36 import org.apache.axis2.soap.SOAPFactory;
37 import org.apache.axis2.util.Utils;
38 import org.apache.commons.logging.Log;
39 import org.apache.commons.logging.LogFactory;
40
41 public class ServiceDispatchingTest extends TestCase {
42     private EndpointReference targetEPR =
43         new EndpointReference(
44             AddressingConstants.WSA_TO,
45             "http://127.0.0.1:"
46                 + (UtilServer.TESTING_PORT)
47                 + "/axis/services/EchoXMLService/echoOMElement");
48     private Log log = LogFactory.getLog(getClass());
49     private QName JavaDoc serviceName = new QName JavaDoc("EchoXMLService");
50     private QName JavaDoc operationName = new QName JavaDoc("echoOMElement");
51     private QName JavaDoc transportName = new QName JavaDoc("http://localhost/my", "NullTransport");
52
53     private AxisConfiguration engineRegistry;
54     private MessageContext mc;
55     //private Thread thisThread;
56
// private SimpleHTTPServer sas;
57
private ServiceContext serviceContext;
58     private ServiceDescription service;
59
60     private boolean finish = false;
61
62     public ServiceDispatchingTest() {
63         super(ServiceDispatchingTest.class.getName());
64     }
65
66     public ServiceDispatchingTest(String JavaDoc testName) {
67         super(testName);
68     }
69
70     protected void setUp() throws Exception JavaDoc {
71         UtilServer.start();
72         service = Utils.createSimpleService(serviceName, Echo.class.getName(), operationName);
73         UtilServer.deployService(service);
74         serviceContext =
75             UtilServer.getConfigurationContext().createServiceContext(service.getName());
76
77     }
78
79     protected void tearDown() throws Exception JavaDoc {
80         UtilServer.unDeployService(serviceName);
81         UtilServer.stop();
82     }
83
84     public void testDispatchWithURLOnly() throws Exception JavaDoc {
85         SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
86         OMElement payload = TestingUtils.createDummyOMElement();
87         org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call();
88         call.setTo(
89             new EndpointReference(
90                 AddressingConstants.WSA_TO,
91                 "http://127.0.0.1:5555/axis/services/EchoXMLService/echoOMElement"));
92         call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
93         OMElement result = (OMElement) call.invokeBlocking(operationName.getLocalPart(), payload);
94         TestingUtils.campareWithCreatedOMElement(result);
95         call.close();
96     }
97     public void testDispatchWithURLAndSOAPAction() throws Exception JavaDoc {
98         SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
99         OMNamespace omNs = fac.createOMNamespace("http://dummyURL", "my");
100         OMElement payload = fac.createOMElement("echoOMElementRequest", omNs);
101         OMElement value = fac.createOMElement("myValue", omNs);
102         value.addChild(fac.createText(value, "Isaac Assimov, the foundation Sega"));
103         payload.addChild(value);
104         org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call();
105         call.setTo(
106             new EndpointReference(
107                 AddressingConstants.WSA_TO,
108                 "http://127.0.0.1:5555/axis/services/EchoXMLService/"));
109         call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
110         call.setSoapAction("echoOMElement");
111         OMElement result = (OMElement) call.invokeBlocking(operationName.getLocalPart(), payload);
112         TestingUtils.campareWithCreatedOMElement(result);
113         call.close();
114     }
115
116     public void testDispatchWithSOAPBody() throws Exception JavaDoc {
117         SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
118
119         OMNamespace omNs = fac.createOMNamespace("http://127.0.0.1:5555/axis/services/EchoXMLService", "my");
120         OMElement payload = fac.createOMElement("echoOMElement", omNs);
121         OMElement value = fac.createOMElement("myValue", omNs);
122         value.addChild(fac.createText(value, "Isaac Assimov, the foundation Sega"));
123         payload.addChild(value);
124
125         
126         org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call();
127         call.setTo(
128             new EndpointReference(
129                 AddressingConstants.WSA_TO,
130                 "http://127.0.0.1:5555/axis/services/"));
131         call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
132         OMElement result = (OMElement) call.invokeBlocking(operationName.getLocalPart(), payload);
133         TestingUtils.campareWithCreatedOMElement(result);
134         call.close();
135     }
136 }
137
Popular Tags