1 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 ; 14 import javax.servlet.http.HttpServletResponse ; 15 import java.util.HashMap ; 16 import java.util.Map ; 17 18 19 25 public class ServletActionContextTest extends TestCase implements WebWorkStatics { 26 28 ActionContext actionContext; 29 ServletActionContext servletActionContext; 30 private HttpServletRequest request; 31 private HttpServletResponse response; 32 private MockServletContext servletContext; 33 34 36 public void setUp() { 37 Map extraContext = new HashMap (); 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 |