[seam-commits] Seam SVN: r12818 - in modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces: event and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed May 26 15:41:42 EDT 2010


Author: lincolnthree
Date: 2010-05-26 15:41:42 -0400 (Wed, 26 May 2010)
New Revision: 12818

Added:
   modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/PhaseTestBase.java
   modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/status/
   modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/status/MessagesAdapterTest.java
Modified:
   modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java
Log:
Added MessagesAdapterTest - still need to figure out how to check the end state of the MockFacesContext.

Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/PhaseTestBase.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/PhaseTestBase.java	                        (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/PhaseTestBase.java	2010-05-26 19:41:42 UTC (rev 12818)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.faces;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.inject.Inject;
+
+import org.jboss.seam.faces.event.PhaseEventBridge;
+import org.jboss.test.faces.mock.context.MockFacesContext;
+import org.jboss.test.faces.mock.lifecycle.MockLifecycle;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class PhaseTestBase
+{
+   @Inject
+   PhaseEventBridge phaseEventBridge;
+
+   protected final MockFacesContext facesContext = new MockFacesContext();
+   protected final MockLifecycle lifecycle = new MockLifecycle();
+
+   static List<PhaseId> ALL_PHASES = new ArrayList<PhaseId>()
+   {
+      private static final long serialVersionUID = 1L;
+
+      {
+         add(PhaseId.APPLY_REQUEST_VALUES);
+         add(PhaseId.INVOKE_APPLICATION);
+         add(PhaseId.PROCESS_VALIDATIONS);
+         add(PhaseId.RENDER_RESPONSE);
+         add(PhaseId.RESTORE_VIEW);
+         add(PhaseId.UPDATE_MODEL_VALUES);
+      }
+   };
+
+   protected void fireAllPhases()
+   {
+      fireAllBeforePhases();
+      fireAllAfterPhases();
+   }
+
+   protected void fireAllBeforePhases()
+   {
+      fireBeforePhases(ALL_PHASES);
+   }
+
+   protected void fireBeforePhases(final List<PhaseId> phases)
+   {
+      for (PhaseId phaseId : phases)
+      {
+         fireBeforePhase(phaseId);
+      }
+   }
+
+   protected void fireBeforePhase(final PhaseId phaseId)
+   {
+      phaseEventBridge.beforePhase(new PhaseEvent(facesContext, phaseId, lifecycle));
+   }
+
+   protected void fireAllAfterPhases()
+   {
+      fireAfterPhases(ALL_PHASES);
+   }
+
+   protected void fireAfterPhases(final List<PhaseId> phases)
+   {
+      for (PhaseId phaseId : phases)
+      {
+         fireAfterPhase(phaseId);
+      }
+   }
+
+   protected void fireAfterPhase(final PhaseId phaseId)
+   {
+      phaseEventBridge.afterPhase(new PhaseEvent(facesContext, phaseId, lifecycle));
+   }
+}

Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java	2010-05-26 18:44:38 UTC (rev 12817)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java	2010-05-26 19:41:42 UTC (rev 12818)
@@ -21,22 +21,17 @@
  */
 package org.jboss.seam.faces.event;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.inject.Inject;
 
 import org.jboss.arquillian.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.faces.PhaseTestBase;
 import org.jboss.seam.faces.MockLogger;
 import org.jboss.shrinkwrap.api.ArchivePaths;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
-import org.jboss.test.faces.mock.context.MockFacesContext;
-import org.jboss.test.faces.mock.lifecycle.MockLifecycle;
 import org.jboss.weld.extensions.beanManager.BeanManagerAware;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -47,22 +42,9 @@
  * 
  */
 @RunWith(Arquillian.class)
-public class PhaseEventBridgeTest
+public class PhaseEventBridgeTest extends PhaseTestBase
 {
-   private static List<PhaseId> ALL_PHASES = new ArrayList<PhaseId>()
-   {
-      private static final long serialVersionUID = 1L;
 
-      {
-         add(PhaseId.APPLY_REQUEST_VALUES);
-         add(PhaseId.INVOKE_APPLICATION);
-         add(PhaseId.PROCESS_VALIDATIONS);
-         add(PhaseId.RENDER_RESPONSE);
-         add(PhaseId.RESTORE_VIEW);
-         add(PhaseId.UPDATE_MODEL_VALUES);
-      }
-   };
-
    @Deployment
    public static JavaArchive createTestArchive()
    {
@@ -70,55 +52,8 @@
    }
 
    @Inject
-   PhaseEventBridge phaseEventBridge;
-   @Inject
    MockPhaseEventObserver observer;
 
-   private final MockFacesContext facesContext = new MockFacesContext();
-   private final MockLifecycle lifecycle = new MockLifecycle();
-
-   private void fireAllPhases()
-   {
-      fireAllBeforePhases();
-      fireAllAfterPhases();
-   }
-
-   private void fireAllBeforePhases()
-   {
-      fireBeforePhases(ALL_PHASES);
-   }
-
-   private void fireBeforePhases(final List<PhaseId> phases)
-   {
-      for (PhaseId phaseId : phases)
-      {
-         fireBeforePhase(phaseId);
-      }
-   }
-
-   private void fireBeforePhase(final PhaseId phaseId)
-   {
-      phaseEventBridge.beforePhase(new PhaseEvent(facesContext, phaseId, lifecycle));
-   }
-
-   private void fireAllAfterPhases()
-   {
-      fireAfterPhases(ALL_PHASES);
-   }
-
-   private void fireAfterPhases(final List<PhaseId> phases)
-   {
-      for (PhaseId phaseId : phases)
-      {
-         fireAfterPhase(phaseId);
-      }
-   }
-
-   private void fireAfterPhase(final PhaseId phaseId)
-   {
-      phaseEventBridge.afterPhase(new PhaseEvent(facesContext, phaseId, lifecycle));
-   }
-
    @Test
    public void testBeforeRenderResponseObserver()
    {

Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/status/MessagesAdapterTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/status/MessagesAdapterTest.java	                        (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/status/MessagesAdapterTest.java	2010-05-26 19:41:42 UTC (rev 12818)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.faces.status;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import javax.faces.event.PhaseId;
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.faces.MockLogger;
+import org.jboss.seam.faces.PhaseTestBase;
+import org.jboss.seam.faces.event.PhaseEventBridge;
+import org.jboss.seam.international.status.Bundles;
+import org.jboss.seam.international.status.MessageFactory;
+import org.jboss.seam.international.status.Messages;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+ at RunWith(Arquillian.class)
+public class MessagesAdapterTest extends PhaseTestBase
+{
+   @Deployment
+   public static JavaArchive createTestArchive()
+   {
+      return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(MessagesAdapter.class, Messages.class, MessageFactory.class, Bundles.class, PhaseEventBridge.class, MockLogger.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+   }
+
+   @Inject
+   Messages messages;
+
+   @Test
+   public void testBeforeRenderResponseObserver()
+   {
+      messages.add(messages.info("Hey! This is a message"));
+      assertEquals(1, messages.getAll().size());
+
+      fireBeforePhase(PhaseId.RENDER_RESPONSE);
+
+      assertTrue(messages.getAll().isEmpty());
+      // assertNotNull(facesContext.getMessages());
+   }
+
+}



More information about the seam-commits mailing list