Search in sources :

Example 1 with MockActionServlet

use of org.apache.struts.mock.MockActionServlet in project sonarqube by SonarSource.

the class TestAuthorizeAction 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 AuthorizeAction();
}
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 2 with MockActionServlet

use of org.apache.struts.mock.MockActionServlet 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 3 with MockActionServlet

use of org.apache.struts.mock.MockActionServlet 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)3 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 MockPrincipal (org.apache.struts.mock.MockPrincipal)2