Search in sources :

Example 46 with ActionMessages

use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.

the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String2.

// -- using ActionErrors
public void testActionMessages_getActionMessages_PageContext_String2() {
    ActionMessages actionMessages = new ActionMessages();
    actionMessages.add("prop", new ActionMessage("key.key"));
    request.setAttribute("messages", actionMessages);
    try {
        ActionMessages messages = tagutils.getActionMessages(pageContext, "messages");
        assertNotNull("messages should not be null", messages);
        assertNotNull("messages prop should not be null", messages.get("prop"));
        String val = null;
        int i = 0;
        for (Iterator iter = messages.get("prop"); iter.hasNext(); ) {
            ActionMessage message = (ActionMessage) iter.next();
            val = message.getKey();
            i++;
        }
        assertEquals("only 1 message", i, 1);
        assertEquals("messages 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 47 with ActionMessages

use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.

the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String6.

// ActionMessages (thrown Exception)
// TODO -- currently this does not hit the line for caught Exception
public void testActionMessages_getActionMessages_PageContext_String6() {
    ActionMessages actionMessages = new ActionMessages();
    actionMessages.add("prop", new ActionMessage("key.key"));
    request.setAttribute("messages", actionMessages);
    try {
        ActionMessages messages = tagutils.getActionMessages(pageContext, "does-not-exist");
        assertNotNull("messages should not be null", messages);
        assertNotNull("messages prop should not be null", messages.get("prop"));
        for (Iterator iter = messages.get("prop"); iter.hasNext(); ) {
            fail("Should not have any messages for does-not-exist");
        }
    } 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)

Aggregations

ActionMessages (org.apache.struts.action.ActionMessages)47 ActionMessage (org.apache.struts.action.ActionMessage)31 JspException (javax.servlet.jsp.JspException)15 ActionForward (org.apache.struts.action.ActionForward)14 Iterator (java.util.Iterator)11 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)10 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)6 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)6 ContestPersistence (cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence)4 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)4 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)4 Date (java.util.Date)4 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)3 UserPreference (cn.edu.zju.acm.onlinejudge.bean.UserPreference)3 ProblemPersistence (cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)3 Contest (cn.edu.zju.acm.onlinejudge.bean.Contest)2 Course (cn.edu.zju.acm.onlinejudge.bean.Course)2 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)2 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 LogCriteria (cn.edu.zju.acm.onlinejudge.bean.request.LogCriteria)2