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"));
}
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"));
}
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();
}
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();
}
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));
}
Aggregations