[seam-commits] Seam SVN: r12513 - in modules/faces/trunk/impl/src: test/java/org/jboss/seam/faces/event and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Apr 16 07:05:27 EDT 2010
Author: nickarls
Date: 2010-04-16 07:05:25 -0400 (Fri, 16 Apr 2010)
New Revision: 12513
Modified:
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PhaseEventBridge.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/SystemEventBridgeTest.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/SystemEventObserver.java
Log:
system tests
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PhaseEventBridge.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PhaseEventBridge.java 2010-04-16 10:42:31 UTC (rev 12512)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PhaseEventBridge.java 2010-04-16 11:05:25 UTC (rev 12513)
@@ -83,27 +83,27 @@
if (PhaseId.RESTORE_VIEW.equals(event.getPhaseId()))
{
- phaseQualifier = PhaseEventBridge.RESTORE_VIEW;
+ phaseQualifier = RESTORE_VIEW;
}
else if (PhaseId.PROCESS_VALIDATIONS.equals(event.getPhaseId()))
{
- phaseQualifier = PhaseEventBridge.PROCESS_VALIDATIONS;
+ phaseQualifier = PROCESS_VALIDATIONS;
}
else if (PhaseId.APPLY_REQUEST_VALUES.equals(event.getPhaseId()))
{
- phaseQualifier = PhaseEventBridge.APPLY_REQUEST_VALUES;
+ phaseQualifier = APPLY_REQUEST_VALUES;
}
else if (PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId()))
{
- phaseQualifier = PhaseEventBridge.INVOKE_APPLICATION;
+ phaseQualifier = INVOKE_APPLICATION;
}
else if (PhaseId.UPDATE_MODEL_VALUES.equals(event.getPhaseId()))
{
- phaseQualifier = PhaseEventBridge.UPDATE_MODEL_VALUES;
+ phaseQualifier = UPDATE_MODEL_VALUES;
}
else if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId()))
{
- phaseQualifier = PhaseEventBridge.RENDER_RESPONSE;
+ phaseQualifier = RENDER_RESPONSE;
}
else
{
Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/SystemEventBridgeTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/SystemEventBridgeTest.java 2010-04-16 10:42:31 UTC (rev 12512)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/SystemEventBridgeTest.java 2010-04-16 11:05:25 UTC (rev 12513)
@@ -24,16 +24,25 @@
import java.util.HashMap;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.event.ComponentSystemEvent;
+import javax.faces.component.UIOutput;
+import javax.faces.component.UIViewRoot;
import javax.faces.event.ExceptionQueuedEvent;
import javax.faces.event.ExceptionQueuedEventContext;
+import javax.faces.event.PostAddToViewEvent;
import javax.faces.event.PostConstructApplicationEvent;
import javax.faces.event.PostConstructCustomScopeEvent;
+import javax.faces.event.PostConstructViewMapEvent;
+import javax.faces.event.PostRestoreStateEvent;
import javax.faces.event.PostValidateEvent;
import javax.faces.event.PreDestroyApplicationEvent;
import javax.faces.event.PreDestroyCustomScopeEvent;
+import javax.faces.event.PreDestroyViewMapEvent;
+import javax.faces.event.PreRemoveFromViewEvent;
+import javax.faces.event.PreRenderComponentEvent;
+import javax.faces.event.PreRenderViewEvent;
+import javax.faces.event.PreValidateEvent;
import javax.faces.event.ScopeContext;
+import javax.faces.event.SystemEvent;
import javax.inject.Inject;
import org.jboss.arquillian.api.Deployment;
@@ -43,10 +52,7 @@
import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
-import org.jboss.test.faces.mock.MockFacesEnvironment;
import org.jboss.test.faces.mock.application.MockApplication;
-import org.jboss.test.faces.mock.component.MockUIComponent;
-import org.jboss.test.faces.mock.component.MockUIComponentBase;
import org.jboss.test.faces.mock.context.MockFacesContext;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -67,58 +73,195 @@
}
@Inject
- SystemEventBridge systemEventListener;
+ SystemEventBridge listener;
+ @Inject
+ SystemEventObserver observer;
+
private final MockFacesContext facesContext = new MockFacesContext();
private final MockApplication application = new MockApplication();
+ private final ScopeContext scopeContext = new ScopeContext("foo", new HashMap<String, Object>());
+ private final ExceptionQueuedEventContext eventContext = new ExceptionQueuedEventContext(facesContext, new NullPointerException());
+ private static final UIComponent component = new UIOutput();
-// Skip until we find out how to set ID:s on mocks...
-// @Test
- public void testSpecificPostComponentValidation()
+ static
{
- UIComponent c = new MockUIComponent();
- System.out.println(c.getId());
- systemEventListener.processEvent(new PostValidateEvent(c));
- assert SystemEventObserver.specificComponentValidationEvent;
+ component.setId("foo");
}
@Test
- public void testExceptionQueuedEventObserver()
+ public void testObservePostConstructApplication()
{
- ExceptionQueuedEventContext eqec = new ExceptionQueuedEventContext(facesContext, new NullPointerException());
- ExceptionQueuedEvent eqe = new ExceptionQueuedEvent(eqec);
- systemEventListener.processEvent(eqe);
- assert SystemEventObserver.excecptionQueuedEvent;
+ fireAndAssert("1", new PostConstructApplicationEvent(application));
}
@Test
- public void testPostConstructApplicationEventObserver()
+ public void testObservePreDestroyApplication()
{
- systemEventListener.processEvent(new PostConstructApplicationEvent(application));
- assert SystemEventObserver.postConstructApplicationEvent;
+ fireAndAssert("2", new PreDestroyApplicationEvent(application));
}
@Test
- public void testPostConstructCustomScopeEvent()
+ public void testObservePostConstructCustomScope()
{
- ScopeContext sc = new ScopeContext("dummyscope", new HashMap<String, Object>());
- systemEventListener.processEvent(new PostConstructCustomScopeEvent(sc));
- assert SystemEventObserver.postConstructCustomScopeEvent;
+ fireAndAssert("3", new PostConstructCustomScopeEvent(scopeContext));
}
@Test
- public void testPreDestroyApplicationEventObserver()
+ public void testObservePreDestroyCustomScope()
{
- systemEventListener.processEvent(new PreDestroyApplicationEvent(application));
- assert SystemEventObserver.preDestroyApplicationEvent;
+ fireAndAssert("4", new PreDestroyCustomScopeEvent(scopeContext));
}
@Test
- public void testPreDestroyCustomScopeEventObserver()
+ public void testObserveExceptionQueued()
{
- ScopeContext sc = new ScopeContext("dummyscope", new HashMap<String, Object>());
- systemEventListener.processEvent(new PreDestroyCustomScopeEvent(sc));
- assert SystemEventObserver.preDestroyCustomScopeEvent;
+ fireAndAssert("5", new ExceptionQueuedEvent(eventContext));
}
+ @Test
+ public void testObserveComponentSystemEvent()
+ {
+ fireAndAssert("6", new PreValidateEvent(component));
+ }
+
+ @Test
+ public void testObservePreValidate()
+ {
+ fireAndAssert("7", new PreValidateEvent(component));
+ }
+
+ @Test
+ public void testObservePreValidateComponent()
+ {
+ fireAndAssert("8", new PreValidateEvent(component));
+ }
+
+ @Test
+ public void testObserveComponent()
+ {
+ fireAndAssert("9", new PreValidateEvent(component));
+ }
+
+ @Test
+ public void testObservePostValidate()
+ {
+ fireAndAssert("10", new PostValidateEvent(component));
+ }
+
+ @Test
+ public void testObservePostValidateComponent()
+ {
+ fireAndAssert("11", new PostValidateEvent(component));
+ }
+
+ @Test
+ public void testObservePostAddToView()
+ {
+ fireAndAssert("12", new PostAddToViewEvent(component));
+ }
+
+ @Test
+ public void testObservePostAddToViewComponent()
+ {
+ fireAndAssert("13", new PostAddToViewEvent(component));
+ }
+
+ @Test
+ public void testObservePostConstructViewMap()
+ {
+ fireAndAssert("14", new PostConstructViewMapEvent(new UIViewRoot()));
+ }
+
+ @Test
+ public void testObservePostRestoreState()
+ {
+ fireAndAssert("15", new PostRestoreStateEvent(component));
+ }
+
+ @Test
+ public void testObservePostRestoreStateComponent()
+ {
+ fireAndAssert("16", new PostRestoreStateEvent(component));
+ }
+
+ @Test
+ public void testObservePreDestroyViewMap()
+ {
+ fireAndAssert("17", new PreDestroyViewMapEvent(new UIViewRoot()));
+ }
+
+ @Test
+ public void testObservePreRemoveFromView()
+ {
+ fireAndAssert("18", new PreRemoveFromViewEvent(component));
+ }
+
+ @Test
+ public void testObservePreRemoveFromViewComponent()
+ {
+ fireAndAssert("19", new PreRemoveFromViewEvent(component));
+ }
+
+ @Test
+ public void testObservePreRenderComponent()
+ {
+ fireAndAssert("20", new PreRenderComponentEvent(component));
+ }
+
+ @Test
+ public void testObservePreRenderComponentComponent()
+ {
+ fireAndAssert("21", new PreRenderComponentEvent(component));
+ }
+
+ @Test
+ public void testObservePreRenderView()
+ {
+ fireAndAssert("22", new PreRenderViewEvent(new UIViewRoot()));
+ }
+
+
+ private void fireAndAssert(String caseId, SystemEvent... events)
+ {
+ observer.reset();
+ for (SystemEvent e : events) {
+ listener.processEvent(e);
+ }
+ observer.assertObservations(caseId, events);
+ }
+
+ /*
+ * @Test public void testSpecificPostComponentValidation() { UIComponent c =
+ * new UIOutput(); c.setId("foo"); systemEventListener.processEvent(new
+ * PostValidateEvent(c)); assert
+ * SystemEventObserver.specificComponentValidationEvent; }
+ *
+ * @Test public void testExceptionQueuedEventObserver() {
+ * ExceptionQueuedEventContext eqec = new
+ * ExceptionQueuedEventContext(facesContext, new NullPointerException());
+ * ExceptionQueuedEvent eqe = new ExceptionQueuedEvent(eqec);
+ * systemEventListener.processEvent(eqe); assert
+ * SystemEventObserver.excecptionQueuedEvent; }
+ *
+ * @Test public void testPostConstructApplicationEventObserver() {
+ * systemEventListener.processEvent(new
+ * PostConstructApplicationEvent(application)); assert
+ * SystemEventObserver.postConstructApplicationEvent; }
+ *
+ * @Test public void testPostConstructCustomScopeEvent() { ScopeContext sc =
+ * new ScopeContext("dummyscope", new HashMap<String, Object>());
+ * systemEventListener.processEvent(new PostConstructCustomScopeEvent(sc));
+ * assert SystemEventObserver.postConstructCustomScopeEvent; }
+ *
+ * @Test public void testPreDestroyApplicationEventObserver() {
+ * systemEventListener.processEvent(new
+ * PreDestroyApplicationEvent(application)); assert
+ * SystemEventObserver.preDestroyApplicationEvent; }
+ *
+ * @Test public void testPreDestroyCustomScopeEventObserver() { ScopeContext
+ * sc = new ScopeContext("dummyscope", new HashMap<String, Object>());
+ * systemEventListener.processEvent(new PreDestroyCustomScopeEvent(sc));
+ * assert SystemEventObserver.preDestroyCustomScopeEvent; }
+ */
}
Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/SystemEventObserver.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/SystemEventObserver.java 2010-04-16 10:42:31 UTC (rev 12512)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/SystemEventObserver.java 2010-04-16 11:05:25 UTC (rev 12513)
@@ -21,15 +21,30 @@
*/
package org.jboss.seam.faces.event;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.faces.event.ComponentSystemEvent;
import javax.faces.event.ExceptionQueuedEvent;
+import javax.faces.event.PostAddToViewEvent;
import javax.faces.event.PostConstructApplicationEvent;
import javax.faces.event.PostConstructCustomScopeEvent;
+import javax.faces.event.PostConstructViewMapEvent;
+import javax.faces.event.PostRestoreStateEvent;
import javax.faces.event.PostValidateEvent;
import javax.faces.event.PreDestroyApplicationEvent;
import javax.faces.event.PreDestroyCustomScopeEvent;
+import javax.faces.event.PreDestroyViewMapEvent;
+import javax.faces.event.PreRemoveFromViewEvent;
+import javax.faces.event.PreRenderComponentEvent;
+import javax.faces.event.PreRenderViewEvent;
+import javax.faces.event.PreValidateEvent;
+import javax.faces.event.SystemEvent;
import org.jboss.seam.faces.event.qualifier.Component;
@@ -41,46 +56,138 @@
@ApplicationScoped
public class SystemEventObserver
{
- public static boolean componentSystemEvent;
- public static boolean excecptionQueuedEvent;
- public static boolean postConstructApplicationEvent;
- public static boolean postConstructCustomScopeEvent;
- public static boolean preDestroyApplicationEvent;
- public static boolean preDestroyCustomScopeEvent;
- public static boolean specificComponentValidationEvent;
+ private Map<String, List<SystemEvent>> observations = new HashMap<String, List<SystemEvent>>();
- public void observeSpecificComponentValidation(@Observes @Component("foo") PostValidateEvent e)
+ private void recordObservation(String id, SystemEvent observation)
{
- specificComponentValidationEvent = true;
+ List<SystemEvent> observed = observations.get(id);
+ if (observed == null)
+ {
+ observed = new ArrayList<SystemEvent>();
+ observations.put(id, observed);
+ }
+ observed.add(observation);
}
- public void observeComponentSystemEvent(@Observes ComponentSystemEvent e)
+ public void reset()
{
- componentSystemEvent = true;
+ observations.clear();
}
- public void observeExceptionQueuedEvent(@Observes ExceptionQueuedEvent e)
+ public void assertObservations(String id, SystemEvent... observations)
{
- excecptionQueuedEvent = true;
+ List<SystemEvent> observed = this.observations.get(id);
+ assert observed != null && observed.size() == observations.length;
+ assert observed.containsAll(Arrays.asList(observations));
}
- public void observePostConstructApplicationEvent(@Observes PostConstructApplicationEvent e)
+ public void observe(@Observes PostConstructApplicationEvent e)
{
- postConstructApplicationEvent = true;
+ recordObservation("1", e);
}
- public void observePreDestroyApplicationEvent(@Observes PreDestroyApplicationEvent e)
+ public void observe(@Observes PreDestroyApplicationEvent e)
{
- preDestroyApplicationEvent = true;
+ recordObservation("2", e);
}
- public void observePostConstructCustomScopeEvent(@Observes PostConstructCustomScopeEvent e)
+ public void observe(@Observes PostConstructCustomScopeEvent e)
{
- postConstructCustomScopeEvent = true;
+ recordObservation("3", e);
}
- public void observePreDestroyCustomScopeEvent(@Observes PreDestroyCustomScopeEvent e)
+ public void observe(@Observes PreDestroyCustomScopeEvent e)
{
- preDestroyCustomScopeEvent = true;
+ recordObservation("4", e);
}
+
+ public void observe(@Observes ExceptionQueuedEvent e)
+ {
+ recordObservation("5", e);
+ }
+
+ public void observe(@Observes ComponentSystemEvent e)
+ {
+ recordObservation("6", e);
+ }
+
+ public void observe(@Observes PreValidateEvent e)
+ {
+ recordObservation("7", e);
+ }
+
+ public void observe2(@Observes @Component("foo") PreValidateEvent e)
+ {
+ recordObservation("8", e);
+ }
+
+ public void observe3(@Observes @Component("foo") ComponentSystemEvent e)
+ {
+ recordObservation("9", e);
+ }
+
+ public void observe(@Observes PostValidateEvent e)
+ {
+ recordObservation("10", e);
+ }
+
+ public void observe2(@Observes @Component("foo") PostValidateEvent e)
+ {
+ recordObservation("11", e);
+ }
+
+ public void observe(@Observes PostAddToViewEvent e)
+ {
+ recordObservation("12", e);
+ }
+
+ public void observe2(@Observes @Component("foo") PostAddToViewEvent e)
+ {
+ recordObservation("13", e);
+ }
+
+ public void observe2(@Observes PostConstructViewMapEvent e)
+ {
+ recordObservation("14", e);
+ }
+
+ public void observe(@Observes PostRestoreStateEvent e)
+ {
+ recordObservation("15", e);
+ }
+
+ public void observe2(@Observes @Component("foo") PostRestoreStateEvent e)
+ {
+ recordObservation("16", e);
+ }
+
+ public void observe2(@Observes PreDestroyViewMapEvent e)
+ {
+ recordObservation("17", e);
+ }
+
+ public void observe(@Observes PreRemoveFromViewEvent e)
+ {
+ recordObservation("18", e);
+ }
+
+ public void observe2(@Observes @Component("foo") PreRemoveFromViewEvent e)
+ {
+ recordObservation("19", e);
+ }
+
+ public void observe(@Observes PreRenderComponentEvent e)
+ {
+ recordObservation("20", e);
+ }
+
+ public void observe2(@Observes @Component("foo") PreRenderComponentEvent e)
+ {
+ recordObservation("21", e);
+ }
+
+ public void observe(@Observes PreRenderViewEvent e)
+ {
+ recordObservation("22", e);
+ }
}
More information about the seam-commits
mailing list