01: package com.mockrunner.example.struts;
02:
03: import javax.servlet.http.HttpServletRequest;
04: import javax.servlet.http.HttpServletRequestWrapper;
05:
06: import com.mockrunner.example.servlet.ImageButtonFilter;
07: import com.mockrunner.servlet.ServletTestModule;
08: import com.mockrunner.struts.ActionTestCaseAdapter;
09:
10: /**
11: * Example test for {@link LogoutAction}. Demonstrates the testing of
12: * actions with specified filters. Also demonstrates how to prepare
13: * custom action mappings in tests. Please note that the use of
14: * custom action mappings relies on CGLib.
15: */
16: public class LogoutActionTest extends ActionTestCaseAdapter {
17: private ServletTestModule servletModule;
18: private LogoutActionMapping logoutMapping;
19:
20: protected void setUp() throws Exception {
21: super .setUp();
22: servletModule = createServletTestModule();
23: logoutMapping = (LogoutActionMapping) getActionMockObjectFactory()
24: .prepareActionMapping(LogoutActionMapping.class);
25: }
26:
27: public void testLogout() throws Exception {
28: logoutMapping.setRequestParameterName("logout");
29: addRequestParameter("logout.x", "11");
30: addRequestParameter("logout.y", "11");
31: servletModule.createFilter(ImageButtonFilter.class);
32: servletModule.setDoChain(true);
33: servletModule.doFilter();
34: getActionMockObjectFactory().addRequestWrapper(
35: new HttpServletRequestWrapper(
36: (HttpServletRequest) servletModule
37: .getFilteredRequest()));
38: actionPerform(LogoutAction.class);
39: assertFalse(getActionMockObjectFactory().getMockSession()
40: .isValid());
41: }
42: }
|