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.portlet.interceptor;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import javax.portlet.PortletConfig;
28 import javax.portlet.PortletRequest;
29
30 import junit.framework.TestCase;
31
32 import org.apache.struts2.portlet.PortletActionConstants;
33 import org.easymock.EasyMock;
34
35 import com.opensymphony.xwork2.ActionContext;
36 import com.opensymphony.xwork2.ActionInvocation;
37
38 public class PortletAwareInterceptorTest extends TestCase implements PortletActionConstants {
39
40 private PortletAwareInterceptor interceptor;
41 private TestAction action;
42 private PortletRequest portletRequest;
43 private PortletConfig portletConfig;
44 private Map<String, Object> contextMap;
45 private ActionInvocation invocation;
46
47 protected void setUp() throws Exception {
48 super.setUp();
49 interceptor = new PortletAwareInterceptor();
50 action = new TestAction();
51 portletRequest = EasyMock.createNiceMock(PortletRequest.class);
52 portletConfig = EasyMock.createNiceMock(PortletConfig.class);
53 contextMap = new HashMap<String, Object>();
54 invocation = EasyMock.createNiceMock(ActionInvocation.class);
55 EasyMock.expect(invocation.getAction()).andReturn(action);
56 EasyMock.expect(invocation.getInvocationContext()).andReturn(new ActionContext(contextMap));
57 }
58
59 protected void tearDown() throws Exception {
60 super.tearDown();
61 }
62
63 public void testPortletRequestIsSet() throws Exception {
64 contextMap.put(REQUEST, portletRequest);
65 EasyMock.replay(invocation);
66 interceptor.intercept(invocation);
67 assertEquals(portletRequest, action.getPortletRequest());
68 }
69
70 public void testPortletConfigIsSet() throws Exception {
71 contextMap.put(PORTLET_CONFIG, portletConfig);
72 EasyMock.replay(invocation);
73 interceptor.intercept(invocation);
74 assertEquals(portletConfig, action.getPortletConfig());
75 }
76
77 public static class TestAction implements PortletRequestAware, PortletConfigAware {
78
79 private PortletRequest request;
80 private PortletConfig config;
81
82 public void setPortletRequest(PortletRequest request) {
83 this.request = request;
84 }
85
86 public void setPortletConfig(PortletConfig portletConfig) {
87 this.config = portletConfig;
88 }
89
90 public PortletConfig getPortletConfig() {
91 return config;
92 }
93
94 public PortletRequest getPortletRequest() {
95 return request;
96 }
97
98 }
99 }