Search in sources :

Example 6 with MockFormBean

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

the class TestTagUtils method testComputeParameters2c.

// Provided map -- scope + name + property
public void testComputeParameters2c() {
    request.setAttribute("attr", new MockFormBean());
    Map map = null;
    try {
        map = tagutils.computeParameters(pageContext, null, null, null, null, "attr", "mapProperty", "request", false);
    } catch (JspException e) {
        fail("JspException: " + e);
    }
    assertNotNull("Map is not null", map);
    assertEquals("Two parameter in the returned map", 2, map.size());
    assertTrue("Parameter foo1 present", map.containsKey("foo1"));
    assertEquals("Parameter foo1 value", "bar1", (String) map.get("foo1"));
    assertTrue("Parameter foo2 present", map.containsKey("foo2"));
    assertEquals("Parameter foo2 value", "bar2", (String) map.get("foo2"));
}
Also used : JspException(javax.servlet.jsp.JspException) MockFormBean(org.apache.struts.mock.MockFormBean) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with MockFormBean

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

the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String5.

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

Example 8 with MockFormBean

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

the class TestTagUtils method testComputeParameters3aa.

// Kitchen sink combination of parameters with a merge
// with array values in map
public void testComputeParameters3aa() {
    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", "mapPropertyArrayValues", "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", 3, values.length);
    assertTrue("Parameter foo2 present", map.containsKey("foo2"));
    String[] arrayValues = (String[]) map.get("foo2");
    String val = arrayValues[0];
    assertEquals("Parameter foo2 value", "bar2", val);
    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 9 with MockFormBean

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

the class TestTagUtils method test_Object_lookup_PageContext_String_String_String3.

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

Example 10 with MockFormBean

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

the class TestTagUtils method test_Object_lookup_PageContext_String__String2.

// lookup with page scope
public void test_Object_lookup_PageContext_String__String2() {
    pageContext.setAttribute("bean", new MockFormBean());
    try {
        Object val = tagutils.lookup(pageContext, "bean", "page");
        assertNotNull((val));
    } catch (JspException e) {
        fail("bean not found:" + e.getMessage());
    }
}
Also used : JspException(javax.servlet.jsp.JspException) MockFormBean(org.apache.struts.mock.MockFormBean)

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