Search in sources :

Example 56 with JspException

use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.

the class TestTagUtils method testGetActionErrors1b.

// String
public void testGetActionErrors1b() {
    request.setAttribute("foo", "bar");
    try {
        ActionMessages errors = tagutils.getActionMessages(pageContext, "foo");
        assertNotNull("errors should not be null", errors);
        assertNotNull("errors prop should not be null", errors.get("prop"));
        String key = null;
        int i = 0;
        for (Iterator iter = errors.get(ActionMessages.GLOBAL_MESSAGE); iter.hasNext(); ) {
            ActionMessage error = (ActionMessage) iter.next();
            key = error.getKey();
            Object[] values = error.getValues();
            assertNull(values);
            i++;
        }
        assertEquals("only 1 error", i, 1);
        assertEquals("key should match", key, "bar");
    } catch (JspException e) {
        fail(e.getMessage());
    }
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) Iterator(java.util.Iterator) ActionMessage(org.apache.struts.action.ActionMessage)

Example 57 with JspException

use of javax.servlet.jsp.JspException 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 58 with JspException

use of javax.servlet.jsp.JspException 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 59 with JspException

use of javax.servlet.jsp.JspException 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 60 with JspException

use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.

the class TestTagUtils method testComputeParameters1a.

// Single parameter -- name
public void testComputeParameters1a() {
    request.getSession().setAttribute("attr", "bar");
    Map map = null;
    try {
        map = tagutils.computeParameters(pageContext, "foo", "attr", null, null, 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) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JspException (javax.servlet.jsp.JspException)158 IOException (java.io.IOException)34 Map (java.util.Map)30 HashMap (java.util.HashMap)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)21 JspWriter (javax.servlet.jsp.JspWriter)21 Iterator (java.util.Iterator)20 ActionMessages (org.apache.struts.action.ActionMessages)15 MockFormBean (org.apache.struts.mock.MockFormBean)15 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 ActionMessage (org.apache.struts.action.ActionMessage)11 ArrayList (java.util.ArrayList)7 Collection (java.util.Collection)7 List (java.util.List)7 Locale (java.util.Locale)6 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)6 MalformedURLException (java.net.MalformedURLException)5 ModuleConfig (org.apache.struts.config.ModuleConfig)5 UserContext (org.mifos.security.util.UserContext)5 SimpleDateFormat (java.text.SimpleDateFormat)4