KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > systest > basicRPCLit > RPCLitClientServerTest


1 package org.objectweb.celtix.systest.basicRPCLit;
2
3 import java.lang.reflect.UndeclaredThrowableException JavaDoc;
4 import java.net.URL JavaDoc;
5
6 import javax.xml.namespace.QName JavaDoc;
7
8 import junit.framework.Test;
9 import junit.framework.TestSuite;
10
11 import org.objectweb.celtix.systest.common.ClientServerSetupBase;
12 import org.objectweb.celtix.systest.common.ClientServerTestBase;
13
14 import org.objectweb.hello_world_rpclit.GreeterRPCLit;
15 import org.objectweb.hello_world_rpclit.SOAPServiceRPCLit;
16 import org.objectweb.hello_world_rpclit.types.MyComplexStruct;
17
18 public class RPCLitClientServerTest extends ClientServerTestBase {
19
20     private final QName JavaDoc serviceName = new QName JavaDoc("http://objectweb.org/hello_world_rpclit",
21                                                 "SOAPServiceRPCLit");
22     private final QName JavaDoc portName = new QName JavaDoc("http://objectweb.org/hello_world_rpclit",
23                                              "SoapPortRPCLit");
24
25
26     public static Test suite() throws Exception JavaDoc {
27         TestSuite suite = new TestSuite(RPCLitClientServerTest.class);
28         return new ClientServerSetupBase(suite) {
29             public void startServers() throws Exception JavaDoc {
30                 assertTrue("server did not launch correctly", launchServer(Server.class));
31             }
32         };
33     }
34     
35     public void testBasicConnection() throws Exception JavaDoc {
36
37         URL JavaDoc wsdl = getClass().getResource("/wsdl/hello_world_rpc_lit.wsdl");
38         assertNotNull(wsdl);
39
40         SOAPServiceRPCLit service = new SOAPServiceRPCLit(wsdl, serviceName);
41         assertNotNull(service);
42
43         String JavaDoc response1 = new String JavaDoc("Hello Milestone-");
44         String JavaDoc response2 = new String JavaDoc("Bonjour");
45         try {
46             GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
47             for (int idx = 0; idx < 5; idx++) {
48                 String JavaDoc greeting = greeter.greetMe("Milestone-" + idx);
49                 assertNotNull("no response received from service", greeting);
50                 String JavaDoc exResponse = response1 + idx;
51                 assertEquals(exResponse, greeting);
52
53                 String JavaDoc reply = greeter.sayHi();
54                 assertNotNull("no response received from service", reply);
55                 assertEquals(response2, reply);
56             }
57         } catch (UndeclaredThrowableException JavaDoc ex) {
58             throw (Exception JavaDoc)ex.getCause();
59         }
60     }
61     
62     public void testComplexType() throws Exception JavaDoc {
63         
64         URL JavaDoc wsdl = getClass().getResource("/wsdl/hello_world_rpc_lit.wsdl");
65         assertNotNull(wsdl);
66
67         SOAPServiceRPCLit service = new SOAPServiceRPCLit(wsdl, serviceName);
68         assertNotNull(service);
69
70         MyComplexStruct argument = new MyComplexStruct();
71         MyComplexStruct retVal = null;
72         
73         try {
74             GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
75             for (int idx = 0; idx < 5; idx++) {
76                 argument.setElem1("Hello Milestone-" + idx);
77                 argument.setElem2("Bonjour-" + idx);
78                 argument.setElem3(idx);
79                 
80                 retVal = greeter.sendReceiveData(argument);
81                 assertNotNull("no response received from service", retVal);
82                 
83                 assertTrue(argument.getElem1().equals(retVal.getElem1()));
84                 assertTrue(argument.getElem2().equals(retVal.getElem2()));
85                 assertTrue(argument.getElem3() == retVal.getElem3());
86                 
87                 retVal = null;
88             }
89         } catch (UndeclaredThrowableException JavaDoc ex) {
90             throw (Exception JavaDoc)ex.getCause();
91         }
92     }
93     
94
95     public static void main(String JavaDoc[] args) {
96         junit.textui.TestRunner.run(RPCLitClientServerTest.class);
97     }
98 }
99
Popular Tags