1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.components;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.apache.struts2.StrutsTestCase;
28 import org.springframework.mock.web.MockHttpServletRequest;
29 import org.springframework.mock.web.MockHttpServletResponse;
30
31 import com.mockobjects.dynamic.Mock;
32 import com.opensymphony.xwork2.util.ValueStack;
33
34 public class ActionComponentTest extends StrutsTestCase {
35
36 public void testCreateParametersForContext() throws Exception {
37 MockHttpServletRequest req = new MockHttpServletRequest();
38 MockHttpServletResponse res = new MockHttpServletResponse();
39 Mock mockValueStack = new Mock(ValueStack.class);
40 HashMap ctx = new HashMap();
41 mockValueStack.expectAndReturn("getContext", ctx);
42 mockValueStack.expectAndReturn("getContext", ctx);
43 mockValueStack.expectAndReturn("getContext", ctx);
44
45 ActionComponent comp = new ActionComponent((ValueStack) mockValueStack.proxy(), req, res);
46 comp.addParameter("foo", "bar");
47 comp.addParameter("baz", new String[]{"jim", "sarah"});
48 Map params = comp.createParametersForContext();
49 assertNotNull(params);
50 assertEquals(2, params.size());
51 assertEquals("bar", ((String[])params.get("foo"))[0]);
52 assertEquals(2, ((String[])params.get("baz")).length);
53 mockValueStack.verify();
54 }
55 }