Search in sources :

Example 1 with MockFormBean

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

the class TestCopyFormToContext method testCopyToDefaultContextKey.

public void testCopyToDefaultContextKey() throws Exception {
    CopyFormToContext command = new CopyFormToContext();
    String formName = "foo";
    command.setFormName(formName);
    command.setScope("request");
    assertNull(context.getActionForm());
    assertNull(context.getRequestScope().get(POST_EXECUTION_CONTEXT_KEY));
    assertNull(context.getSessionScope().get(POST_EXECUTION_CONTEXT_KEY));
    command.execute(context);
    assertNotNull(context.getActionForm());
    assertNotNull(context.getRequestScope().get(formName));
    assertNull(context.getSessionScope().get(formName));
    assertSame(context.getActionForm(), context.getRequestScope().get(formName));
    ActionForm theForm = (ActionForm) context.getActionForm();
    assertTrue(theForm instanceof MockFormBean);
}
Also used : ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm) MockFormBean(org.apache.struts.mock.MockFormBean)

Example 2 with MockFormBean

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

the class TestTagUtils method test_Object_lookup_PageContext_String__String3.

// lookup with invalid scope
// -- (where an exception is thrown)
public void test_Object_lookup_PageContext_String__String3() {
    pageContext.setAttribute("bean", new MockFormBean());
    Object val = null;
    try {
        val = tagutils.lookup(pageContext, "bean", "invalid");
        fail("invalid scope :");
    } catch (JspException e) {
        assertNull((val));
    }
}
Also used : JspException(javax.servlet.jsp.JspException) MockFormBean(org.apache.struts.mock.MockFormBean)

Example 3 with MockFormBean

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

the class TestTagUtils method testComputeParametersParamValueToString.

public void testComputeParametersParamValueToString() {
    request.getSession().setAttribute("SomeBean", new MockFormBean(false, false, new Double(1)));
    Map map = null;
    try {
        map = tagutils.computeParameters(pageContext, "paramId", "SomeBean", "doubleValue", null, null, null, null, false);
        assertNotNull("map is null", map);
        String val = (String) map.get("paramId");
        assertTrue("paramId should be 1.0", "1.0".equals(val));
    } catch (JspException e) {
        fail("JspException not thrown");
    }
}
Also used : JspException(javax.servlet.jsp.JspException) MockFormBean(org.apache.struts.mock.MockFormBean) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with MockFormBean

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

the class TestTagUtils method testComputeParametersParamIdParamPropThrowException.

public void testComputeParametersParamIdParamPropThrowException() {
    request.getSession().setAttribute("SomeBean", new MockFormBean(true));
    Map map = null;
    try {
        map = tagutils.computeParameters(pageContext, "paramId", "SomeBean", "justThrowAnException", null, null, null, null, false);
        fail("JspException not thrown");
    } catch (JspException e) {
        assertNull("map is null", map);
    }
}
Also used : JspException(javax.servlet.jsp.JspException) MockFormBean(org.apache.struts.mock.MockFormBean) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with MockFormBean

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

the class TestTagUtils method testComputeParameters1c.

// Single parameter -- scope + name + property
public void testComputeParameters1c() {
    request.setAttribute("attr", new MockFormBean("bar"));
    Map map = null;
    try {
        map = tagutils.computeParameters(pageContext, "foo", "attr", "stringProperty", "request", null, null, null, false);
    } catch (JspException e) {
        fail("JspException: " + e);
    }
    assertNotNull("Map is not null", map);
    assertEquals("One parameter in the returned map", 1, map.size());
    assertTrue("Parameter present", map.containsKey("foo"));
    assertEquals("Parameter value", "bar", (String) map.get("foo"));
}
Also used : JspException(javax.servlet.jsp.JspException) MockFormBean(org.apache.struts.mock.MockFormBean) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MockFormBean (org.apache.struts.mock.MockFormBean)21 JspException (javax.servlet.jsp.JspException)15 HashMap (java.util.HashMap)8 Map (java.util.Map)8 ActionForm (org.apache.struts.action.ActionForm)5 DynaActionForm (org.apache.struts.action.DynaActionForm)5 ActionMapping (org.apache.struts.action.ActionMapping)3 ActionMessages (org.apache.struts.action.ActionMessages)2 ServletException (javax.servlet.ServletException)1 MockMultipartRequestHandler (org.apache.struts.mock.MockMultipartRequestHandler)1