You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/10/14 21:00:29 UTC

svn commit: r1022655 - in /myfaces/extensions/cdi/trunk/test-modules/webapp-test-module: ./ src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/ src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/bean/ src/test/java/o...

Author: jakobk
Date: Thu Oct 14 19:00:29 2010
New Revision: 1022655

URL: http://svn.apache.org/viewvc?rev=1022655&view=rev
Log:
EXTCDI-10 and EXTCDI-11 test cases

Added:
    myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/
    myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/PhaseListenerTest.java
    myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/bean/
    myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/bean/PhaseListenerBean.java
    myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/
    myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/AllPhaseListener.java
    myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/ValidationPhaseListener.java
    myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/resources/listener/
    myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/resources/listener/phase-listener-test1.xhtml
      - copied, changed from r1021829, myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/resources/events/access-bean-event-test1.xhtml
Modified:
    myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/pom.xml

Modified: myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/pom.xml?rev=1022655&r1=1022654&r2=1022655&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/pom.xml (original)
+++ myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/pom.xml Thu Oct 14 19:00:29 2010
@@ -223,6 +223,12 @@
                                <configuration>
                                    <skip>false</skip>
 
+                                   <!--
+                                       fork for every test to circumvent OutOfMemoryError: PermGen space
+                                       (which occurs if there is too much classloading)
+                                    -->
+                                   <forkMode>always</forkMode>
+
                                    <testNGArtifactName>none:none</testNGArtifactName>
                                    <classpathDependencyExcludes>
                                        <classpathDependencyExclude>org.apache.myfaces.extensions.cdi.core:myfaces-extcdi-core-impl</classpathDependencyExclude>

Added: myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/PhaseListenerTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/PhaseListenerTest.java?rev=1022655&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/PhaseListenerTest.java (added)
+++ myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/PhaseListenerTest.java Thu Oct 14 19:00:29 2010
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.test.webapp.listener;
+
+import org.apache.myfaces.extensions.cdi.test.webapp.listener.bean.PhaseListenerBean;
+import org.apache.myfaces.extensions.cdi.test.webapp.listener.phase.AllPhaseListener;
+import org.apache.myfaces.extensions.cdi.test.webapp.listener.phase.ValidationPhaseListener;
+import org.apache.myfaces.test.webapp.api.annotation.BeansXml;
+import org.apache.myfaces.test.webapp.api.annotation.PageBean;
+import org.apache.myfaces.test.webapp.api.annotation.Tester;
+import org.apache.myfaces.test.webapp.api.annotation.View;
+import org.apache.myfaces.test.webapp.api.annotation.WebXml;
+import org.apache.myfaces.test.webapp.api.annotation.WebappDependency;
+import org.apache.myfaces.test.webapp.api.runner.WebappTestRunner;
+import org.apache.myfaces.test.webapp.api.tester.ServerSideCode;
+import org.apache.myfaces.test.webapp.api.tester.WebappTester;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseId;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+@View(id = "listener/phase-listener-test1.xhtml",
+      pageBeans = {
+              @PageBean(clazz = AllPhaseListener.class),
+              @PageBean(clazz = ValidationPhaseListener.class),
+              @PageBean(clazz = PhaseListenerBean.class)
+      }
+)
+
+@BeansXml
+
+@WebXml("web.xml")
+
+@WebappDependency.List
+({
+    @WebappDependency("org.apache.myfaces.extensions.cdi.core:myfaces-extcdi-core-api:jar:1.0.0-SNAPSHOT"),
+    @WebappDependency("org.apache.myfaces.extensions.cdi.core:myfaces-extcdi-core-impl:jar:1.0.0-SNAPSHOT"),
+    @WebappDependency("org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-jsf20-module-api:jar:1.0.0-SNAPSHOT"),
+    @WebappDependency("org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-jsf20-module-impl:jar:1.0.0-SNAPSHOT"),
+    @WebappDependency("org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-message-module-api:jar:1.0.0-SNAPSHOT"),
+    @WebappDependency("org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-message-module-impl:jar:1.0.0-SNAPSHOT"),
+    @WebappDependency("org.apache.openwebbeans:openwebbeans-impl:jar:1.0.0-alpha-2"),
+    @WebappDependency("org.apache.openwebbeans:openwebbeans-spi:jar:1.0.0-alpha-2"),
+    @WebappDependency("org.apache.openwebbeans:openwebbeans-jsf:jar:1.0.0-alpha-2"),
+    @WebappDependency("org.apache.openwebbeans:openwebbeans-resource:jar:1.0.0-alpha-2"),
+    @WebappDependency("org.apache.openwebbeans:openwebbeans-web:jar:1.0.0-alpha-2"),
+    @WebappDependency("javassist:javassist:jar:3.12.0.GA"),
+    @WebappDependency("net.sf.scannotation:scannotation:jar:1.0.2")
+})
+
+@RunWith(WebappTestRunner.class)
+
+/**
+ * Test cases for the CODI PhaseListener support.
+ *
+ * @author Jakob Korherr
+ */
+public class PhaseListenerTest
+{
+
+    @Tester
+    private static WebappTester tester;
+
+    @Test
+    public void jsfPhaseListener_AnyPhase_Called() throws Exception
+    {
+        // implicit initial request (including initial redirect)
+
+        // new request
+        tester.click("testForm:emptyCommand");
+
+        // new request - to do assertions
+        tester.click("testForm:emptyCommand");
+
+        // all phases must have been called
+        // NOTE that there are also assertions in AllPhaseListener
+        List<Boolean> assertList = Arrays.asList(true, true, true, true, true, true);
+
+        tester.assertThat(new ServerSideCode()
+        {
+
+            public Object execute() throws Exception
+            {
+                FacesContext facesContext = FacesContext.getCurrentInstance();
+                Map<String, Object> applicationMap = facesContext
+                        .getExternalContext().getApplicationMap();
+
+
+                return applicationMap.get(AllPhaseListener.BEFORE_CALLED);
+            }
+            
+        }).is(assertList).before(PhaseId.RESTORE_VIEW);
+
+        tester.assertThat(new ServerSideCode()
+        {
+
+            public Object execute() throws Exception
+            {
+                FacesContext facesContext = FacesContext.getCurrentInstance();
+                Map<String, Object> applicationMap = facesContext
+                        .getExternalContext().getApplicationMap();
+
+
+                return applicationMap.get(AllPhaseListener.AFTER_CALLED);
+            }
+
+        }).is(assertList).before(PhaseId.RESTORE_VIEW);
+    }
+
+    @Test
+    public void jsfPhaseListener_SpecificPhase_Called() throws Exception
+    {
+        // implicit initial request (including initial redirect)
+
+        // new request
+        tester.click("testForm:emptyCommand");
+
+        // new request - to do assertions
+        tester.click("testForm:emptyCommand");
+
+        // only phase PROCESS_VALIDATIONS must have been called
+        // NOTE that there are also assertions in ValidationPhaseListener
+        List<Boolean> assertList = Arrays.asList(false, false, true, false, false, false);
+
+        tester.assertThat(new ServerSideCode()
+        {
+
+            public Object execute() throws Exception
+            {
+                FacesContext facesContext = FacesContext.getCurrentInstance();
+                Map<String, Object> applicationMap = facesContext
+                        .getExternalContext().getApplicationMap();
+
+
+                return applicationMap.get(ValidationPhaseListener.BEFORE_CALLED);
+            }
+
+        }).is(assertList).before(PhaseId.RESTORE_VIEW);
+
+        tester.assertThat(new ServerSideCode()
+        {
+
+            public Object execute() throws Exception
+            {
+                FacesContext facesContext = FacesContext.getCurrentInstance();
+                Map<String, Object> applicationMap = facesContext
+                        .getExternalContext().getApplicationMap();
+
+
+                return applicationMap.get(ValidationPhaseListener.AFTER_CALLED);
+            }
+
+        }).is(assertList).before(PhaseId.RESTORE_VIEW);
+    }
+
+    @Test
+    public void observes_PhaseEvent_AnyPhase_Called() throws Exception
+    {
+        // implicit initial request (including initial redirect)
+
+        // new request
+        tester.click("testForm:emptyCommand");
+
+        // new request - to do assertions
+        tester.click("testForm:emptyCommand");
+
+        // all phases must have been called
+        // NOTE that there are also assertions in the PhaseListenerBean
+        List<Boolean> assertList = Arrays.asList(true, true, true, true, true, true);
+
+        tester.assertThat("#{phaseListenerBean.beforeAnyCalled}").is(assertList).before(PhaseId.RESTORE_VIEW);
+        tester.assertThat("#{phaseListenerBean.afterAnyCalled}").is(assertList).before(PhaseId.RESTORE_VIEW);
+    }
+
+    @Test
+    public void observes_PhaseEvent_SpecificPhase_Called() throws Exception
+    {
+        // implicit initial request (including initial redirect)
+
+        // new request
+        tester.click("testForm:emptyCommand");
+
+        // new request - to do assertions
+        tester.click("testForm:emptyCommand");
+
+        // only INVOKE_APPLICATION must have been called
+        // NOTE that there are also assertions in the PhaseListenerBean
+        List<Boolean> assertList = Arrays.asList(false, false, false, false, true, false);
+
+        tester.assertThat("#{phaseListenerBean.beforeInvokeApplicationCalled}").is(assertList).before(PhaseId.RESTORE_VIEW);
+        tester.assertThat("#{phaseListenerBean.afterInvokeApplicationCalled}").is(assertList).before(PhaseId.RESTORE_VIEW);
+    }
+
+}

Added: myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/bean/PhaseListenerBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/bean/PhaseListenerBean.java?rev=1022655&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/bean/PhaseListenerBean.java (added)
+++ myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/bean/PhaseListenerBean.java Thu Oct 14 19:00:29 2010
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.test.webapp.listener.bean;
+
+import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.AfterPhase;
+import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.BeforePhase;
+import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.JsfPhaseId;
+import org.junit.Assert;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.inject.Named;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Jakob Korherr
+ */
+@Named
+@ApplicationScoped
+public class PhaseListenerBean implements Serializable
+{
+
+    private List<Boolean> beforeAnyCalled;
+    private List<Boolean> afterAnyCalled;
+    private List<Boolean> beforeInvokeApplicationCalled;
+    private List<Boolean> afterInvokeApplicationCalled;
+
+    @PostConstruct
+    public void initialize()
+    {
+        beforeAnyCalled = new ArrayList<Boolean>(6);
+        afterAnyCalled = new ArrayList<Boolean>(6);
+        beforeInvokeApplicationCalled = new ArrayList<Boolean>(6);
+        afterInvokeApplicationCalled = new ArrayList<Boolean>(6);
+
+        for (int i = 0; i < 6; i++)
+        {
+            beforeAnyCalled.add(false);
+            afterAnyCalled.add(false);
+            beforeInvokeApplicationCalled.add(false);
+            afterInvokeApplicationCalled.add(false);
+        }
+    }
+
+    public void beforeAnyPhase(@Observes @BeforePhase(JsfPhaseId.ANY_PHASE) PhaseEvent event)
+    {
+        doAssertions(event);
+
+        beforeAnyCalled.set(event.getPhaseId().getOrdinal() - 1, true);
+    }
+
+    public void afterAnyPhase(@Observes @AfterPhase(JsfPhaseId.ANY_PHASE) PhaseEvent event)
+    {
+        doAssertions(event);
+
+        afterAnyCalled.set(event.getPhaseId().getOrdinal() - 1, true);
+    }
+
+    public void beforeInvokeApplicationPhase(@Observes @BeforePhase(JsfPhaseId.INVOKE_APPLICATION) PhaseEvent event)
+    {
+        doAssertions(event);
+
+        beforeInvokeApplicationCalled.set(event.getPhaseId().getOrdinal() - 1, true);
+    }
+
+    public void afterInvokeApplicationPhase(@Observes @AfterPhase(JsfPhaseId.INVOKE_APPLICATION) PhaseEvent event)
+    {
+        doAssertions(event);
+
+        afterInvokeApplicationCalled.set(event.getPhaseId().getOrdinal() - 1, true);
+    }
+
+    private void doAssertions(PhaseEvent event)
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        PhaseId fcPhaseId = facesContext.getCurrentPhaseId();
+        PhaseId eventPhaseId = event.getPhaseId();
+
+        // PhaseIds must match
+        Assert.assertEquals(fcPhaseId, eventPhaseId);
+    }
+
+    public List<Boolean> getBeforeAnyCalled()
+    {
+        return beforeAnyCalled;
+    }
+
+    public List<Boolean> getAfterAnyCalled()
+    {
+        return afterAnyCalled;
+    }
+
+    public List<Boolean> getBeforeInvokeApplicationCalled()
+    {
+        return beforeInvokeApplicationCalled;
+    }
+
+    public List<Boolean> getAfterInvokeApplicationCalled()
+    {
+        return afterInvokeApplicationCalled;
+    }
+}

Added: myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/AllPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/AllPhaseListener.java?rev=1022655&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/AllPhaseListener.java (added)
+++ myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/AllPhaseListener.java Thu Oct 14 19:00:29 2010
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.test.webapp.listener.phase;
+
+import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.JsfPhaseListener;
+import org.junit.Assert;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Jakob Korherr
+ */
+@JsfPhaseListener
+public class AllPhaseListener implements PhaseListener
+{
+
+    public static final String BEFORE_CALLED = "AllPhaseListener.BEFORE_CALLED";
+    public static final String AFTER_CALLED = "AllPhaseListener.AFTER_CALLED";
+
+    private List<Boolean> beforeCalled;
+    private List<Boolean> afterCalled;
+    private boolean initialized = false;
+
+    public AllPhaseListener()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        Assert.assertNotNull("FacesContext must be accessible at instantiation time", facesContext);
+    }
+
+    public void beforePhase(PhaseEvent event)
+    {
+        lazyinit();
+
+        doAssertions(event);
+
+        beforeCalled.set(event.getPhaseId().getOrdinal() - 1, true);
+    }
+
+    public void afterPhase(PhaseEvent event)
+    {
+        doAssertions(event);
+
+        afterCalled.set(event.getPhaseId().getOrdinal() - 1, true);
+    }
+
+    public PhaseId getPhaseId()
+    {
+        return PhaseId.ANY_PHASE;
+    }
+
+    private void lazyinit()
+    {
+        if (!initialized)
+        {
+            beforeCalled = new ArrayList<Boolean>(6);
+            afterCalled = new ArrayList<Boolean>(6);
+
+            for (int i = 0; i < 6; i++)
+            {
+                beforeCalled.add(false);
+                afterCalled.add(false);
+            }
+
+            // put on ApplicationMap
+            FacesContext facesContext = FacesContext.getCurrentInstance();
+            Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap();
+            applicationMap.put(BEFORE_CALLED, beforeCalled);
+            applicationMap.put(AFTER_CALLED, afterCalled);
+
+            initialized = true;
+        }
+    }
+
+    private void doAssertions(PhaseEvent event)
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        PhaseId fcPhaseId = facesContext.getCurrentPhaseId();
+        PhaseId eventPhaseId = event.getPhaseId();
+
+        // PhaseIds must match
+        Assert.assertEquals(fcPhaseId, eventPhaseId);
+    }
+
+}

Added: myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/ValidationPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/ValidationPhaseListener.java?rev=1022655&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/ValidationPhaseListener.java (added)
+++ myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/java/org/apache/myfaces/extensions/cdi/test/webapp/listener/phase/ValidationPhaseListener.java Thu Oct 14 19:00:29 2010
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.cdi.test.webapp.listener.phase;
+
+import org.apache.myfaces.extensions.cdi.jsf.api.listener.phase.JsfPhaseListener;
+import org.junit.Assert;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Jakob Korherr
+ */
+@JsfPhaseListener
+public class ValidationPhaseListener implements PhaseListener
+{
+
+    public static final String BEFORE_CALLED = "ValidationPhaseListener.BEFORE_CALLED";
+    public static final String AFTER_CALLED = "ValidationPhaseListener.AFTER_CALLED";
+
+    private List<Boolean> beforeCalled;
+    private List<Boolean> afterCalled;
+    private boolean initialized = false;
+
+    public ValidationPhaseListener()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        Assert.assertNotNull("FacesContext must be accessible at instantiation time", facesContext);
+    }
+
+    public void beforePhase(PhaseEvent event)
+    {
+        lazyinit();
+
+        doAssertions(event);
+
+        beforeCalled.set(event.getPhaseId().getOrdinal() - 1, true);
+    }
+
+    public void afterPhase(PhaseEvent event)
+    {
+        doAssertions(event);
+
+        afterCalled.set(event.getPhaseId().getOrdinal() - 1, true);
+    }
+
+    public PhaseId getPhaseId()
+    {
+        return PhaseId.PROCESS_VALIDATIONS;
+    }
+
+    private void lazyinit()
+    {
+        if (!initialized)
+        {
+            beforeCalled = new ArrayList<Boolean>(6);
+            afterCalled = new ArrayList<Boolean>(6);
+
+            for (int i = 0; i < 6; i++)
+            {
+                beforeCalled.add(false);
+                afterCalled.add(false);
+            }
+
+            // put on ApplicationMap
+            FacesContext facesContext = FacesContext.getCurrentInstance();
+            Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap();
+            applicationMap.put(BEFORE_CALLED, beforeCalled);
+            applicationMap.put(AFTER_CALLED, afterCalled);
+
+            initialized = true;
+        }
+    }
+
+    private void doAssertions(PhaseEvent event)
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        PhaseId fcPhaseId = facesContext.getCurrentPhaseId();
+        PhaseId eventPhaseId = event.getPhaseId();
+
+        // PhaseIds must match
+        Assert.assertEquals(fcPhaseId, eventPhaseId);
+    }
+
+}

Copied: myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/resources/listener/phase-listener-test1.xhtml (from r1021829, myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/resources/events/access-bean-event-test1.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/resources/listener/phase-listener-test1.xhtml?p2=myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/resources/listener/phase-listener-test1.xhtml&p1=myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/resources/events/access-bean-event-test1.xhtml&r1=1021829&r2=1022655&rev=1022655&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/resources/events/access-bean-event-test1.xhtml (original)
+++ myfaces/extensions/cdi/trunk/test-modules/webapp-test-module/src/test/resources/listener/phase-listener-test1.xhtml Thu Oct 14 19:00:29 2010
@@ -22,7 +22,7 @@
       xmlns:f="http://java.sun.com/jsf/core">
 
 <h:head>
-    <title>MyFaces CODI BeanAccessEvent Test - Start page</title>
+    <title>MyFaces CODI PhaseListener Test</title>
 </h:head>
 <h:body>
     <h:form id="testForm">