01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork;
06:
07: import com.mockobjects.servlet.MockHttpServletRequest;
08: import com.mockobjects.servlet.MockHttpServletResponse;
09: import com.mockobjects.servlet.MockServletContext;
10: import com.opensymphony.xwork.ActionContext;
11: import junit.framework.TestCase;
12:
13: import javax.servlet.http.HttpServletRequest;
14: import javax.servlet.http.HttpServletResponse;
15: import java.util.HashMap;
16: import java.util.Map;
17:
18: /**
19: * Unit test for ServletActionContext. Based loosly on Jason's ActionContextTest.
20: * My first attempt at unit testing. Please hack away as needed.
21: *
22: * @author <a href="mailto:nightfal@etherlands.net">Erik Beeson</a>
23: */
24: public class ServletActionContextTest extends TestCase implements
25: WebWorkStatics {
26:
27: ActionContext actionContext;
28: ServletActionContext servletActionContext;
29: private HttpServletRequest request;
30: private HttpServletResponse response;
31: private MockServletContext servletContext;
32:
33: public void setUp() {
34: Map extraContext = new HashMap();
35:
36: request = new MockHttpServletRequest();
37: response = new MockHttpServletResponse();
38: servletContext = new MockServletContext();
39:
40: extraContext.put(HTTP_REQUEST, request);
41: extraContext.put(HTTP_RESPONSE, response);
42: extraContext.put(SERVLET_CONTEXT, servletContext);
43:
44: actionContext = new ActionContext(extraContext);
45: ServletActionContext.setContext(actionContext);
46: }
47:
48: public void testContextParams() {
49: assertEquals(ServletActionContext.getRequest(), request);
50: assertEquals(ServletActionContext.getResponse(), response);
51: assertEquals(ServletActionContext.getServletContext(),
52: servletContext);
53: }
54:
55: public void testGetContext() {
56: ActionContext threadContext = ServletActionContext.getContext();
57: assertEquals(actionContext, threadContext);
58: }
59: }
|