[seam-commits] Seam SVN: r12381 - modules/faces/trunk/src/test/java/org/jboss/seam/faces/event.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Apr 5 07:15:13 EDT 2010
Author: nickarls
Date: 2010-04-05 07:15:13 -0400 (Mon, 05 Apr 2010)
New Revision: 12381
Modified:
modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java
modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java
Log:
test tunings
Modified: modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java 2010-04-05 08:58:08 UTC (rev 12380)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java 2010-04-05 11:15:13 UTC (rev 12381)
@@ -1,7 +1,21 @@
package org.jboss.seam.faces.event;
-import static org.junit.Assert.assertEquals;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_APPLY_VALUES;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_INVOKE_APPLICATION;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_PROCESS_VALIDATION;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_RENDER_RESPONSE;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_RESTORE_VIEW;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_UPDATE_MODEL_VALUES;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_APPLY_VALUES;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_INVOKE_APPLICATION;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_PROCESS_VALIDATION;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_RENDER_RESPONSE;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_RESTORE_VIEW;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_UPDATE_MODEL_VALUES;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.inject.Inject;
@@ -22,6 +36,20 @@
@RunWith(Arquillian.class)
public class PhaseEventBridgeTest
{
+ 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()
{
@@ -30,6 +58,8 @@
@Inject
PhaseEventBridge phaseEventBridge;
+ @Inject
+ PhaseEventObserver observer;
private final MockFacesContext facesContext = new MockFacesContext();
private final MockLifecycle lifecycle = new MockLifecycle();
@@ -37,103 +67,149 @@
@Test
public void testBeforeAnyPhaseObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, lifecycle));
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, lifecycle));
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, lifecycle));
- assertEquals(3, PhaseEventObserver.beforeAnyPhaseCount);
+ observer.reset();
+ fireAllBeforePhases();
+ observer.assertAllBeforePhasesObserved();
}
+ private void fireAllBeforePhases()
+ {
+ fireBeforePhases(ALL_PHASES);
+ }
+
+ private void fireBeforePhases(List<PhaseId> phases)
+ {
+ for (PhaseId phaseId : phases)
+ {
+ fireBeforePhase(phaseId);
+ }
+ }
+
+ private void fireBeforePhase(PhaseId phaseId)
+ {
+ phaseEventBridge.beforePhase(new PhaseEvent(facesContext, phaseId, lifecycle));
+ }
+
@Test
public void testAfterAnyPhaseObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, lifecycle));
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, lifecycle));
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, lifecycle));
- assertEquals(3, PhaseEventObserver.afterAnyPhaseCount);
+ observer.reset();
+ fireAllAfterPhases();
+ observer.assertAllAfterPhasesObserved();
}
+ private void fireAllAfterPhases()
+ {
+ fireAfterPhases(ALL_PHASES);
+ }
+
+ private void fireAfterPhases(List<PhaseId> phases)
+ {
+ for (PhaseId phaseId : phases)
+ {
+ fireAfterPhase(phaseId);
+ }
+ }
+
+ private void fireAfterPhase(PhaseId phaseId)
+ {
+ phaseEventBridge.afterPhase(new PhaseEvent(facesContext, phaseId, lifecycle));
+ }
+
@Test
public void testBeforeRenderResponseObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, lifecycle));
- assert PhaseEventObserver.observeBeforeRenderResponse;
+ observer.reset();
+ fireBeforePhase(PhaseId.RENDER_RESPONSE);
+ observer.assertSingleObservation(BEFORE_RENDER_RESPONSE);
}
@Test
public void testAfterRenderResponseObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, lifecycle));
- assert PhaseEventObserver.observeAfterRenderResponse;
+ observer.reset();
+ fireAfterPhase(PhaseId.RENDER_RESPONSE);
+ observer.assertSingleObservation(AFTER_RENDER_RESPONSE);
}
@Test
public void testBeforeApplyRequestValuesObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, lifecycle));
- assert PhaseEventObserver.observeBeforeApplyRequestValues;
+ observer.reset();
+ fireBeforePhase(PhaseId.APPLY_REQUEST_VALUES);
+ observer.assertSingleObservation(BEFORE_APPLY_VALUES);
}
@Test
public void testAfterApplyRequestValuesObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, lifecycle));
- assert PhaseEventObserver.observeAfterApplyRequestValues;
+ observer.reset();
+ fireAfterPhase(PhaseId.APPLY_REQUEST_VALUES);
+ observer.assertSingleObservation(AFTER_APPLY_VALUES);
}
@Test
public void testBeforeInvokeApplicationObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, lifecycle));
- assert PhaseEventObserver.observeBeforeInvokeApplication;
+ observer.reset();
+ fireBeforePhase(PhaseId.INVOKE_APPLICATION);
+ observer.assertSingleObservation(BEFORE_INVOKE_APPLICATION);
}
@Test
public void testAfterInvokeApplicationObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, lifecycle));
- assert PhaseEventObserver.observeAfterInvokeApplication;
+ observer.reset();
+ fireAfterPhase(PhaseId.INVOKE_APPLICATION);
+ observer.assertSingleObservation(AFTER_INVOKE_APPLICATION);
}
@Test
public void testBeforeProcessValidationsObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, lifecycle));
- assert PhaseEventObserver.observeBeforeProcessValidations;
+ observer.reset();
+ fireBeforePhase(PhaseId.PROCESS_VALIDATIONS);
+ observer.assertSingleObservation(BEFORE_PROCESS_VALIDATION);
}
@Test
public void testAfterProcessValidationsObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, lifecycle));
- assert PhaseEventObserver.observeAfterProcessValidations;
+ observer.reset();
+ fireAfterPhase(PhaseId.PROCESS_VALIDATIONS);
+ observer.assertSingleObservation(AFTER_PROCESS_VALIDATION);
}
@Test
public void testBeforeRestoreViewObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, lifecycle));
- assert PhaseEventObserver.observeBeforeRestoreView;
+ observer.reset();
+ fireBeforePhase(PhaseId.RESTORE_VIEW);
+ observer.assertSingleObservation(BEFORE_RESTORE_VIEW);
}
@Test
public void testAfterRestoreViewObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, lifecycle));
- assert PhaseEventObserver.observeAfterRestoreView;
+ observer.reset();
+ fireAfterPhase(PhaseId.RESTORE_VIEW);
+ observer.assertSingleObservation(AFTER_RESTORE_VIEW);
}
@Test
public void testBeforeUpdateModelValuesObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, lifecycle));
- assert PhaseEventObserver.observeBeforeUpdateModelValues;
+ observer.reset();
+ fireBeforePhase(PhaseId.UPDATE_MODEL_VALUES);
+ observer.assertSingleObservation(BEFORE_UPDATE_MODEL_VALUES);
}
@Test
public void testAfterUpdateModelValuesObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, lifecycle));
- assert PhaseEventObserver.observeAfterUpdateModelValues;
+ observer.reset();
+ fireAfterPhase(PhaseId.UPDATE_MODEL_VALUES);
+ observer.assertSingleObservation(AFTER_UPDATE_MODEL_VALUES);
}
}
Modified: modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java 2010-04-05 08:58:08 UTC (rev 12380)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java 2010-04-05 11:15:13 UTC (rev 12381)
@@ -1,5 +1,8 @@
package org.jboss.seam.faces.event;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.faces.event.PhaseEvent;
@@ -17,89 +20,169 @@
@ApplicationScoped
public class PhaseEventObserver
{
- public static boolean observeBeforeRenderResponse;
- public static boolean observeAfterRenderResponse;
- public static boolean observeBeforeApplyRequestValues;
- public static boolean observeAfterApplyRequestValues;
- public static boolean observeBeforeInvokeApplication;
- public static boolean observeAfterInvokeApplication;
- public static boolean observeBeforeProcessValidations;
- public static boolean observeAfterProcessValidations;
- public static boolean observeBeforeRestoreView;
- public static boolean observeAfterRestoreView;
- public static boolean observeBeforeUpdateModelValues;
- public static boolean observeAfterUpdateModelValues;
- public static int beforeAnyPhaseCount;
- public static int afterAnyPhaseCount;
+ public static enum Observation
+ {
+ BEFORE_RENDER_RESPONSE, AFTER_RENDER_RESPONSE, BEFORE_APPLY_VALUES, AFTER_APPLY_VALUES, BEFORE_INVOKE_APPLICATION, AFTER_INVOKE_APPLICATION, BEFORE_PROCESS_VALIDATION, BEFORE_RESTORE_VIEW, AFTER_RESTORE_VIEW, AFTER_UPDATE_MODEL_VALUES, AFTER_PROCESS_VALIDATION, BEFORE_UPDATE_MODEL_VALUES
+ }
+ private static final List<Observation> ALL_BEFORE_OBSERVATIONS = new ArrayList<Observation>()
+ {
+ private static final long serialVersionUID = 1L;
+ {
+ add(Observation.BEFORE_APPLY_VALUES);
+ add(Observation.BEFORE_INVOKE_APPLICATION);
+ add(Observation.BEFORE_PROCESS_VALIDATION);
+ add(Observation.BEFORE_RENDER_RESPONSE);
+ add(Observation.BEFORE_RESTORE_VIEW);
+ add(Observation.BEFORE_UPDATE_MODEL_VALUES);
+ }
+ };
+
+ private static final List<Observation> ALL_AFTER_OBSERVATIONS = new ArrayList<Observation>()
+ {
+ private static final long serialVersionUID = 1L;
+ {
+ add(Observation.AFTER_APPLY_VALUES);
+ add(Observation.AFTER_INVOKE_APPLICATION);
+ add(Observation.AFTER_PROCESS_VALIDATION);
+ add(Observation.AFTER_RENDER_RESPONSE);
+ add(Observation.AFTER_RESTORE_VIEW);
+ add(Observation.AFTER_UPDATE_MODEL_VALUES);
+ }
+ };
+
+ private List<Observation> observations = new ArrayList<Observation>();
+ private List<Observation> beforeAnyObservations = new ArrayList<Observation>();
+ private List<Observation> afterAnyObservations = new ArrayList<Observation>();
+
+ public void reset()
+ {
+ observations.clear();
+ beforeAnyObservations.clear();
+ afterAnyObservations.clear();
+ }
+
+ public void assertSingleObservation(Observation observation)
+ {
+ assert observations.size() == 1;
+ assert observation.equals(observations.iterator().next());
+ }
+
+ private void recordObservation(Observation observation)
+ {
+ observations.add(observation);
+ }
+
public void observeBeforeAnyPhase(@Observes @Before @AnyPhase final PhaseEvent e)
{
- beforeAnyPhaseCount++;
+ recordBeforeAnyObservations();
}
+ private void recordBeforeAnyObservations()
+ {
+ recordBeforeAnyObservation(Observation.BEFORE_APPLY_VALUES);
+ recordBeforeAnyObservation(Observation.BEFORE_INVOKE_APPLICATION);
+ recordBeforeAnyObservation(Observation.BEFORE_PROCESS_VALIDATION);
+ recordBeforeAnyObservation(Observation.BEFORE_RENDER_RESPONSE);
+ recordBeforeAnyObservation(Observation.BEFORE_RESTORE_VIEW);
+ recordBeforeAnyObservation(Observation.BEFORE_UPDATE_MODEL_VALUES);
+ }
+
+ private void recordBeforeAnyObservation(Observation observation)
+ {
+ beforeAnyObservations.add(observation);
+ }
+
public void observeAfterAnyPhase(@Observes @After @AnyPhase final PhaseEvent e)
{
- afterAnyPhaseCount++;
+ recordAfterAnyObservations();
}
+ private void recordAfterAnyObservations()
+ {
+ recordAfterAnyObservation(Observation.AFTER_APPLY_VALUES);
+ recordAfterAnyObservation(Observation.AFTER_INVOKE_APPLICATION);
+ recordAfterAnyObservation(Observation.AFTER_PROCESS_VALIDATION);
+ recordAfterAnyObservation(Observation.AFTER_RENDER_RESPONSE);
+ recordAfterAnyObservation(Observation.AFTER_RESTORE_VIEW);
+ recordAfterAnyObservation(Observation.AFTER_UPDATE_MODEL_VALUES);
+ }
+
+ private void recordAfterAnyObservation(Observation observation)
+ {
+ afterAnyObservations.add(observation);
+ }
+
public void observeBeforeRenderResponse(@Observes @Before @RenderResponse final PhaseEvent e)
{
- observeBeforeRenderResponse = true;
+ recordObservation(Observation.BEFORE_RENDER_RESPONSE);
}
public void observeAfterRenderResponse(@Observes @After @RenderResponse final PhaseEvent e)
{
- observeAfterRenderResponse = true;
+ recordObservation(Observation.AFTER_RENDER_RESPONSE);
}
public void observeBeforeApplyRequestValues(@Observes @Before @ApplyRequestValues final PhaseEvent e)
{
- observeBeforeApplyRequestValues = true;
+ recordObservation(Observation.BEFORE_APPLY_VALUES);
}
public void observeAfterApplyRequestValues(@Observes @After @ApplyRequestValues final PhaseEvent e)
{
- observeAfterApplyRequestValues = true;
+ recordObservation(Observation.AFTER_APPLY_VALUES);
}
public void observeBeforeInvokeApplication(@Observes @Before @InvokeApplication final PhaseEvent e)
{
- observeBeforeInvokeApplication = true;
+ recordObservation(Observation.BEFORE_INVOKE_APPLICATION);
}
public void observeAfterInvokeApplication(@Observes @After @InvokeApplication final PhaseEvent e)
{
- observeAfterInvokeApplication = true;
+ recordObservation(Observation.AFTER_INVOKE_APPLICATION);
}
public void observeBeforeProcessValidations(@Observes @Before @ProcessValidations final PhaseEvent e)
{
- observeBeforeProcessValidations = true;
+ recordObservation(Observation.BEFORE_PROCESS_VALIDATION);
}
public void observeAfterProcessValidations(@Observes @After @ProcessValidations final PhaseEvent e)
{
- observeAfterProcessValidations = true;
+ recordObservation(Observation.AFTER_PROCESS_VALIDATION);
}
public void observeBeforeRestoreView(@Observes @Before @RestoreView final PhaseEvent e)
{
- observeBeforeRestoreView = true;
+ recordObservation(Observation.BEFORE_RESTORE_VIEW);
}
public void observeAfterRestoreView(@Observes @After @RestoreView final PhaseEvent e)
{
- observeAfterRestoreView = true;
+ recordObservation(Observation.AFTER_RESTORE_VIEW);
}
public void observeBeforeUpdateModelValues(@Observes @Before @UpdateModelValues final PhaseEvent e)
{
- observeBeforeUpdateModelValues = true;
+ recordObservation(Observation.BEFORE_UPDATE_MODEL_VALUES);
}
public void observeAfterUpdateModelValues(@Observes @After @UpdateModelValues final PhaseEvent e)
{
- observeAfterUpdateModelValues = true;
+ recordObservation(Observation.AFTER_UPDATE_MODEL_VALUES);
}
+ public void assertAllAfterPhasesObserved()
+ {
+// assert afterAnyObservations.size() == ALL_AFTER_OBSERVATIONS.size();
+ assert afterAnyObservations.containsAll(ALL_AFTER_OBSERVATIONS);
+ }
+
+ public void assertAllBeforePhasesObserved()
+ {
+// assert beforeAnyObservations.size() == ALL_BEFORE_OBSERVATIONS.size();
+ assert beforeAnyObservations.containsAll(ALL_BEFORE_OBSERVATIONS);
+ }
+
}
More information about the seam-commits
mailing list