Search in sources :

Example 46 with JspException

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

the class TestTagUtils method testComputeParameters1b.

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

Example 47 with JspException

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

the class TestTagUtils method testGetActionErrors1a.

// ------------------------------------------ getActionErrors()
// ActionErrors
public void testGetActionErrors1a() {
    ActionMessages actionErrors = new ActionMessages();
    actionErrors.add("prop", new ActionMessage("key.key"));
    request.setAttribute("errors", actionErrors);
    try {
        ActionMessages errors = tagutils.getActionMessages(pageContext, "errors");
        assertNotNull("errors should not be null", errors);
        assertNotNull("errors prop should not be null", errors.get("prop"));
        String val = null;
        int i = 0;
        for (Iterator iter = errors.get("prop"); iter.hasNext(); ) {
            ActionMessage error = (ActionMessage) iter.next();
            val = error.getKey();
            i++;
        }
        assertEquals("only 1 error", i, 1);
        assertEquals("errors prop should match", val, "key.key");
    } catch (JspException e) {
        fail(e.getMessage());
    }
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Iterator(java.util.Iterator)

Example 48 with JspException

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

the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String4.

// -- using String Array
public void testActionMessages_getActionMessages_PageContext_String4() {
    String[] vals = new String[] { "bar", "baz" };
    request.setAttribute("foo", vals);
    try {
        ActionMessages messages = tagutils.getActionMessages(pageContext, "foo");
        assertNotNull("messages should not be null", messages);
        assertNotNull("messages prop should not be null", messages.get("prop"));
        String key = null;
        int i = 0;
        for (Iterator iter = messages.get(ActionMessages.GLOBAL_MESSAGE); iter.hasNext(); ) {
            ActionMessage message = (ActionMessage) iter.next();
            key = message.getKey();
            Object[] values = message.getValues();
            assertNull((values));
            assertEquals("1st key should match", key, vals[i]);
            i++;
        }
        assertEquals("only 1 message", i, 2);
    } 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 49 with JspException

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

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

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