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.servlet;
019:
020: import org.w3c.dom.Document;
021:
022: import com.meterware.httpunit.PostMethodWebRequest;
023: import com.meterware.httpunit.WebRequest;
024: import com.meterware.httpunit.WebResponse;
025: import com.meterware.servletunit.ServletUnitClient;
026:
027: import org.apache.cxf.Bus;
028: import org.apache.cxf.BusException;
029: import org.apache.cxf.helpers.DOMUtils;
030: import org.junit.Test;
031:
032: public class SpringServletTest extends AbstractServletTest {
033: @Override
034: protected String getConfiguration() {
035: return "/org/apache/cxf/systest/servlet/web-spring.xml";
036: }
037:
038: @Override
039: protected Bus createBus() throws BusException {
040: // don't set up the bus, let the servlet do it
041: return null;
042: }
043:
044: @Test
045: public void testInvokingSpringBeans() throws Exception {
046:
047: WebRequest req = new PostMethodWebRequest(CONTEXT_URL
048: + "/services/Greeter", getClass().getResourceAsStream(
049: "GreeterMessage.xml"), "text/xml; charset=utf-8");
050:
051: invokingEndpoint(req);
052:
053: req = new PostMethodWebRequest(CONTEXT_URL
054: + "/services/Greeter1", getClass().getResourceAsStream(
055: "GreeterMessage.xml"), "text/xml; charset=utf-8");
056:
057: invokingEndpoint(req);
058: }
059:
060: public void invokingEndpoint(WebRequest req) throws Exception {
061:
062: WebResponse response = newClient().getResponse(req);
063: assertEquals("text/xml", response.getContentType());
064: assertEquals("utf-8", response.getCharacterSet());
065:
066: Document doc = DOMUtils.readXml(response.getInputStream());
067: assertNotNull(doc);
068:
069: addNamespace("h",
070: "http://apache.org/hello_world_soap_http/types");
071: assertValid("/s:Envelope/s:Body", doc);
072: assertValid("//h:sayHiResponse", doc);
073: }
074:
075: @Test
076: public void testGreetMeGetRequest() throws Exception {
077: ServletUnitClient client = newClient();
078: client.setExceptionsThrownOnErrorStatus(true);
079:
080: WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL
081: + "/services/Greeter/greetMe?" + "requestType=hello");
082:
083: WebResponse response = client.getResponse(req);
084: Document doc = DOMUtils.readXml(response.getInputStream());
085: addNamespace("h",
086: "http://apache.org/hello_world_soap_http/types");
087: assertValid("/s:Envelope/s:Body", doc);
088: assertValid("//h:greetMeResponse", doc);
089:
090: req = new GetMethodQueryWebRequest(CONTEXT_URL
091: + "/services/Greeter1/greetMe?" + "requestType=hello");
092:
093: response = client.getResponse(req);
094: doc = DOMUtils.readXml(response.getInputStream());
095: addNamespace("h",
096: "http://apache.org/hello_world_soap_http/types");
097: assertValid("/s:Envelope/s:Body", doc);
098: assertValid("//h:greetMeResponse", doc);
099: }
100:
101: @Test
102: public void testGetWSDL() throws Exception {
103: ServletUnitClient client = newClient();
104: client.setExceptionsThrownOnErrorStatus(true);
105:
106: WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL
107: + "/services/Greeter?wsdl");
108:
109: WebResponse res = client.getResponse(req);
110: assertEquals(200, res.getResponseCode());
111: assertEquals("text/xml", res.getContentType());
112: assertTrue("the wsdl should contain the opertion greetMe", res
113: .getText()
114: .contains("<wsdl:operation name=\"greetMe\">"));
115: assertTrue("the soap address should changed", res.getText()
116: .contains(
117: "<soap:address location=\"" + CONTEXT_URL
118: + "/services/Greeter"));
119:
120: }
121:
122: }
|