KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.TestCase;
22 import org.apache.axis2.Constants;
23 import org.apache.axis2.addressing.AddressingConstants;
24 import org.apache.axis2.addressing.EndpointReference;
25 import org.apache.axis2.clientapi.Call;
26 import org.apache.axis2.context.MessageContext;
27 import org.apache.axis2.integration.UtilServer;
28 import org.apache.axis2.om.OMAbstractFactory;
29 import org.apache.axis2.om.OMElement;
30 import org.apache.axis2.om.OMNamespace;
31 import org.apache.axis2.soap.SOAPBody;
32 import org.apache.axis2.soap.SOAPEnvelope;
33 import org.apache.axis2.soap.SOAPFactory;
34 import org.apache.axis2.transport.http.SimpleHTTPServer;
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 import javax.xml.namespace.QName JavaDoc;
39
40 public class CallUnregisteredServiceTest extends TestCase {
41     private Log log = LogFactory.getLog(getClass());
42     private QName JavaDoc serviceName = new QName JavaDoc("", "EchoXMLService");
43     private QName JavaDoc operationName = new QName JavaDoc("http://localhost/my", "echoOMElement");
44
45     private AxisConfiguration engineRegistry;
46     private MessageContext mc;
47     private Thread JavaDoc thisThread;
48     private SimpleHTTPServer sas;
49
50     public CallUnregisteredServiceTest() {
51         super(CallUnregisteredServiceTest.class.getName());
52     }
53
54     public CallUnregisteredServiceTest(String JavaDoc testName) {
55         super(testName);
56     }
57
58     protected void setUp() throws Exception JavaDoc {
59         UtilServer.start();
60     }
61
62     protected void tearDown() throws Exception JavaDoc {
63         UtilServer.stop();
64     }
65
66     public void testEchoXMLSync() throws Exception JavaDoc {
67         try {
68             SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
69
70             SOAPEnvelope reqEnv = fac.getDefaultEnvelope();
71             OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
72             OMElement method = fac.createOMElement("echoOMElement", omNs);
73             OMElement value = fac.createOMElement("myValue", omNs);
74             value.addChild(fac.createText(value, "Isaac Assimov, the foundation Sega"));
75             method.addChild(value);
76             reqEnv.getBody().addChild(method);
77
78             Call call = new Call();
79             EndpointReference targetEPR =
80                 new EndpointReference(
81                     AddressingConstants.WSA_TO,
82                     "http://127.0.0.1:"
83                         + (UtilServer.TESTING_PORT)
84                         + "/axis/services/EchoXMLService1");
85             call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
86             call.setTo(targetEPR);
87             SOAPEnvelope resEnv =
88                 (SOAPEnvelope) call.invokeBlocking(operationName.getLocalPart(), reqEnv);
89
90             SOAPBody sb = resEnv.getBody();
91             if (sb.hasFault()) {
92                 throw new AxisFault(sb.getFault().getReason().getSOAPText().getText());
93             }
94             fail("The test must fail due to wrong service Name");
95
96         } catch (AxisFault e) {
97             assertTrue(e.getMessage().indexOf("Service Not found") > 0);
98             tearDown();
99             return;
100         }
101
102     }
103 }
104
Popular Tags