01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.systest.jaxws;
19:
20: import java.io.InputStream;
21: import java.lang.reflect.UndeclaredThrowableException;
22: import java.net.HttpURLConnection;
23: import java.util.HashMap;
24: import java.util.Map;
25:
26: import javax.xml.xpath.XPathConstants;
27:
28: import org.w3c.dom.Document;
29: import org.w3c.dom.Node;
30:
31: import org.apache.cxf.binding.soap.Soap11;
32: import org.apache.cxf.greeter_control.Greeter;
33: import org.apache.cxf.greeter_control.GreeterService;
34: import org.apache.cxf.helpers.XMLUtils;
35: import org.apache.cxf.helpers.XPathUtils;
36: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
37: import org.junit.BeforeClass;
38: import org.junit.Test;
39:
40: public class ClientServerGreeterNoWsdlTest extends
41: AbstractBusClientServerTestBase {
42:
43: @BeforeClass
44: public static void startServers() throws Exception {
45: assertTrue("server did not launch correctly",
46: launchServer(ServerGreeterNoWsdl.class));
47: }
48:
49: @Test
50: public void testInvocation() throws Exception {
51:
52: GreeterService service = new GreeterService();
53: assertNotNull(service);
54:
55: try {
56: Greeter greeter = service.getGreeterPort();
57:
58: String greeting = greeter.greetMe("Bonjour");
59: assertNotNull("no response received from service", greeting);
60: assertEquals("Hello Bonjour", greeting);
61:
62: } catch (UndeclaredThrowableException ex) {
63: throw (Exception) ex.getCause();
64: }
65: }
66:
67: // test the http get invocation
68:
69: @Test
70: public void testGetGreetMe() throws Exception {
71: HttpURLConnection httpConnection = getHttpConnection("http://localhost:9020/SoapContext/GreeterPort/greetMe/requestType/cxf");
72: httpConnection.connect();
73:
74: assertEquals(200, httpConnection.getResponseCode());
75:
76: assertEquals("text/xml; charset=utf-8", httpConnection
77: .getContentType());
78: assertEquals("OK", httpConnection.getResponseMessage());
79:
80: InputStream in = httpConnection.getInputStream();
81: assertNotNull(in);
82:
83: Document doc = XMLUtils.parse(in);
84: assertNotNull(doc);
85:
86: Map<String, String> ns = new HashMap<String, String>();
87: ns.put("soap", Soap11.SOAP_NAMESPACE);
88: ns.put("ns2", "http://cxf.apache.org/greeter_control/types");
89: XPathUtils xu = new XPathUtils(ns);
90: Node body = (Node) xu.getValue("/soap:Envelope/soap:Body", doc,
91: XPathConstants.NODE);
92: assertNotNull(body);
93: String response = (String) xu.getValue(
94: "//ns2:greetMeResponse/ns2:responseType/text()", body,
95: XPathConstants.STRING);
96: assertEquals("Hello cxf", response);
97: }
98:
99: }
|