01: /*
02: * $Id: RequestUtilsTest.java 471756 2006-11-06 15:01:43Z husted $
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.struts2;
22:
23: /**
24: * <code>RequestUtilsTest</code>
25: *
26: */
27: import javax.servlet.http.HttpServletRequest;
28:
29: import junit.framework.TestCase;
30:
31: import org.easymock.MockControl;
32:
33: public class RequestUtilsTest extends TestCase {
34:
35: private MockControl control;
36: private HttpServletRequest requestMock;
37:
38: public void testGetServletPathWithServletPathSet() throws Exception {
39: control.expectAndReturn(requestMock.getServletPath(),
40: "/mycontext/");
41: control.replay();
42: assertEquals("/mycontext/", RequestUtils
43: .getServletPath(requestMock));
44: control.verify();
45: }
46:
47: public void testGetServletPathWithRequestURIAndEmptyContextPath()
48: throws Exception {
49: control.expectAndReturn(requestMock.getServletPath(), null);
50: control.expectAndReturn(requestMock.getRequestURI(),
51: "/mycontext/test.jsp");
52: control.expectAndReturn(requestMock.getContextPath(), "");
53: control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
54: control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
55: control.replay();
56: assertEquals("/mycontext/", RequestUtils
57: .getServletPath(requestMock));
58: control.verify();
59: }
60:
61: public void testGetServletPathWithRequestURIAndContextPathSet()
62: throws Exception {
63: control.expectAndReturn(requestMock.getServletPath(), null);
64: control.expectAndReturn(requestMock.getRequestURI(),
65: "/servlet/mycontext/test.jsp");
66: control.expectAndReturn(requestMock.getContextPath(),
67: "/servlet");
68: control.expectAndReturn(requestMock.getContextPath(),
69: "/servlet");
70: control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
71: control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
72: control.replay();
73: assertEquals("/mycontext/", RequestUtils
74: .getServletPath(requestMock));
75: control.verify();
76: }
77:
78: public void testGetServletPathWithRequestURIAndContextPathSetButNoPatchInfo()
79: throws Exception {
80: control.expectAndReturn(requestMock.getServletPath(), null);
81: control.expectAndReturn(requestMock.getRequestURI(),
82: "/servlet/mycontext/");
83: control.expectAndReturn(requestMock.getContextPath(),
84: "/servlet");
85: control.expectAndReturn(requestMock.getContextPath(),
86: "/servlet");
87: control.expectAndReturn(requestMock.getPathInfo(), null);
88: control.replay();
89: assertEquals("/mycontext/", RequestUtils
90: .getServletPath(requestMock));
91: control.verify();
92: }
93:
94: protected void setUp() {
95: control = MockControl.createControl(HttpServletRequest.class);
96: requestMock = (HttpServletRequest) control.getMock();
97: }
98:
99: }
|