001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.systest.jaxws;
019:
020: import java.lang.reflect.UndeclaredThrowableException;
021:
022: import javax.xml.namespace.QName;
023: import javax.xml.ws.Endpoint;
024:
025: import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
026: import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
027: import org.apache.hello_world_rpclit.GreeterRPCLit;
028: import org.apache.hello_world_rpclit.SOAPServiceRPCLit;
029: import org.apache.hello_world_rpclit.types.MyComplexStruct;
030: import org.apache.hello_world_soap_http.RPCLitGreeterImpl;
031: import org.junit.BeforeClass;
032: import org.junit.Test;
033:
034: public class ClientServerRPCLitTest extends
035: AbstractClientServerTestBase {
036:
037: private final QName portName = new QName(
038: "http://apache.org/hello_world_rpclit", "SoapPortRPCLit");
039:
040: public static class Server extends AbstractBusTestServerBase {
041:
042: protected void run() {
043: Object implementor = new RPCLitGreeterImpl();
044: String address = "http://localhost:9002/SOAPServiceRPCLit/SoapPort";
045: Endpoint.publish(address, implementor);
046: }
047:
048: public static void main(String[] args) {
049: try {
050: Server s = new Server();
051: s.start();
052: } catch (Exception ex) {
053: ex.printStackTrace();
054: System.exit(-1);
055: } finally {
056: System.out.println("done!");
057: }
058: }
059: }
060:
061: @BeforeClass
062: public static void startServers() throws Exception {
063: assertTrue("server did not launch correctly",
064: launchServer(Server.class));
065: }
066:
067: @Test
068: public void testBasicConnection() throws Exception {
069:
070: SOAPServiceRPCLit service = new SOAPServiceRPCLit();
071: assertNotNull(service);
072:
073: String response1 = new String("Hello Milestone-");
074: String response2 = new String("Bonjour");
075: try {
076: GreeterRPCLit greeter = service.getPort(portName,
077: GreeterRPCLit.class);
078: for (int idx = 0; idx < 1; idx++) {
079: String greeting = greeter.greetMe("Milestone-" + idx);
080: assertNotNull("no response received from service",
081: greeting);
082: String exResponse = response1 + idx;
083: assertEquals(exResponse, greeting);
084:
085: String reply = greeter.sayHi();
086: assertNotNull("no response received from service",
087: reply);
088: assertEquals(response2, reply);
089: }
090: } catch (UndeclaredThrowableException ex) {
091: throw (Exception) ex.getCause();
092: }
093: }
094:
095: @Test
096: public void testComplexType() throws Exception {
097: SOAPServiceRPCLit service = new SOAPServiceRPCLit();
098: assertNotNull(service);
099:
100: GreeterRPCLit greeter = service.getPort(portName,
101: GreeterRPCLit.class);
102:
103: MyComplexStruct in = new MyComplexStruct();
104: in.setElem1("elem1");
105: in.setElem2("elem2");
106: in.setElem3(45);
107:
108: try {
109: MyComplexStruct out = greeter.sendReceiveData(in);
110: assertNotNull("no response received from service", out);
111: assertEquals(in.getElem1(), out.getElem1());
112: assertEquals(in.getElem2(), out.getElem2());
113: assertEquals(in.getElem3(), out.getElem3());
114: } catch (UndeclaredThrowableException ex) {
115: throw (Exception) ex.getCause();
116: }
117:
118: }
119: }
|