KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > sandesha > intergratedtest > TCScenarioTest


1 /*
2  * Copyright 1999-2004 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.sandesha.intergratedtest;
18
19 import junit.framework.TestCase;
20 import org.apache.axis.client.Call;
21 import org.apache.axis.client.Service;
22 import org.apache.axis.components.uuid.UUIDGen;
23 import org.apache.axis.components.uuid.UUIDGenFactory;
24 import org.apache.axis.deployment.wsdd.WSDDDeployment;
25 import org.apache.axis.deployment.wsdd.WSDDDocument;
26 import org.apache.axis.encoding.XMLType;
27 import org.apache.axis.transport.http.SimpleAxisServer;
28 import org.apache.sandesha.Constants;
29 import org.apache.sandesha.RMReport;
30 import org.apache.sandesha.SandeshaContext;
31 import org.w3c.dom.Document JavaDoc;
32
33 import javax.xml.namespace.QName JavaDoc;
34 import javax.xml.parsers.DocumentBuilder JavaDoc;
35 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
36 import javax.xml.rpc.ParameterMode JavaDoc;
37 import java.io.File JavaDoc;
38 import java.net.ServerSocket JavaDoc;
39
40 /**
41  * Created by IntelliJ IDEA.
42  * User: Jaliya
43  * Date: May 20, 2005
44  * Time: 4:47:43 PM
45  */

46 public class TCScenarioTest extends TestCase {
47     private static SimpleAxisServer sas = null;
48
49     private static String JavaDoc defaultServerPort = "5555";
50     private static String JavaDoc defaultClientPort = "9090";
51     private static boolean serverStarted = false;
52     private static int testCount = 5;
53
54     private static String JavaDoc targetURL = "http://127.0.0.1:" + defaultServerPort +
55             "/axis/services/RMTestService";
56
57
58     public void setUp() throws Exception JavaDoc {
59         if (!serverStarted) {
60             sas = new SimpleAxisServer();
61
62             DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
63             dbf.setNamespaceAware(true);
64             DocumentBuilder JavaDoc db = dbf.newDocumentBuilder();
65
66             Document doc = db.parse(new File JavaDoc("test-resources/server-config.wsdd"));
67             WSDDDocument wsdddoc = new WSDDDocument(doc);
68             WSDDDeployment wsdddep = wsdddoc.getDeployment();
69             sas.setMyConfig(wsdddep);
70
71             sas.setServerSocket(new ServerSocket JavaDoc((new Integer JavaDoc(defaultServerPort)).intValue()));
72             sas.start();
73             serverStarted = true;
74         }
75     }
76
77     public void tearDown() throws InterruptedException JavaDoc {
78         if (testCount == 0) {
79             Thread.sleep(5000);
80             sas.stop();
81         }
82     }
83
84     /**
85      * This test will test the Ping interop scenario. 3 One-way messages are sent with
86      * <wsrm:AckTo> set to ANONYMOUS URI and acknowledgements are received.
87      *
88      * @throws Exception
89      */

90     public void testPingSync() throws Exception JavaDoc {
91         System.out.println(" Synchronous Ping Test Started");
92
93         Service service = new Service();
94         Call call = (Call) service.createCall();
95
96         SandeshaContext ctx = new SandeshaContext(Constants.SYNCHRONOUS);
97         ctx.initCall(call, targetURL, "urn:wsrm:Ping", Constants.ClientProperties.IN_ONLY);
98
99         call.setOperationName(new QName JavaDoc("http://tempuri.org/", "Ping"));
100         call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);
101
102
103         call.invoke(new Object JavaDoc[]{"Ping One"});
104         ctx.setLastMessage(call);
105         call.invoke(new Object JavaDoc[]{"Ping Two"});
106
107         RMReport report = ctx.endSequence();
108
109         assertEquals(report.isAllAcked(), true);
110         assertEquals(report.getNumberOfReturnMessages(), 0);
111         testCount--;
112         System.out.println(" Synchronous Ping Test Finished");
113     }
114
115     /**
116      * This test will test the Ping interop scenario. 3 One-way messages are sent with
117      * <wsrm:AckTo> set to asynchronous client URI and acknowledgements are received.
118      *
119      * @throws Exception
120      */

121     public void testPingAsync() throws Exception JavaDoc {
122         System.out.println(" Asynchronous Ping Test Started");
123
124         Service service = new Service();
125         Call call = (Call) service.createCall();
126
127         SandeshaContext ctx = new SandeshaContext();
128
129         ctx.setAcksToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService");
130         ctx.setReplyToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService");
131         ctx.initCall(call, targetURL, "urn:wsrm:ping", Constants.ClientProperties.IN_ONLY);
132
133         call.setOperationName(new QName JavaDoc("http://tempuri.org", "Ping"));
134         call.addParameter("Text", XMLType.XSD_STRING, ParameterMode.IN);
135
136         call.invoke(new Object JavaDoc[]{"Ping One"});
137         ctx.setLastMessage(call);
138         call.invoke(new Object JavaDoc[]{"Ping Two"});
139
140         RMReport report = ctx.endSequence();
141
142         assertEquals(report.isAllAcked(), true);
143         assertEquals(report.getNumberOfReturnMessages(), 0);
144         testCount--;
145         System.out.println(" Asynchronous Ping Test Finished");
146
147     }
148
149     /**
150      * This test will test the echoString interop scenario. 3 echo messages are sent with
151      * <wsrm:AckTo> set to ANONYMOUS URI. Acknowledgements relating to the scenario is received
152      * using the same HTTP connection used in the request message while the responses are
153      * received using the asynchronous client side endpoint.
154      *
155      * @throws Exception
156      */

157
158     public void testEchoSyncAck() throws Exception JavaDoc {
159         System.out.println(" Echo(Sync Ack) Test Started");
160
161         UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(); //Can use this for continuous testing.
162
String JavaDoc str = uuidGen.nextUUID();
163
164         Service service = new Service();
165         Call call = (Call) service.createCall();
166
167         SandeshaContext ctx = new SandeshaContext();
168
169         ctx.setAcksToURL(Constants.WSA.NS_ADDRESSING_ANONYMOUS);
170         ctx.setReplyToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService");
171         ctx.setSendOffer(true);
172
173         ctx.initCall(call, targetURL, "urn:wsrm:echoString", Constants.ClientProperties.IN_OUT);
174
175         call.setOperationName(new QName JavaDoc("http://tempuri.org/", "echoString"));
176
177         call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);
178         call.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN);
179         call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
180
181         String JavaDoc ret = (String JavaDoc) call.invoke(new Object JavaDoc[]{" Echo 1 ", str});
182         System.out.println(" The Response for First Messsage is :" + ret);
183
184         ctx.setLastMessage(call);
185         ret = (String JavaDoc) call.invoke(new Object JavaDoc[]{" Echo 2 ", str});
186         System.out.println(" The Response for Second Messsage is :" + ret);
187
188         RMReport report = ctx.endSequence();
189
190         assertEquals(report.isAllAcked(), true);
191         assertEquals(report.getNumberOfReturnMessages(), 2);
192         testCount--;
193         System.out.println(" Echo(Sync Ack) Test Finished");
194     }
195
196     /**
197      * This test will test the echoString interop scenario. 3 echo messages are sent with
198      * <wsrm:AckTo> set to asynchronous client side endpoint. Acknowledgements and responses
199      * are both received using the asynchronous client side endpoint.
200      *
201      * @throws Exception
202      */

203     public void testEchoAsyncAck() throws Exception JavaDoc {
204         System.out.println(" Echo(Aync Ack) Test Started");
205
206         UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(); //Can use this for continuous testing.
207
String JavaDoc str = uuidGen.nextUUID();
208
209         Service service = new Service();
210         Call call = (Call) service.createCall();
211
212         SandeshaContext ctx = new SandeshaContext();
213
214         ctx.setAcksToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService");
215         ctx.setReplyToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService");
216         ctx.setSendOffer(true);
217
218         ctx.initCall(call, targetURL, "urn:wsrm:echoString", Constants.ClientProperties.IN_OUT);
219
220         call.setOperationName(new QName JavaDoc("http://tempuri.org/", "echoString"));
221
222         call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);
223         call.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN);
224         call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
225
226         String JavaDoc ret = (String JavaDoc) call.invoke(new Object JavaDoc[]{" Echo 1 ", str});
227         System.out.println(" The Response for First Messsage is :" + ret);
228
229         ctx.setLastMessage(call);
230         ret = (String JavaDoc) call.invoke(new Object JavaDoc[]{" Echo 2 ", str});
231         System.out.println(" The Response for Second Messsage is :" + ret);
232
233         RMReport report = ctx.endSequence();
234
235         assertEquals(report.isAllAcked(), true);
236         assertEquals(report.getNumberOfReturnMessages(), 2);
237         testCount--;
238         System.out.println(" Echo(Async Ack) Test Finished");
239     }
240
241     /**
242      * This test will test the echoString interop scenario and Ping scenario together.
243      * Response of each echoString request is used to invoke a Ping service. This test tests the
244      * capability of Sandesha Client side endpoint to handle multiple web service requests
245      * at the same time.
246      *
247      * @throws Exception
248      */

249     public void testEchoPing() throws Exception JavaDoc {
250         System.out.println(" Echo and Ping Combined Test Started");
251         UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(); //Can use this for continuous testing.
252
String JavaDoc str = uuidGen.nextUUID();
253
254         Service service = new Service();
255         Call echoCall = (Call) service.createCall();
256
257         SandeshaContext ctx = new SandeshaContext();
258         //------------------------ECHO--------------------------------------------
259

260         ctx.setAcksToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService");
261         ctx.setReplyToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService");
262         ctx.setSendOffer(true);
263         ctx.initCall(echoCall, targetURL, "urn:wsrm:echoString", Constants.ClientProperties.IN_OUT);
264
265         echoCall.setOperationName(new QName JavaDoc("http://tempuri.org/", "echoString"));
266
267         echoCall.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);
268         echoCall.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN);
269         echoCall.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
270         //----------------------ECHO------------------------------------------------
271

272         //------------------------PING--------------------------------------------
273
Service pingService = new Service();
274         Call pingCall = (Call) pingService.createCall();
275         SandeshaContext pingCtx = new SandeshaContext();
276         pingCtx.setAcksToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService");
277         pingCtx.setReplyToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService");
278
279         pingCtx.initCall(pingCall, targetURL, "urn:wsrm:Ping", Constants.ClientProperties.IN_ONLY);
280
281         pingCall.setOperationName(new QName JavaDoc("http://tempuri.org/", "ping"));
282         pingCall.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN);
283         //----------------------PING------------------------------------------------
284

285
286         String JavaDoc ret = (String JavaDoc) echoCall.invoke(new Object JavaDoc[]{" Echo 1 ", str});
287         System.out.println(" The Response for First Messsage is :" + ret);
288         pingCall.invoke(new Object JavaDoc[]{ret});
289
290         ctx.setLastMessage(echoCall);
291         ret = (String JavaDoc) echoCall.invoke(new Object JavaDoc[]{" Echo 2 ", str});
292         System.out.println(" The Response for Second Messsage is :" + ret);
293         pingCall.invoke(new Object JavaDoc[]{ret});
294
295         pingCtx.setLastMessage(pingCall);
296         pingCall.invoke(new Object JavaDoc[]{ret});
297
298         RMReport echoReport = ctx.endSequence();
299         RMReport pingReport = pingCtx.endSequence();
300
301         assertEquals(echoReport.isAllAcked(), true);
302         assertEquals(echoReport.getNumberOfReturnMessages(), 2);
303
304         assertEquals(pingReport.isAllAcked(), true);
305         assertEquals(pingReport.getNumberOfReturnMessages(), 0);
306         testCount--;
307         System.out.println(" Echo and Ping Combined Test Finished");
308
309     }
310
311 }
312
Popular Tags