Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x 521ea067a -> c3a20e7a5


ensuring all container event are not propagated upper the when sent for a 
webapp of an ear


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/c3a20e7a
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/c3a20e7a
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/c3a20e7a

Branch: refs/heads/tomee-1.7.x
Commit: c3a20e7a59d6a6f9532389ea7e15491d364ec8b3
Parents: 521ea06
Author: Romain Manni-Bucau <[email protected]>
Authored: Wed Feb 11 15:22:40 2015 +0100
Committer: Romain Manni-Bucau <[email protected]>
Committed: Wed Feb 11 15:22:59 2015 +0100

----------------------------------------------------------------------
 .../apache/openejb/cdi/WebappBeanManager.java   | 23 +++--
 .../openejb/cdi/WebappBeanManagerTest.java      | 90 ++++++++++++++++++++
 2 files changed, 108 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/c3a20e7a/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
index 3cadc8b..444a3f2 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
@@ -23,6 +23,10 @@ import org.apache.webbeans.component.ExtensionBean;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.event.EventMetadata;
+import org.apache.webbeans.portable.events.discovery.AfterBeanDiscoveryImpl;
+import 
org.apache.webbeans.portable.events.discovery.AfterDeploymentValidationImpl;
+import org.apache.webbeans.portable.events.discovery.BeforeBeanDiscoveryImpl;
+import org.apache.webbeans.portable.events.discovery.BeforeShutdownImpl;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
@@ -31,8 +35,12 @@ import javax.el.ExpressionFactory;
 import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AfterDeploymentValidation;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.BeforeShutdown;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
 import javax.enterprise.inject.spi.ObserverMethod;
@@ -251,10 +259,10 @@ public class WebappBeanManager extends BeanManagerImpl {
             // so reuse parent beans
             // this can happen for validations
             return new IteratorSet<Bean<?>>(
-                new MultipleIterator<Bean<?>>(
-                    InheritedBeanFilter.INSTANCE,
-                    deploymentBeans.iterator(),
-                    getParentBm().getComponents().iterator()));
+                    new MultipleIterator<Bean<?>>(
+                            InheritedBeanFilter.INSTANCE,
+                            deploymentBeans.iterator(),
+                            getParentBm().getComponents().iterator()));
         }
         return deploymentBeans;
     }
@@ -295,7 +303,12 @@ public class WebappBeanManager extends BeanManagerImpl {
     }
 
     private static boolean isEvent(final Class<?> eventClass) {
-        return !WebBeansUtil.isDefaultExtensionBeanEventType(eventClass) && 
!WebBeansUtil.isExtensionEventType(eventClass);
+        return !WebBeansUtil.isDefaultExtensionBeanEventType(eventClass) && 
!WebBeansUtil.isExtensionEventType(eventClass)
+                && !(
+                eventClass.equals(BeforeBeanDiscoveryImpl.class) ||
+                eventClass.equals(AfterBeanDiscoveryImpl.class) ||
+                eventClass.equals(AfterDeploymentValidationImpl.class) ||
+                eventClass.equals(BeforeShutdownImpl.class));
     }
 
     private interface Filter<A> {

http://git-wip-us.apache.org/repos/asf/tomee/blob/c3a20e7a/container/openejb-core/src/test/java/org/apache/openejb/cdi/WebappBeanManagerTest.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/cdi/WebappBeanManagerTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/cdi/WebappBeanManagerTest.java
new file mode 100644
index 0000000..c7edb01
--- /dev/null
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/cdi/WebappBeanManagerTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.openejb.cdi;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.portable.events.discovery.AfterBeanDiscoveryImpl;
+import 
org.apache.webbeans.portable.events.discovery.AfterDeploymentValidationImpl;
+import org.apache.webbeans.portable.events.discovery.BeforeBeanDiscoveryImpl;
+import org.apache.webbeans.portable.events.discovery.BeforeShutdownImpl;
+import org.apache.webbeans.portable.events.generics.GProcessAnnotatedType;
+import org.apache.webbeans.portable.events.generics.GProcessBean;
+import org.apache.webbeans.portable.events.generics.GProcessInjectionTarget;
+import org.apache.webbeans.portable.events.generics.GProcessProducer;
+import org.apache.webbeans.portable.events.generics.GProcessProducerField;
+import org.apache.webbeans.portable.events.generics.GProcessProducerMethod;
+import org.apache.webbeans.portable.events.generics.GProcessSessionBean;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.junit.Assert.fail;
+
+public class WebappBeanManagerTest {
+    @Test
+    public void containerEventsShouldntGoUp() {
+        final WebappWebBeansContext ctx = new 
WebappWebBeansContext(Collections.<Class<?>, Object>emptyMap(), new 
Properties(), new WebBeansContext());
+        final WebappBeanManager wbm = new WebappBeanManager(ctx) {
+            @Override
+            public BeanManagerImpl getParentBm() {
+                throw new IllegalStateException("shouldn't be called");
+            }
+        };
+        wbm.fireEvent(new GProcessProducer(null, null));
+        wbm.fireEvent(new GProcessProducerField(null, null, null));
+        wbm.fireEvent(new GProcessProducerMethod(null, null, null));
+        wbm.fireEvent(new GProcessInjectionTarget(null, null));
+        wbm.fireEvent(new GProcessBean(null, null));
+        wbm.fireEvent(new GProcessAnnotatedType(null));
+        wbm.fireEvent(new GProcessSessionBean(null, null, null, null));
+        wbm.fireEvent(new AfterBeanDiscoveryImpl(ctx));
+        wbm.fireEvent(new AfterDeploymentValidationImpl(wbm));
+        wbm.fireEvent(new BeforeBeanDiscoveryImpl(ctx));
+        wbm.fireEvent(new BeforeShutdownImpl());
+    }
+
+    @Test
+    public void otherEventsShouldGoUp() {
+        final WebappWebBeansContext ctx = new 
WebappWebBeansContext(Collections.<Class<?>, Object>emptyMap(), new 
Properties(), new WebBeansContext());
+        final WebappBeanManager wbm = new WebappBeanManager(ctx) {
+            @Override
+            public BeanManagerImpl getParentBm() {
+                throw new IllegalStateException("shouldn't be called");
+            }
+        };
+        try {
+            wbm.fireEvent(new Object());
+            fail();
+        } catch (final IllegalStateException ise) {
+            // ok
+        }
+        try {
+            wbm.fireEvent("yeah");
+            fail();
+        } catch (final IllegalStateException ise) {
+            // ok
+        }
+        try {
+            wbm.fireEvent(this);
+            fail();
+        } catch (final IllegalStateException ise) {
+            // ok
+        }
+    }
+}

Reply via email to