Search in sources :

Example 21 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class TestPerformForward method setUp.

/* setUp method for test case */
protected void setUp() throws Exception {
    this.request = new MockHttpServletRequest();
    this.principal = new MockPrincipal("Mr. Macri", new String[] { "administrator" });
    this.request.setUserPrincipal(principal);
    MockServletConfig servletConfig = new MockServletConfig();
    MockServletContext servletContext = new MockServletContext();
    MockActionServlet servlet = new MockActionServlet(servletContext, servletConfig);
    servlet.initInternal();
    this.saContext = new ServletActionContext(servletContext, request, new MockHttpServletResponse());
    this.saContext.setActionServlet(servlet);
    this.command = new PerformForward();
}
Also used : MockActionServlet(org.apache.struts.mock.MockActionServlet) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) MockPrincipal(org.apache.struts.mock.MockPrincipal) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) MockServletConfig(org.apache.struts.mock.MockServletConfig) MockServletContext(org.apache.struts.mock.MockServletContext) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse)

Example 22 with ServletActionContext

use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.

the class TestSetOriginalURI method testSetOriginalURI.

public void testSetOriginalURI() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("foo/", "bar.do", null, null);
    MockServletConfig servletConfig = new MockServletConfig();
    MockServletContext servletContext = new MockServletContext();
    MockActionServlet servlet = new MockActionServlet(servletContext, servletConfig);
    servlet.initInternal();
    ServletActionContext saContext = new ServletActionContext(servletContext, request, new MockHttpServletResponse());
    saContext.setActionServlet(servlet);
    boolean result = command.execute(saContext);
    assertTrue(!result);
    String uri = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
    assertTrue("Original uri not correct: " + uri, "bar.do".equals(uri));
    request.setPathElements("foo/", "bar2.do", null, null);
    uri = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
    assertTrue("Original uri not correct: " + uri, "bar.do".equals(uri));
}
Also used : MockActionServlet(org.apache.struts.mock.MockActionServlet) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) MockServletConfig(org.apache.struts.mock.MockServletConfig) MockServletContext(org.apache.struts.mock.MockServletContext) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse)

Aggregations

ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ActionServlet (org.apache.struts.action.ActionServlet)4 MockActionServlet (org.apache.struts.mock.MockActionServlet)3 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)3 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)3 MockServletConfig (org.apache.struts.mock.MockServletConfig)3 MockServletContext (org.apache.struts.mock.MockServletContext)3 Map (java.util.Map)2 ActionForm (org.apache.struts.action.ActionForm)2 ActionMapping (org.apache.struts.action.ActionMapping)2 ModuleConfig (org.apache.struts.config.ModuleConfig)2 MockPrincipal (org.apache.struts.mock.MockPrincipal)2 MessageResources (org.apache.struts.util.MessageResources)2 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletContext (javax.servlet.ServletContext)1 HttpSession (javax.servlet.http.HttpSession)1