01: /*
02: * $Id: TestSetOriginalURI.java 481833 2006-12-03 17:32:52Z niallp $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts.chain.commands.servlet;
22:
23: import junit.framework.TestCase;
24:
25: import org.apache.struts.Globals;
26: import org.apache.struts.chain.contexts.ServletActionContext;
27: import org.apache.struts.mock.MockActionServlet;
28: import org.apache.struts.mock.MockHttpServletRequest;
29: import org.apache.struts.mock.MockHttpServletResponse;
30: import org.apache.struts.mock.MockServletConfig;
31: import org.apache.struts.mock.MockServletContext;
32:
33: /* JUnitTest case for class: org.apache.struts.chain.commands.servlet.SetOriginalURI */
34: public class TestSetOriginalURI extends TestCase {
35: SetOriginalURI command = null;
36:
37: public TestSetOriginalURI(String _name) {
38: super (_name);
39: }
40:
41: /* setUp method for test case */
42: protected void setUp() throws Exception {
43: this .command = new SetOriginalURI();
44: }
45:
46: /* tearDown method for test case */
47: protected void tearDown() {
48: }
49:
50: public void testSetOriginalURI() throws Exception {
51: MockHttpServletRequest request = new MockHttpServletRequest(
52: "foo/", "bar.do", null, null);
53: MockServletConfig servletConfig = new MockServletConfig();
54: MockServletContext servletContext = new MockServletContext();
55: MockActionServlet servlet = new MockActionServlet(
56: servletContext, servletConfig);
57:
58: servlet.initInternal();
59:
60: ServletActionContext saContext = new ServletActionContext(
61: servletContext, request, new MockHttpServletResponse());
62:
63: saContext.setActionServlet(servlet);
64:
65: boolean result = command.execute(saContext);
66:
67: assertTrue(!result);
68:
69: String uri = (String) request
70: .getAttribute(Globals.ORIGINAL_URI_KEY);
71:
72: assertTrue("Original uri not correct: " + uri, "bar.do"
73: .equals(uri));
74:
75: request.setPathElements("foo/", "bar2.do", null, null);
76: uri = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
77: assertTrue("Original uri not correct: " + uri, "bar.do"
78: .equals(uri));
79: }
80:
81: /* Executes the test case */
82: public static void main(String[] argv) {
83: String[] testCaseList = { TestSetOriginalURI.class.getName() };
84:
85: junit.textui.TestRunner.main(testCaseList);
86: }
87: }
|