Search in sources :

Example 1 with MockHttpServletRequest

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

the class DynaActionFormConfig method testResetGet.

/**
     * Test the reset method when the request method is GET.
     */
public void testResetGet() {
    // set a choice set of props with non-initial values
    dynaForm.set("booleanProperty", Boolean.FALSE);
    dynaForm.set("booleanSecond", Boolean.FALSE);
    dynaForm.set("doubleProperty", new Double(456.0));
    dynaForm.set("floatProperty", new Float((float) 456.0));
    dynaForm.set("intProperty", new Integer(456));
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    dynaForm.reset(mapping, request);
    assertEquals("booleanProperty should be reset", Boolean.TRUE, (Boolean) dynaForm.get("booleanProperty"));
    assertEquals("booleanSecond should be reset", Boolean.TRUE, (Boolean) dynaForm.get("booleanSecond"));
    assertEquals("doubleProperty should be reset", new Double(321.0), (Double) dynaForm.get("doubleProperty"));
    assertEquals("floatProperty should NOT be reset", new Float((float) 456.0), (Float) dynaForm.get("floatProperty"));
    assertEquals("intProperty should NOT be reset", new Integer(456), (Integer) dynaForm.get("intProperty"));
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest)

Example 2 with MockHttpServletRequest

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

the class DynaActionFormConfig method testResetPost.

/**
     * Test the reset method when the request method is GET.
     */
public void testResetPost() {
    // set a choice set of props with non-initial values
    dynaForm.set("booleanProperty", Boolean.FALSE);
    dynaForm.set("booleanSecond", Boolean.FALSE);
    dynaForm.set("doubleProperty", new Double(456.0));
    dynaForm.set("floatProperty", new Float((float) 456.0));
    dynaForm.set("intProperty", new Integer(456));
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("POST");
    dynaForm.reset(mapping, request);
    assertEquals("booleanProperty should be reset", Boolean.TRUE, (Boolean) dynaForm.get("booleanProperty"));
    assertEquals("booleanSecond should be reset", Boolean.TRUE, (Boolean) dynaForm.get("booleanSecond"));
    assertEquals("doubleProperty should NOT be reset", new Double(456), (Double) dynaForm.get("doubleProperty"));
    assertEquals("floatProperty should be reset", new Float((float) 123.0), (Float) dynaForm.get("floatProperty"));
    assertEquals("intProperty should NOT be reset", new Integer(456), (Integer) dynaForm.get("intProperty"));
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest)

Example 3 with MockHttpServletRequest

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

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

use of org.apache.struts.mock.MockHttpServletRequest 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

MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)8 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)6 MockServletConfig (org.apache.struts.mock.MockServletConfig)6 MockServletContext (org.apache.struts.mock.MockServletContext)5 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)3 MockActionServlet (org.apache.struts.mock.MockActionServlet)3 MockPageContext (org.apache.struts.mock.MockPageContext)3 ModuleConfigImpl (org.apache.struts.config.impl.ModuleConfigImpl)2 MockPrincipal (org.apache.struts.mock.MockPrincipal)2 ForwardConfig (org.apache.struts.config.ForwardConfig)1 ModuleConfig (org.apache.struts.config.ModuleConfig)1 MockHttpSession (org.apache.struts.mock.MockHttpSession)1