Search in sources :

Example 16 with MockFormBean

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

the class TestRequestUtils method testCreateActionForm2a.

// Default module -- Standard ActionForm should be created
public void testCreateActionForm2a() {
    request.setPathElements("/myapp", "/static.do", null, null);
    ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig("/static");
    assertNotNull("Found /static mapping", mapping);
    assertNotNull("Mapping has non-null name", mapping.getName());
    assertEquals("Mapping has correct name", "static", mapping.getName());
    assertNotNull("AppConfig has form bean " + mapping.getName(), moduleConfig.findFormBeanConfig(mapping.getName()));
    ActionForm form = RequestUtils.createActionForm(request, mapping, moduleConfig, null);
    assertNotNull("ActionForm returned", form);
    assertTrue("ActionForm of correct type", form instanceof MockFormBean);
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm) MockFormBean(org.apache.struts.mock.MockFormBean)

Example 17 with MockFormBean

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

the class TestTagUtils method test_Object_lookup_PageContext_String_String_String2.

// try to get the call to throw an IllegalArgumentException
public void test_Object_lookup_PageContext_String_String_String2() {
    pageContext.setAttribute("bean", new MockFormBean());
    Object val = null;
    try {
        val = tagutils.lookup(pageContext, "bean", "doesNotExistMethod", "page");
        fail("should have thrown exception");
    } catch (JspException e) {
        assertNull(val);
    }
}
Also used : JspException(javax.servlet.jsp.JspException) MockFormBean(org.apache.struts.mock.MockFormBean)

Example 18 with MockFormBean

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

the class TestTagUtils method testGetActionErrors1d.

// String Array (thrown JspException)
public void testGetActionErrors1d() {
    request.setAttribute("foo", new MockFormBean());
    ActionMessages errors = null;
    try {
        errors = tagutils.getActionMessages(pageContext, "foo");
        fail("should have thrown JspException");
    } catch (JspException e) {
        assertNull("errors should be null", errors);
    }
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) MockFormBean(org.apache.struts.mock.MockFormBean)

Example 19 with MockFormBean

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

the class TestTagUtils method testComputeParameters3a.

// Kitchen sink combination of parameters with a merge
public void testComputeParameters3a() {
    request.setAttribute("attr", new MockFormBean("bar3"));
    request.getSession().setAttribute(Globals.TRANSACTION_TOKEN_KEY, "token");
    Map map = null;
    try {
        map = tagutils.computeParameters(pageContext, "foo1", "attr", "stringProperty", "request", "attr", "mapProperty", "request", true);
    } catch (JspException e) {
        fail("JspException: " + e);
    }
    assertNotNull("Map is not null", map);
    assertEquals("Three parameter in the returned map", 3, map.size());
    assertTrue("Parameter foo1 present", map.containsKey("foo1"));
    assertTrue("Parameter foo1 value type", map.get("foo1") instanceof String[]);
    String[] values = (String[]) map.get("foo1");
    assertEquals("Values count", 2, values.length);
    assertTrue("Parameter foo2 present", map.containsKey("foo2"));
    assertEquals("Parameter foo2 value", "bar2", (String) map.get("foo2"));
    assertTrue("Transaction token parameter present", map.containsKey(Constants.TOKEN_KEY));
    assertEquals("Transaction token parameter value", "token", (String) map.get(Constants.TOKEN_KEY));
}
Also used : JspException(javax.servlet.jsp.JspException) MockFormBean(org.apache.struts.mock.MockFormBean) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with MockFormBean

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

the class TestTagUtils method testComputeParameters3b.

// Kitchen sink combination of parameters with a merge
public void testComputeParameters3b() {
    request.setAttribute("attr", new MockFormBean("bar3"));
    request.getSession().setAttribute(Globals.TRANSACTION_TOKEN_KEY, "token");
    Map map = null;
    try {
        map = tagutils.computeParameters(pageContext, "foo1", "attr", "stringProperty", "request", "attr", "mapProperty", "request", true);
    } catch (JspException e) {
        fail("JspException: " + e);
    }
    assertNotNull("Map is not null", map);
    assertEquals("Three parameter in the returned map", 3, map.size());
    assertTrue("Parameter foo1 present", map.containsKey("foo1"));
    assertTrue("Parameter foo1 value type", map.get("foo1") instanceof String[]);
    String[] values = (String[]) map.get("foo1");
    assertEquals("Values count", 2, values.length);
    assertTrue("Parameter foo2 present", map.containsKey("foo2"));
    assertEquals("Parameter foo2 value", "bar2", (String) map.get("foo2"));
    assertTrue("Transaction token parameter present", map.containsKey(Constants.TOKEN_KEY));
    assertEquals("Transaction token parameter value", "token", (String) map.get(Constants.TOKEN_KEY));
}
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