[seam-commits] Seam SVN: r10705 - in modules/trunk/faces/src: test and 15 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Apr 29 02:01:58 EDT 2009
Author: dan.j.allen
Date: 2009-04-29 02:01:57 -0400 (Wed, 29 Apr 2009)
New Revision: 10705
Added:
modules/trunk/faces/src/test/
modules/trunk/faces/src/test/java/
modules/trunk/faces/src/test/java/org/
modules/trunk/faces/src/test/java/org/jboss/
modules/trunk/faces/src/test/java/org/jboss/seam/
modules/trunk/faces/src/test/java/org/jboss/seam/faces/
modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesContextProducerTest.java
modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesExpressionsTest.java
modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesStatusMessagesTest.java
modules/trunk/faces/src/test/resources/
modules/trunk/faces/src/test/resources/org/
modules/trunk/faces/src/test/resources/org/jboss/
modules/trunk/faces/src/test/resources/org/jboss/seam/
modules/trunk/faces/src/test/resources/org/jboss/seam/faces/
modules/trunk/faces/src/test/resources/org/jboss/seam/faces/beans.xml
modules/trunk/faces/src/test/resources/org/jboss/testharness/
modules/trunk/faces/src/test/resources/org/jboss/testharness/impl/
modules/trunk/faces/src/test/resources/org/jboss/testharness/impl/packaging/
modules/trunk/faces/src/test/resources/org/jboss/testharness/impl/packaging/jsr299/
modules/trunk/faces/src/test/resources/org/jboss/testharness/impl/packaging/jsr299/default/
modules/trunk/faces/src/test/resources/org/jboss/testharness/impl/packaging/jsr299/default/beans.xml
modules/trunk/faces/src/test/resources/test-suite.xml
Log:
add a bunch of tests
Added: modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesContextProducerTest.java
===================================================================
--- modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesContextProducerTest.java (rev 0)
+++ modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesContextProducerTest.java 2009-04-29 06:01:57 UTC (rev 10705)
@@ -0,0 +1,50 @@
+package org.jboss.seam.faces;
+
+import javax.faces.context.FacesContext;
+import org.jboss.seam.mock.faces.MockFacesContext;
+import static org.testng.Assert.*;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.webbeans.test.AbstractWebBeansTest;
+import org.testng.annotations.Test;
+
+/**
+ * Verify that the FacesContextProducer produces the same FacesContext
+ * as returned by FacesContext#getCurrentInstance().
+ *
+ * @author Dan Allen
+ */
+ at Artifact(addCurrentPackage = false)
+ at Classes(FacesContextProducer.class)
+public class FacesContextProducerTest extends AbstractWebBeansTest
+{
+ @Override
+ public void beforeMethod()
+ {
+ super.beforeMethod();
+ installFacesContext();
+ }
+
+ @Test
+ public void testProduceCurrentFacesContext()
+ {
+ FacesContext actualFacesContext = FacesContext.getCurrentInstance();
+ FacesContextProducer standaloneProducer = new FacesContextProducer();
+ assertSame(standaloneProducer.getFacesContext(), actualFacesContext);
+ assertSame(getFacesContextInstance(), actualFacesContext);
+ }
+
+ private void installFacesContext()
+ {
+ new MockFacesContext().setCurrent();
+ }
+
+ /**
+ * Retrieve the FacesContextProducer instance
+ */
+ private FacesContext getFacesContextInstance()
+ {
+ return getCurrentManager().getInstanceByType(FacesContext.class);
+ }
+}
Added: modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesExpressionsTest.java
===================================================================
--- modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesExpressionsTest.java (rev 0)
+++ modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesExpressionsTest.java 2009-04-29 06:01:57 UTC (rev 10705)
@@ -0,0 +1,62 @@
+package org.jboss.seam.faces;
+
+import static org.testng.Assert.*;
+
+import javax.el.CompositeELResolver;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseId;
+import org.jboss.seam.el.Expressions;
+import org.jboss.seam.el.SeamEL;
+import org.jboss.seam.mock.faces.MockFacesContext;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
+import org.jboss.webbeans.test.AbstractWebBeansTest;
+import org.testng.annotations.Test;
+
+/**
+ * First and foremost, ensure that FacesExpressions is configured properly
+ * to specialize Expressions and will thus load successfully. Once loaded,
+ * verify that Expressions adds the appropriate JSF-specific functionality.
+ *
+ * @author Dan Allen
+ */
+ at Artifact(addCurrentPackage = false)
+ at BeansXml("beans.xml")
+ at Classes(
+{
+ FacesExpressions.class, Expressions.class
+})
+public class FacesExpressionsTest extends AbstractWebBeansTest
+{
+ @Override
+ public void beforeMethod()
+ {
+ super.beforeMethod();
+ installMockFacesContext();
+ }
+
+ @Test
+ public void testUsesELFromFacesContext()
+ {
+ Expressions expressions = getExpressionInstance();
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
+ assertSame(expressions.getELContext(), facesContext.getELContext());
+ }
+
+ private Expressions getExpressionInstance()
+ {
+ Expressions expressions = getCurrentManager().getInstanceByType(Expressions.class);
+ assert expressions instanceof FacesExpressions;
+ return expressions;
+ }
+
+ private void installMockFacesContext()
+ {
+ MockFacesContext facesContext = new MockFacesContext();
+ facesContext.setELContext(SeamEL.createELContext(new CompositeELResolver()));
+ facesContext.setCurrent();
+ }
+}
Added: modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesStatusMessagesTest.java
===================================================================
--- modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesStatusMessagesTest.java (rev 0)
+++ modules/trunk/faces/src/test/java/org/jboss/seam/faces/FacesStatusMessagesTest.java 2009-04-29 06:01:57 UTC (rev 10705)
@@ -0,0 +1,100 @@
+package org.jboss.seam.faces;
+
+import javax.faces.application.FacesMessage;
+import static org.testng.Assert.*;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseId;
+import org.jboss.seam.el.Expressions;
+import org.jboss.seam.international.Interpolator;
+import org.jboss.seam.international.LocaleProducer;
+import org.jboss.seam.international.StatusMessages;
+import org.jboss.seam.mock.faces.MockFacesContext;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
+import org.jboss.webbeans.context.ConversationContext;
+import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
+import org.jboss.webbeans.test.AbstractWebBeansTest;
+import org.testng.annotations.Test;
+
+/**
+ * First and foremost, ensure that FacesStatusMessage is configured properly
+ * to specialize StatusMessage and will thus load successfully. Once loaded,
+ * verify that FacesStatusMessage adds the appropriate JSF-specific functionality
+ * to the status message repository.
+ *
+ * @author Dan Allen
+ *
+ * @see FacesStatusMessages
+ * @see StatusMessages
+ */
+ at Artifact(addCurrentPackage = false)
+ at BeansXml("beans.xml")
+ at Classes(
+{
+ FacesStatusMessages.class, StatusMessages.class, Interpolator.class, Expressions.class, LocaleProducer.class
+})
+public class FacesStatusMessagesTest extends AbstractWebBeansTest
+{
+ @Override
+ public void beforeMethod()
+ {
+ super.beforeMethod();
+ activateConversationContext();
+ installMockFacesContext();
+ }
+
+ /**
+ * Test that the StatusMessage objects properly tranfer to FacesMessage objects
+ * upon the call to onBeforeRender().
+ */
+ @Test
+ public void testStatusMessagesTransferToFacesMessages()
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.setCurrentPhaseId(PhaseId.INVOKE_APPLICATION);
+ StatusMessages statusMessages = getStatusMessagesInstance();
+
+ statusMessages.add("You've booked a night at {0}. Bon chance!", "Mandalay Bay");
+
+ assertEquals(statusMessages.getGlobalMessages().size(), 1);
+ assertEquals(facesContext.getMessageList().size(), 0);
+
+ facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
+ statusMessages.onBeforeRender();
+
+ assertEquals(statusMessages.getGlobalMessages().size(), 0);
+ assertEquals(facesContext.getMessageList().size(), 1);
+ assertEquals(facesContext.getMessageList(null).size(), 1);
+ FacesMessage facesMessage = facesContext.getMessageList().get(0);
+ assertEquals(facesMessage.getSeverity(), FacesMessage.SEVERITY_INFO);
+ assertEquals(facesMessage.getSummary(), "You've booked a night at Mandalay Bay. Bon chance!");
+ // this assignment happens inside the FacesMessage implementation
+ assertEquals(facesMessage.getSummary(), facesMessage.getDetail());
+ }
+
+ // TODO test addToControl() because there is important logic in the getClientId() method
+ // TODO either test TransferStatusMessagesListener here or create a dedicated test for it
+
+ private void installMockFacesContext()
+ {
+ new MockFacesContext().setCurrent();
+ }
+
+ private void activateConversationContext()
+ {
+ ConversationContext.instance().setBeanStore(new ConcurrentHashMapBeanStore());
+ ConversationContext.instance().setActive(true);
+ }
+
+ /**
+ * Retrieve the StatusMessage instance, which is expected to be the type FacesMessages.
+ */
+ private StatusMessages getStatusMessagesInstance()
+ {
+ StatusMessages statusMessages = getCurrentManager().getInstanceByType(StatusMessages.class);
+ assert statusMessages instanceof FacesStatusMessages;
+ return statusMessages;
+ }
+}
Added: modules/trunk/faces/src/test/resources/org/jboss/seam/faces/beans.xml
===================================================================
--- modules/trunk/faces/src/test/resources/org/jboss/seam/faces/beans.xml (rev 0)
+++ modules/trunk/faces/src/test/resources/org/jboss/seam/faces/beans.xml 2009-04-29 06:01:57 UTC (rev 10705)
@@ -0,0 +1,8 @@
+<Beans xmlns="urn:java:ee"
+ xmlns:faces="urn:java:org.jboss.seam.faces">
+ <Deploy>
+ <Standard/>
+ <Production/>
+ <faces:Faces/>
+ </Deploy>
+</Beans>
Added: modules/trunk/faces/src/test/resources/org/jboss/testharness/impl/packaging/jsr299/default/beans.xml
===================================================================
Added: modules/trunk/faces/src/test/resources/test-suite.xml
===================================================================
--- modules/trunk/faces/src/test/resources/test-suite.xml (rev 0)
+++ modules/trunk/faces/src/test/resources/test-suite.xml 2009-04-29 06:01:57 UTC (rev 10705)
@@ -0,0 +1,15 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<suite name="Seam Faces Module Test Suite" verbose="1">
+ <test name="Seam Faces Module - Unit Tests">
+ <!--
+ <method-selectors>
+ <method-selector>
+ <selector-class name="org.jboss.testharness.impl.testng.DisableIntegrationTestsMethodSelector"/>
+ </method-selector>
+ </method-selectors>
+ -->
+ <packages>
+ <package name="org.jboss.seam.faces"/>
+ </packages>
+ </test>
+</suite>
More information about the seam-commits
mailing list