01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.dispatcher;
06:
07: import java.util.LinkedHashMap;
08: import java.util.Map;
09:
10: import org.easymock.MockControl;
11: import org.springframework.mock.web.MockHttpServletRequest;
12: import org.springframework.mock.web.MockHttpServletResponse;
13:
14: import com.opensymphony.webwork.ServletActionContext;
15: import com.opensymphony.webwork.interceptor.FlashInterceptor;
16: import com.opensymphony.xwork.ActionContext;
17: import com.opensymphony.xwork.ActionInvocation;
18: import com.opensymphony.xwork.ActionSupport;
19:
20: import junit.framework.TestCase;
21:
22: /**
23: * @author tmjee
24: * @version $Date: 2006-12-11 13:44:39 +0100 (Mon, 11 Dec 2006) $ $Id: FlashResultTest.java 2756 2006-12-11 12:44:39Z tmjee $
25: */
26: public class FlashResultTest extends TestCase {
27:
28: public void testResult() throws Exception {
29:
30: InternalAction action = new InternalAction();
31:
32: Map sessionMap = new LinkedHashMap();
33: MockHttpServletRequest request = new MockHttpServletRequest();
34: MockHttpServletResponse response = new MockHttpServletResponse();
35:
36: ActionContext actionContext = ActionContext.getContext();
37: actionContext.getContextMap().put(
38: ServletActionContext.HTTP_REQUEST, request);
39: actionContext.getContextMap().put(
40: ServletActionContext.HTTP_RESPONSE, response);
41: actionContext.getContextMap().put(ActionContext.SESSION,
42: sessionMap);
43:
44: MockControl control = MockControl
45: .createControl(ActionInvocation.class);
46: ActionInvocation invocation = (ActionInvocation) control
47: .getMock();
48: invocation.getInvocationContext();
49: control.expectAndDefaultReturn(null, actionContext);
50: invocation.getAction();
51: control.expectAndDefaultReturn(null, action);
52:
53: control.replay();
54:
55: FlashResult result = new FlashResult();
56: result.doExecute("http://www.google.com", invocation);
57:
58: assertEquals(sessionMap.size(), 1);
59: assertTrue(sessionMap.containsKey(FlashInterceptor.DEFAULT_KEY));
60: assertEquals(sessionMap.get(FlashInterceptor.DEFAULT_KEY),
61: action);
62:
63: control.verify();
64: }
65:
66: class InternalAction extends ActionSupport {
67: private static final long serialVersionUID = 2836339824246564870L;
68: }
69: }
|