FileDocCategorySizeDatePackage
ServletActionContextTest.javaAPI DocExample2755Mon Jul 23 13:26:26 BST 2007org.apache.struts2

ServletActionContextTest

public class ServletActionContextTest extends TestCase implements StrutsStatics
Unit test for ServletActionContext. Based loosly on Jason's ActionContextTest. My first attempt at unit testing. Please hack away as needed.

Fields Summary
com.opensymphony.xwork2.ActionContext
actionContext
ServletActionContext
servletActionContext
private HttpServletRequest
request
private HttpServletResponse
response
private com.mockobjects.servlet.MockServletContext
servletContext
Constructors Summary
Methods Summary
public voidsetUp()

        Map extraContext = new HashMap();

        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        servletContext = new MockServletContext();

        extraContext.put(HTTP_REQUEST, request);
        extraContext.put(HTTP_RESPONSE, response);
        extraContext.put(SERVLET_CONTEXT, servletContext);

        actionContext = new ActionContext(extraContext);
        ServletActionContext.setContext(actionContext);
    
public voidtestContextParams()

        assertEquals(ServletActionContext.getRequest(), request);
        assertEquals(ServletActionContext.getResponse(), response);
        assertEquals(ServletActionContext.getServletContext(), servletContext);
    
public voidtestGetContext()

        ActionContext threadContext = ServletActionContext.getContext();
        assertEquals(actionContext, threadContext);