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.commons.chain.web.servlet.ServletWebContext;
26 import org.apache.struts.chain.contexts.ServletActionContext;
27 import org.apache.struts.config.ForwardConfig;
28 import org.apache.struts.mock.MockActionServlet;
29 import org.apache.struts.mock.MockHttpServletRequest;
30 import org.apache.struts.mock.MockHttpServletResponse;
31 import org.apache.struts.mock.MockPrincipal;
32 import org.apache.struts.mock.MockServletConfig;
33 import org.apache.struts.mock.MockServletContext;
34
35
36 public class TestPerformForward extends TestCase {
37 MockHttpServletRequest request = null;
38 MockPrincipal principal = null;
39 ServletWebContext swContext = null;
40 ServletActionContext saContext = null;
41 PerformForward command = null;
42
43 public TestPerformForward(String _name) {
44 super(_name);
45 }
46
47
48 protected void setUp() throws Exception {
49 this.request = new MockHttpServletRequest();
50 this.principal =
51 new MockPrincipal("Mr. Macri", new String[] { "administrator" });
52 this.request.setUserPrincipal(principal);
53
54 MockServletConfig servletConfig = new MockServletConfig();
55 MockServletContext servletContext = new MockServletContext();
56 MockActionServlet servlet =
57 new MockActionServlet(servletContext, servletConfig);
58
59 servlet.initInternal();
60
61 this.saContext =
62 new ServletActionContext(servletContext, request,
63 new MockHttpServletResponse());
64
65 this.saContext.setActionServlet(servlet);
66 this.command = new PerformForward();
67 }
68
69
70 protected void tearDown() {
71 }
72
73 public void testNullForwardPath()
74 throws Exception {
75 ForwardConfig config = new ForwardConfig();
76
77 config.setPath(null);
78
79 try {
80 command.perform(saContext, config);
81 fail(
82 "Didn't throw an illegal argument exception on null forward path");
83 } catch (IllegalArgumentException ex) {
84 System.out.println("exception: " + ex.getMessage());
85
86
87 }
88 }
89
90
91 public static void main(String[] argv) {
92 String[] testCaseList = { TestPerformForward.class.getName() };
93
94 junit.textui.TestRunner.main(testCaseList);
95 }
96 }