[seam-commits] Seam SVN: r12207 - in modules/faces/trunk/src: main/resources/META-INF and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Mar 17 07:32:37 EDT 2010


Author: nickarls
Date: 2010-03-17 07:32:35 -0400 (Wed, 17 Mar 2010)
New Revision: 12207

Modified:
   modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/GenericEventListener.java
   modules/faces/trunk/src/main/resources/META-INF/faces-config.xml
   modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/Observer.java
   modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseListenerTests.java
Log:
Some more tests
Hooking up listener in faces-config.xml
More generic manager lookup

Modified: modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/GenericEventListener.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/GenericEventListener.java	2010-03-17 10:47:07 UTC (rev 12206)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/GenericEventListener.java	2010-03-17 11:32:35 UTC (rev 12207)
@@ -2,15 +2,32 @@
 
 import javax.enterprise.inject.spi.BeanManager;
 import javax.inject.Inject;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 
-import org.jboss.weld.Container;
-
 public class GenericEventListener
 {
-   @Inject BeanManager beanManager;
-   
+   @Inject
+   BeanManager beanManager;
+
    protected BeanManager getBeanManager()
    {
-      return beanManager != null ? beanManager : Container.instance().deploymentManager();
+      if (beanManager == null)
+      {
+         beanManager = lookupBeanManager();
+      }
+      return beanManager;
    }
+
+   private BeanManager lookupBeanManager()
+   {
+      try
+      {
+         return beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
+      }
+      catch (NamingException e)
+      {
+         throw new IllegalArgumentException("Could not find BeanManager in JNDI", e);
+      }
+   }
 }

Modified: modules/faces/trunk/src/main/resources/META-INF/faces-config.xml
===================================================================
--- modules/faces/trunk/src/main/resources/META-INF/faces-config.xml	2010-03-17 10:47:07 UTC (rev 12206)
+++ modules/faces/trunk/src/main/resources/META-INF/faces-config.xml	2010-03-17 11:32:35 UTC (rev 12207)
@@ -16,6 +16,7 @@
    
    <lifecycle>
       <phase-listener>org.jboss.seam.faces.context.FlashScopedContext</phase-listener>
+      <phase-listener>org.jboss.seam.faces.PhaseEventListener</phase-listener>      
    </lifecycle>
 	
 	<!--

Modified: modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/Observer.java
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/Observer.java	2010-03-17 10:47:07 UTC (rev 12206)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/Observer.java	2010-03-17 11:32:35 UTC (rev 12207)
@@ -5,14 +5,29 @@
 import javax.faces.event.PhaseEvent;
 
 import org.jboss.seam.faces.event.qualifier.After;
+import org.jboss.seam.faces.event.qualifier.ApplyRequestValues;
 import org.jboss.seam.faces.event.qualifier.Before;
+import org.jboss.seam.faces.event.qualifier.InvokeApplication;
+import org.jboss.seam.faces.event.qualifier.ProcessValidations;
 import org.jboss.seam.faces.event.qualifier.RenderResponse;
+import org.jboss.seam.faces.event.qualifier.RestoreView;
+import org.jboss.seam.faces.event.qualifier.UpdateModelValues;
 
 @ApplicationScoped
 public class Observer
 {
    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 void observeBeforeRenderResponse(@Observes @Before @RenderResponse PhaseEvent e) 
    {
@@ -24,5 +39,54 @@
       Observer.observeAfterRenderResponse = true;
    }
    
+   public void observeBeforeApplyRequestValues(@Observes @Before @ApplyRequestValues PhaseEvent e) 
+   {
+      Observer.observeBeforeApplyRequestValues = true;
+   }
+   
+   public void observeAfterApplyRequestValues(@Observes @After @ApplyRequestValues PhaseEvent e) 
+   {
+      Observer.observeAfterApplyRequestValues = true;
+   }
+   
+   public void observeBeforeInvokeApplication(@Observes @Before @InvokeApplication PhaseEvent e) 
+   {
+      Observer.observeBeforeInvokeApplication = true;
+   }
+   
+   public void observeAfterInvokeApplication(@Observes @After @InvokeApplication PhaseEvent e) 
+   {
+      Observer.observeAfterInvokeApplication = true;
+   }   
+   
+   public void observeBeforeProcessValidations(@Observes @Before @ProcessValidations PhaseEvent e) 
+   {
+      Observer.observeBeforeProcessValidations = true;
+   }
+   
+   public void observeAfterProcessValidations(@Observes @After @ProcessValidations PhaseEvent e) 
+   {
+      Observer.observeAfterProcessValidations = true;
+   }   
+   
+   public void observeBeforeRestoreView(@Observes @Before @RestoreView PhaseEvent e) 
+   {
+      Observer.observeBeforeRestoreView = true;
+   }
+   
+   public void observeAfterRestoreView(@Observes @After @RestoreView PhaseEvent e) 
+   {
+      Observer.observeAfterRestoreView = true;
+   }  
+
+   public void observeBeforeUpdateModelValues(@Observes @Before @UpdateModelValues PhaseEvent e) 
+   {
+      Observer.observeBeforeUpdateModelValues = true;
+   }
+   
+   public void observeAfterUpdateModelValues(@Observes @After @UpdateModelValues PhaseEvent e) 
+   {
+      Observer.observeAfterUpdateModelValues = true;
+   }  
+   
 }
-

Modified: modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseListenerTests.java
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseListenerTests.java	2010-03-17 10:47:07 UTC (rev 12206)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseListenerTests.java	2010-03-17 11:32:35 UTC (rev 12207)
@@ -1,11 +1,18 @@
 package org.jboss.seam.faces.event;
 
+import javax.enterprise.util.AnnotationLiteral;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.inject.Inject;
 
 import org.jboss.arquillian.api.Deployment;
 import org.jboss.arquillian.testng.Arquillian;
+import org.jboss.seam.faces.event.qualifier.ApplyRequestValues;
+import org.jboss.seam.faces.event.qualifier.InvokeApplication;
+import org.jboss.seam.faces.event.qualifier.ProcessValidations;
+import org.jboss.seam.faces.event.qualifier.RenderResponse;
+import org.jboss.seam.faces.event.qualifier.RestoreView;
+import org.jboss.seam.faces.event.qualifier.UpdateModelValues;
 import org.jboss.shrinkwrap.api.ArchivePaths;
 import org.jboss.shrinkwrap.api.Archives;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
@@ -27,7 +34,6 @@
    }
 
    @Inject PhaseEventListener phaseEventListener;
-   @Inject Observer observer;
 
    MockFacesEnvironment environment = MockFacesEnvironment.createEnvironment();
    MockLifecycle lifecycle = new MockLifecycle();
@@ -36,14 +42,84 @@
    public void testBeforeRenderResponse()
    {
       phaseEventListener.beforePhase(new PhaseEvent(environment.getFacesContext(), PhaseId.RENDER_RESPONSE, lifecycle));
-      assert observer.observeBeforeRenderResponse;
+      assert Observer.observeBeforeRenderResponse;
    }
    
    @Test
    public void testAfterRenderResponse()
    {
       phaseEventListener.afterPhase(new PhaseEvent(environment.getFacesContext(), PhaseId.RENDER_RESPONSE, lifecycle));
-      assert observer.observeAfterRenderResponse;
+      assert Observer.observeAfterRenderResponse;
    }
    
+   @Test
+   public void testBeforeApplyRequestValues()
+   {
+      phaseEventListener.beforePhase(new PhaseEvent(environment.getFacesContext(), PhaseId.APPLY_REQUEST_VALUES, lifecycle));
+      assert Observer.observeBeforeApplyRequestValues;
+   }
+   
+   @Test
+   public void testAfterApplyRequestValues()
+   {
+      phaseEventListener.afterPhase(new PhaseEvent(environment.getFacesContext(), PhaseId.APPLY_REQUEST_VALUES, lifecycle));
+      assert Observer.observeAfterApplyRequestValues;
+   }   
+
+   @Test
+   public void testBeforeInvokeApplication()
+   {
+      phaseEventListener.beforePhase(new PhaseEvent(environment.getFacesContext(), PhaseId.INVOKE_APPLICATION, lifecycle));
+      assert Observer.observeBeforeInvokeApplication;
+   }
+   
+   @Test
+   public void testAfterInvokeApplication()
+   {
+      phaseEventListener.afterPhase(new PhaseEvent(environment.getFacesContext(), PhaseId.INVOKE_APPLICATION, lifecycle));
+      assert Observer.observeAfterInvokeApplication;
+   }   
+
+   @Test
+   public void testBeforeProcessValidations()
+   {
+      phaseEventListener.beforePhase(new PhaseEvent(environment.getFacesContext(), PhaseId.PROCESS_VALIDATIONS, lifecycle));
+      assert Observer.observeBeforeProcessValidations;
+   }
+   
+   @Test
+   public void testAfterProcessValidations()
+   {
+      phaseEventListener.afterPhase(new PhaseEvent(environment.getFacesContext(), PhaseId.PROCESS_VALIDATIONS, lifecycle));
+      assert Observer.observeAfterProcessValidations;
+   }   
+
+   @Test
+   public void testBeforeRestoreView()
+   {
+      phaseEventListener.beforePhase(new PhaseEvent(environment.getFacesContext(), PhaseId.RESTORE_VIEW, lifecycle));
+      assert Observer.observeBeforeRestoreView;
+   }
+   
+   @Test
+   public void testAfterRestoreView()
+   {
+      phaseEventListener.afterPhase(new PhaseEvent(environment.getFacesContext(), PhaseId.RESTORE_VIEW, lifecycle));
+      assert Observer.observeAfterRestoreView;
+   }   
+
+   @Test
+   public void testBeforeUpdateModelValues()
+   {
+      phaseEventListener.beforePhase(new PhaseEvent(environment.getFacesContext(), PhaseId.UPDATE_MODEL_VALUES, lifecycle));
+      assert Observer.observeBeforeUpdateModelValues;
+   }
+   
+   @Test
+   public void testAfterUpdateModelValues()
+   {
+      phaseEventListener.afterPhase(new PhaseEvent(environment.getFacesContext(), PhaseId.UPDATE_MODEL_VALUES, lifecycle));
+      assert Observer.observeAfterUpdateModelValues;
+   }   
+
 }



More information about the seam-commits mailing list