Author: craigmcc Date: Tue Sep 20 21:53:58 2005 New Revision: 290619 URL: http://svn.apache.org/viewcvs?rev=290619&view=rev Log: Update tests for AbstractFacesBean to include checking that messages get queued correctly.
Modified: struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBeanTestCase.java Modified: struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBeanTestCase.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBeanTestCase.java?rev=290619&r1=290618&r2=290619&view=diff ============================================================================== --- struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBeanTestCase.java (original) +++ struts/shale/trunk/core-library/src/test/org/apache/shale/view/ConcreteFacesBeanTestCase.java Tue Sep 20 21:53:58 2005 @@ -16,7 +16,11 @@ package org.apache.shale.view; +import java.util.Iterator; import java.util.Map; +import javax.faces.application.FacesMessage; +import javax.faces.application.FacesMessage.Severity; +import javax.faces.component.UIViewRoot; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.shale.test.base.AbstractJsfTestCase; @@ -114,6 +118,91 @@ } + private Severity messagesAttachedSeverity[] = { + FacesMessage.SEVERITY_ERROR, + FacesMessage.SEVERITY_ERROR, + FacesMessage.SEVERITY_ERROR, + FacesMessage.SEVERITY_ERROR, + FacesMessage.SEVERITY_FATAL, + FacesMessage.SEVERITY_FATAL, + FacesMessage.SEVERITY_FATAL, + FacesMessage.SEVERITY_INFO, + FacesMessage.SEVERITY_INFO, + FacesMessage.SEVERITY_WARN, + }; + + private String messagesAttachedSummary[] = { + "Error 0", "Error 1", "Error 2", "Error 3", + "Fatal 0", "Fatal 1", "Fatal 2", + "Info 0", "Info 1", + "Warn 0", + }; + + + // Test messages attached to a particular component + public void testMessagesAttached() { + + UIViewRoot root = new UIViewRoot(); + root.setId("root"); + facesContext.setViewRoot(root); + bean.error(root, "Error 0"); + bean.error(root, "Error 1"); + bean.error(root, "Error 2"); + bean.error(root, "Error 3"); + bean.fatal(root, "Fatal 0"); + bean.fatal(root, "Fatal 1"); + bean.fatal(root, "Fatal 2"); + bean.info(root, "Info 0"); + bean.info(root, "Info 1"); + bean.warn(root, "Warn 0"); + checkMessages(facesContext.getMessages(root.getClientId(facesContext)), + messagesAttachedSeverity, + messagesAttachedSummary); + + } + + + private Severity messagesUnattachedSeverity[] = { + FacesMessage.SEVERITY_ERROR, + FacesMessage.SEVERITY_FATAL, + FacesMessage.SEVERITY_FATAL, + FacesMessage.SEVERITY_INFO, + FacesMessage.SEVERITY_INFO, + FacesMessage.SEVERITY_INFO, + FacesMessage.SEVERITY_WARN, + FacesMessage.SEVERITY_WARN, + FacesMessage.SEVERITY_WARN, + FacesMessage.SEVERITY_WARN, + }; + + private String messagesUnattachedSummary[] = { + "Error 0", + "Fatal 0", "Fatal 1", + "Info 0", "Info 1", "Info 2", + "Warn 0", "Warn 1", "Warn 2", "Warn 3", + }; + + + // Test messages not attached to any particular component + public void testMessagesUnattached() { + + bean.error("Error 0"); + bean.fatal("Fatal 0"); + bean.fatal("Fatal 1"); + bean.info("Info 0"); + bean.info("Info 1"); + bean.info("Info 2"); + bean.warn("Warn 0"); + bean.warn("Warn 1"); + bean.warn("Warn 2"); + bean.warn("Warn 3"); + checkMessages(facesContext.getMessages(null), + messagesUnattachedSeverity, + messagesUnattachedSummary); + + } + + // Test pristine instance public void testPristine() { @@ -178,6 +267,21 @@ assertEquals("baz", bean.getValue("#{foo.id}")); assertEquals("baz", ((ConcreteFacesBean) servletContext.getAttribute("foo")).getId()); + } + + + // --------------------------------------------------------- Support Methods + + + // Check the queued messages for correct severity and summary messages + private void checkMessages(Iterator messages, Severity severity[], String summary[]) { + int n = 0; + while (messages.hasNext()) { + FacesMessage message = (FacesMessage) messages.next(); + assertEquals(summary[n] + " severity", severity[n], message.getSeverity()); + assertEquals(summary[n] + " summary", summary[n], message.getSummary()); + n++; + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]