01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: // Created on Dec 6, 2006
18: package edu.iu.uis.eden.server;
19:
20: import java.io.IOException;
21:
22: import javax.servlet.ServletException;
23:
24: import junit.framework.TestCase;
25:
26: import org.springframework.mock.web.MockHttpServletRequest;
27: import org.springframework.mock.web.MockHttpServletResponse;
28: import org.springframework.mock.web.MockServletConfig;
29: import org.springframework.mock.web.MockServletContext;
30:
31: /**
32: * Tests the RequestForwardingServlet used to remap WSDL location
33: * @author Aaron Hamid (arh14 at cornell dot edu)
34: */
35: public class RequestForwardingServletTest extends TestCase {
36:
37: protected static void testForward(String sourcePattern,
38: String targetPath, String sourcePath, String forwardedPath)
39: throws ServletException, IOException {
40: MockServletConfig cfg = new MockServletConfig(
41: new MockServletContext());
42: cfg.addInitParameter(sourcePattern, targetPath);
43: RequestForwardingServlet servlet = new RequestForwardingServlet();
44: servlet.init(cfg);
45: MockHttpServletRequest request = new MockHttpServletRequest(
46: "GET", sourcePath);
47: MockHttpServletResponse response = new MockHttpServletResponse();
48: servlet.service(request, response);
49: assertEquals(response.getForwardedUrl(), forwardedPath);
50: }
51:
52: public void test() throws Exception {
53: testForward(
54: ".*/(\\w+)\\.wsdl",
55: "/services/{0}?wsdl",
56: "http://bogushost/wsdl/WorkflowDocumentActionsService.wsdl",
57: "/services/WorkflowDocumentActionsService?wsdl");
58:
59: testForward(
60: ".*/(\\w+)\\.wsdl",
61: "/services/{0}?wsdl",
62: "http://bogushost/any/path/really/WorkflowDocumentActionsService.wsdl",
63: "/services/WorkflowDocumentActionsService?wsdl");
64:
65: testForward(
66: ".*/(\\w+)\\.wsdl",
67: "/services/{0}?wsdl",
68: "http://bogushost/any/path/really/Invalid Service Name.wsdl",
69: null);
70: }
71: }
|