1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
34 public class TestSetOriginalURI extends TestCase {
35 SetOriginalURI command = null;
36
37 public TestSetOriginalURI(String _name) {
38 super(_name);
39 }
40
41
42 protected void setUp() throws Exception {
43 this.command = new SetOriginalURI();
44 }
45
46
47 protected void tearDown() {
48 }
49
50 public void testSetOriginalURI()
51 throws Exception {
52 MockHttpServletRequest request =
53 new MockHttpServletRequest("foo/", "bar.do", null, null);
54 MockServletConfig servletConfig = new MockServletConfig();
55 MockServletContext servletContext = new MockServletContext();
56 MockActionServlet servlet =
57 new MockActionServlet(servletContext, servletConfig);
58
59 servlet.initInternal();
60
61 ServletActionContext saContext =
62 new ServletActionContext(servletContext, request,
63 new MockHttpServletResponse());
64
65 saContext.setActionServlet(servlet);
66
67 boolean result = command.execute(saContext);
68
69 assertTrue(!result);
70
71 String uri = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
72
73 assertTrue("Original uri not correct: " + uri, "bar.do".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".equals(uri));
78 }
79
80
81 public static void main(String[] argv) {
82 String[] testCaseList = { TestSetOriginalURI.class.getName() };
83
84 junit.textui.TestRunner.main(testCaseList);
85 }
86 }