001: /*
002: * Copyright 2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.transport.http;
018:
019: import java.io.File;
020: import java.io.IOException;
021:
022: import junit.framework.TestCase;
023: import org.apache.commons.httpclient.HttpClient;
024: import org.apache.commons.httpclient.HttpStatus;
025: import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
026: import org.apache.commons.httpclient.methods.PostMethod;
027: import org.mortbay.jetty.Server;
028: import org.mortbay.jetty.servlet.Context;
029: import org.mortbay.jetty.servlet.ServletHolder;
030: import org.springframework.core.io.ClassPathResource;
031: import org.springframework.core.io.Resource;
032: import org.springframework.ws.transport.TransportConstants;
033:
034: public class MessageDispatcherServletIntegrationTest extends TestCase {
035:
036: private Server jettyServer;
037:
038: private HttpClient client;
039:
040: private static final String CONTENT_TYPE = "Content-Type";
041:
042: protected final void setUp() throws Exception {
043: jettyServer = new Server(8888);
044: Context jettyContext = new Context(jettyServer, "/");
045: File dir = new File(getClass().getResource(".").toURI());
046: jettyContext.setResourceBase(dir.getAbsolutePath());
047: ServletHolder servletHolder = new ServletHolder(
048: new MessageDispatcherServlet());
049: servletHolder.setName("spring-ws");
050: jettyContext.addServlet(servletHolder, "/*");
051: jettyServer.start();
052: client = new HttpClient();
053: }
054:
055: protected void tearDown() throws Exception {
056: jettyServer.stop();
057: }
058:
059: public void testNoResponse() throws IOException {
060: PostMethod postMethod = new PostMethod(
061: "http://localhost:8888/service");
062: postMethod.addRequestHeader(CONTENT_TYPE, "text/xml");
063: postMethod.addRequestHeader(
064: TransportConstants.HEADER_SOAP_ACTION,
065: "http://springframework.org/spring-ws/NoResponse");
066: Resource soapRequest = new ClassPathResource("soapRequest.xml",
067: MessageDispatcherServletIntegrationTest.class);
068: postMethod.setRequestEntity(new InputStreamRequestEntity(
069: soapRequest.getInputStream()));
070: client.executeMethod(postMethod);
071: assertEquals("Invalid Response Code", HttpStatus.SC_ACCEPTED,
072: postMethod.getStatusCode());
073: assertEquals("Response retrieved", 0, postMethod
074: .getResponseContentLength());
075: }
076:
077: public void testResponse() throws IOException {
078: PostMethod postMethod = new PostMethod(
079: "http://localhost:8888/service");
080: postMethod.addRequestHeader(CONTENT_TYPE, "text/xml");
081: postMethod.addRequestHeader(
082: TransportConstants.HEADER_SOAP_ACTION,
083: "http://springframework.org/spring-ws/Response");
084: Resource soapRequest = new ClassPathResource("soapRequest.xml",
085: MessageDispatcherServletIntegrationTest.class);
086: postMethod.setRequestEntity(new InputStreamRequestEntity(
087: soapRequest.getInputStream()));
088: client.executeMethod(postMethod);
089: assertEquals("Invalid Response Code", HttpStatus.SC_OK,
090: postMethod.getStatusCode());
091: assertTrue("No Response retrieved", postMethod
092: .getResponseContentLength() > 0);
093: }
094:
095: public void testNoEndpoint() throws IOException {
096: PostMethod postMethod = new PostMethod(
097: "http://localhost:8888/service");
098: postMethod.addRequestHeader(CONTENT_TYPE, "text/xml");
099: postMethod.addRequestHeader(
100: TransportConstants.HEADER_SOAP_ACTION,
101: "http://springframework.org/spring-ws/NoEndpoint");
102: Resource soapRequest = new ClassPathResource("soapRequest.xml",
103: MessageDispatcherServletIntegrationTest.class);
104: postMethod.setRequestEntity(new InputStreamRequestEntity(
105: soapRequest.getInputStream()));
106: client.executeMethod(postMethod);
107: assertEquals("Invalid Response Code", HttpStatus.SC_NOT_FOUND,
108: postMethod.getStatusCode());
109: assertEquals("Response retrieved", 0, postMethod
110: .getResponseContentLength());
111: }
112:
113: public void testFault() throws IOException {
114: PostMethod postMethod = new PostMethod(
115: "http://localhost:8888/service");
116: postMethod.addRequestHeader(CONTENT_TYPE, "text/xml");
117: postMethod.addRequestHeader(
118: TransportConstants.HEADER_SOAP_ACTION,
119: "http://springframework.org/spring-ws/Fault");
120: Resource soapRequest = new ClassPathResource("soapRequest.xml",
121: MessageDispatcherServletIntegrationTest.class);
122: postMethod.setRequestEntity(new InputStreamRequestEntity(
123: soapRequest.getInputStream()));
124: client.executeMethod(postMethod);
125: assertEquals("Invalid Response Code",
126: HttpStatus.SC_INTERNAL_SERVER_ERROR, postMethod
127: .getStatusCode());
128: assertTrue("No Response retrieved", postMethod
129: .getResponseContentLength() > 0);
130: }
131:
132: }
|