KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > ServletActionContextTest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork;
6
7 import com.mockobjects.servlet.MockHttpServletRequest;
8 import com.mockobjects.servlet.MockHttpServletResponse;
9 import com.mockobjects.servlet.MockServletContext;
10 import com.opensymphony.xwork.ActionContext;
11 import junit.framework.TestCase;
12
13 import javax.servlet.http.HttpServletRequest JavaDoc;
14 import javax.servlet.http.HttpServletResponse JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Map JavaDoc;
17
18
19 /**
20  * Unit test for ServletActionContext. Based loosly on Jason's ActionContextTest.
21  * My first attempt at unit testing. Please hack away as needed.
22  *
23  * @author <a HREF="mailto:nightfal@etherlands.net">Erik Beeson</a>
24  */

25 public class ServletActionContextTest extends TestCase implements WebWorkStatics {
26     //~ Instance fields ////////////////////////////////////////////////////////
27

28     ActionContext actionContext;
29     ServletActionContext servletActionContext;
30     private HttpServletRequest request;
31     private HttpServletResponse response;
32     private MockServletContext servletContext;
33
34     //~ Methods ////////////////////////////////////////////////////////////////
35

36     public void setUp() {
37         Map JavaDoc extraContext = new HashMap JavaDoc();
38
39         request = new MockHttpServletRequest();
40         response = new MockHttpServletResponse();
41         servletContext = new MockServletContext();
42
43         extraContext.put(HTTP_REQUEST, request);
44         extraContext.put(HTTP_RESPONSE, response);
45         extraContext.put(SERVLET_CONTEXT, servletContext);
46
47         actionContext = new ActionContext(extraContext);
48         ServletActionContext.setContext(actionContext);
49     }
50
51     public void testContextParams() {
52         assertEquals(ServletActionContext.getRequest(), request);
53         assertEquals(ServletActionContext.getResponse(), response);
54         assertEquals(ServletActionContext.getServletContext(), servletContext);
55     }
56
57     public void testGetContext() {
58         ActionContext threadContext = ServletActionContext.getContext();
59         assertEquals(actionContext, threadContext);
60     }
61 }
62
Popular Tags