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.net.URL;
021: import java.util.ArrayList;
022: import java.util.List;
023: import java.util.logging.Logger;
024:
025: import javax.xml.bind.JAXBElement;
026: import javax.xml.namespace.QName;
027: import javax.xml.ws.Endpoint;
028:
029: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
030: import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
031: import org.apache.hello_world_soap_http.any.Greeter;
032: import org.apache.hello_world_soap_http.any.SOAPService;
033: import org.apache.hello_world_soap_http.any_types.GreeterImpl;
034: import org.apache.hello_world_soap_http.any_types.SayHi.Port;
035: import org.junit.BeforeClass;
036: import org.junit.Test;
037:
038: public final class AnyClientServerTest extends
039: AbstractBusClientServerTestBase {
040:
041: static final Logger LOG = Logger
042: .getLogger(AnyClientServerTest.class.getName());
043: private final QName serviceName = new QName(
044: "http://apache.org/hello_world_soap_http/any",
045: "SOAPService");
046:
047: public static class MyServer extends AbstractBusTestServerBase {
048:
049: protected void run() {
050: Object implementor = new GreeterImpl();
051: String address = "http://localhost:9000/SoapContext/SoapPort";
052: Endpoint.publish(address, implementor);
053:
054: }
055:
056: public static void main(String[] args) {
057: try {
058: MyServer s = new MyServer();
059: s.start();
060: } catch (Exception ex) {
061: ex.printStackTrace();
062: System.exit(-1);
063: } finally {
064: LOG.info("done!");
065: }
066: }
067: }
068:
069: @BeforeClass
070: public static void startServers() throws Exception {
071: assertTrue("server did not launch correctly",
072: launchServer(MyServer.class));
073: }
074:
075: @Test
076: public void testAny() throws Exception {
077: URL wsdl = getClass().getResource("/wsdl/any.wsdl");
078: assertNotNull(wsdl);
079:
080: SOAPService ss = new SOAPService(wsdl, serviceName);
081: Greeter port = ss.getSoapPort();
082:
083: List<Port> any = new ArrayList<Port>();
084: Port anyPort = new Port();
085: Port anyPort1 = new Port();
086: JAXBElement<String> ele1 = new JAXBElement<String>(
087: new QName(
088: "http://apache.org/hello_world_soap_http/other",
089: "port"), String.class, "hello");
090:
091: anyPort.setAny(ele1);
092: JAXBElement<String> ele2 = new JAXBElement<String>(
093: new QName(
094: "http://apache.org/hello_world_soap_http/other",
095: "port"), String.class, "Bon");
096: anyPort1.setAny(ele2);
097:
098: any.add(anyPort);
099: any.add(anyPort1);
100: String rep = port.sayHi(any);
101: assertEquals(rep, "helloBon");
102: }
103:
104: @Test
105: public void testList() throws Exception {
106: URL wsdl = getClass().getResource("/wsdl/any.wsdl");
107: assertNotNull(wsdl);
108:
109: SOAPService ss = new SOAPService(wsdl, serviceName);
110: Greeter port = ss.getSoapPort();
111: List<org.apache.hello_world_soap_http.any_types.SayHi1.Port> list = new ArrayList<org.apache.hello_world_soap_http.any_types.SayHi1.Port>();
112: org.apache.hello_world_soap_http.any_types.SayHi1.Port port1 = new org.apache.hello_world_soap_http.any_types.SayHi1.Port();
113: port1.setRequestType("hello");
114: org.apache.hello_world_soap_http.any_types.SayHi1.Port port2 = new org.apache.hello_world_soap_http.any_types.SayHi1.Port();
115: port2.setRequestType("Bon");
116: list.add(port1);
117: list.add(port2);
118: String rep = port.sayHi1(list);
119: assertEquals(rep, "helloBon");
120: }
121: }
|