001: package org.objectweb.celtix.systest.basicRPCLit;
002:
003: import java.lang.reflect.UndeclaredThrowableException;
004: import java.net.URL;
005:
006: import javax.xml.namespace.QName;
007:
008: import junit.framework.Test;
009: import junit.framework.TestSuite;
010:
011: import org.objectweb.celtix.systest.common.ClientServerSetupBase;
012: import org.objectweb.celtix.systest.common.ClientServerTestBase;
013:
014: import org.objectweb.hello_world_rpclit.GreeterRPCLit;
015: import org.objectweb.hello_world_rpclit.SOAPServiceRPCLit;
016: import org.objectweb.hello_world_rpclit.types.MyComplexStruct;
017:
018: public class RPCLitClientServerTest extends ClientServerTestBase {
019:
020: private final QName serviceName = new QName(
021: "http://objectweb.org/hello_world_rpclit",
022: "SOAPServiceRPCLit");
023: private final QName portName = new QName(
024: "http://objectweb.org/hello_world_rpclit", "SoapPortRPCLit");
025:
026: public static Test suite() throws Exception {
027: TestSuite suite = new TestSuite(RPCLitClientServerTest.class);
028: return new ClientServerSetupBase(suite) {
029: public void startServers() throws Exception {
030: assertTrue("server did not launch correctly",
031: launchServer(Server.class));
032: }
033: };
034: }
035:
036: public void testBasicConnection() throws Exception {
037:
038: URL wsdl = getClass().getResource(
039: "/wsdl/hello_world_rpc_lit.wsdl");
040: assertNotNull(wsdl);
041:
042: SOAPServiceRPCLit service = new SOAPServiceRPCLit(wsdl,
043: serviceName);
044: assertNotNull(service);
045:
046: String response1 = new String("Hello Milestone-");
047: String response2 = new String("Bonjour");
048: try {
049: GreeterRPCLit greeter = service.getPort(portName,
050: GreeterRPCLit.class);
051: for (int idx = 0; idx < 5; idx++) {
052: String greeting = greeter.greetMe("Milestone-" + idx);
053: assertNotNull("no response received from service",
054: greeting);
055: String exResponse = response1 + idx;
056: assertEquals(exResponse, greeting);
057:
058: String reply = greeter.sayHi();
059: assertNotNull("no response received from service",
060: reply);
061: assertEquals(response2, reply);
062: }
063: } catch (UndeclaredThrowableException ex) {
064: throw (Exception) ex.getCause();
065: }
066: }
067:
068: public void testComplexType() throws Exception {
069:
070: URL wsdl = getClass().getResource(
071: "/wsdl/hello_world_rpc_lit.wsdl");
072: assertNotNull(wsdl);
073:
074: SOAPServiceRPCLit service = new SOAPServiceRPCLit(wsdl,
075: serviceName);
076: assertNotNull(service);
077:
078: MyComplexStruct argument = new MyComplexStruct();
079: MyComplexStruct retVal = null;
080:
081: try {
082: GreeterRPCLit greeter = service.getPort(portName,
083: GreeterRPCLit.class);
084: for (int idx = 0; idx < 5; idx++) {
085: argument.setElem1("Hello Milestone-" + idx);
086: argument.setElem2("Bonjour-" + idx);
087: argument.setElem3(idx);
088:
089: retVal = greeter.sendReceiveData(argument);
090: assertNotNull("no response received from service",
091: retVal);
092:
093: assertTrue(argument.getElem1()
094: .equals(retVal.getElem1()));
095: assertTrue(argument.getElem2()
096: .equals(retVal.getElem2()));
097: assertTrue(argument.getElem3() == retVal.getElem3());
098:
099: retVal = null;
100: }
101: } catch (UndeclaredThrowableException ex) {
102: throw (Exception) ex.getCause();
103: }
104: }
105:
106: public static void main(String[] args) {
107: junit.textui.TestRunner.run(RPCLitClientServerTest.class);
108: }
109: }
|