01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05:
06: package com.opensymphony.webwork;
07:
08: /**
09: * <code>RequestUtilsTest</code>
10: *
11: * @author Rainer Hermanns
12: * @version $Id: RequestUtilsTest.java 2335 2006-03-08 18:09:29Z rainerh $
13: */
14: import junit.framework.TestCase;
15:
16: import javax.servlet.http.HttpServletRequest;
17:
18: import org.easymock.MockControl;
19:
20: public class RequestUtilsTest extends TestCase {
21:
22: private MockControl control;
23: private HttpServletRequest requestMock;
24:
25: public void testGetServletPathWithServletPathSet() throws Exception {
26: control.expectAndReturn(requestMock.getServletPath(),
27: "/mycontext/");
28: control.replay();
29: assertEquals("/mycontext/", RequestUtils
30: .getServletPath(requestMock));
31: control.verify();
32: }
33:
34: public void testGetServletPathWithRequestURIAndEmptyContextPath()
35: throws Exception {
36: control.expectAndReturn(requestMock.getServletPath(), null);
37: control.expectAndReturn(requestMock.getRequestURI(),
38: "/mycontext/test.jsp");
39: control.expectAndReturn(requestMock.getContextPath(), "");
40: control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
41: control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
42: control.replay();
43: assertEquals("/mycontext/", RequestUtils
44: .getServletPath(requestMock));
45: control.verify();
46: }
47:
48: public void testGetServletPathWithRequestURIAndContextPathSet()
49: throws Exception {
50: control.expectAndReturn(requestMock.getServletPath(), null);
51: control.expectAndReturn(requestMock.getRequestURI(),
52: "/servlet/mycontext/test.jsp");
53: control.expectAndReturn(requestMock.getContextPath(),
54: "/servlet");
55: control.expectAndReturn(requestMock.getContextPath(),
56: "/servlet");
57: control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
58: control.expectAndReturn(requestMock.getPathInfo(), "test.jsp");
59: control.replay();
60: assertEquals("/mycontext/", RequestUtils
61: .getServletPath(requestMock));
62: control.verify();
63: }
64:
65: public void testGetServletPathWithRequestURIAndContextPathSetButNoPatchInfo()
66: throws Exception {
67: control.expectAndReturn(requestMock.getServletPath(), null);
68: control.expectAndReturn(requestMock.getRequestURI(),
69: "/servlet/mycontext/");
70: control.expectAndReturn(requestMock.getContextPath(),
71: "/servlet");
72: control.expectAndReturn(requestMock.getContextPath(),
73: "/servlet");
74: control.expectAndReturn(requestMock.getPathInfo(), null);
75: control.replay();
76: assertEquals("/mycontext/", RequestUtils
77: .getServletPath(requestMock));
78: control.verify();
79: }
80:
81: protected void setUp() {
82: control = MockControl.createControl(HttpServletRequest.class);
83: requestMock = (HttpServletRequest) control.getMock();
84: }
85:
86: }
|