openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [openwebbeans] branch master updated: OWB-1302 ensure produceWith works in bean configurator - ensure it can get enclosing InjectionPoint
Date Mon, 18 Nov 2019 16:10:00 GMT
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 5995e86  OWB-1302 ensure produceWith works in bean configurator - ensure it can get
enclosing InjectionPoint
5995e86 is described below

commit 5995e86e0a1f831d61539a62d04a1614b097e77f
Author: Romain Manni-Bucau <rmannibucau@gmail.com>
AuthorDate: Mon Nov 18 17:09:55 2019 +0100

    OWB-1302 ensure produceWith works in bean configurator - ensure it can get enclosing InjectionPoint
---
 .../webbeans/portable/InjectionPointProducer.java  |  4 ++-
 .../test/portable/events/PortableAddBeanTest.java  | 33 ++++++++++++++++++++--
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
b/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
index 9f1866f..633375c 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
@@ -35,6 +35,7 @@ import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.Interceptor;
 
+import org.apache.webbeans.component.InjectionPointBean;
 import org.apache.webbeans.component.third.ThirdpartyBeanImpl;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.util.ClassUtil;
@@ -60,7 +61,8 @@ public class InjectionPointProducer extends AbstractProducer<InjectionPoint>
         InjectionPoint injectionPoint;
         if (!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(first.getType())))
         {
-            if (!ThirdpartyBeanImpl.class.isInstance(creationalContextImpl.getBean()))
+            if (!ThirdpartyBeanImpl.class.isInstance(creationalContextImpl.getBean()) &&
+                !InjectionPointBean.class.isInstance(creationalContextImpl.getBean()))
             {
                 throw new IllegalStateException("Inconsistent injection point stack");
             }
diff --git a/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/events/PortableAddBeanTest.java
b/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/events/PortableAddBeanTest.java
index ba70b67..75b0d77 100644
--- a/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/events/PortableAddBeanTest.java
+++ b/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/events/PortableAddBeanTest.java
@@ -19,7 +19,9 @@
 package org.apache.webbeans.test.portable.events;
 
 import static java.util.Collections.emptyList;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 
 import java.util.ArrayList;
@@ -28,7 +30,11 @@ import java.util.Collection;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
 
 import org.junit.Assert;
 
@@ -62,20 +68,41 @@ public class PortableAddBeanTest extends AbstractUnitTest
         final MyBean myBean = new MyBean();
         addExtension(new Extension()
         {
-            public void addBean(@Observes AfterBeanDiscovery event)
+            void addType(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
+            {
+                beforeBeanDiscovery.addAnnotatedType(Injected.class, Injected.class.getName());
+            }
+
+            void addBean(@Observes AfterBeanDiscovery event)
             {
                 event.addBean()
                         .scope(Dependent.class)
                         .addTypes(MyBean.class, Object.class)
                         .beanClass(MyBean.class)
-                        .produceWith(i -> myBean);
+                        .produceWith(i -> {
+                            assertNull(myBean.ip);
+                            myBean.ip = i.select(InjectionPoint.class).get();
+                            return myBean;
+                        });
             }
         });
         startContainer(emptyList(), emptyList());
-        assertSame(myBean, getInstance(MyBean.class));
+
+        final Injected instance = getInstance(Injected.class);
+        assertSame(myBean, instance.bean);
+        assertNotNull(instance.bean.ip);
+        assertEquals(MyBean.class, instance.bean.ip.getType());
+        assertEquals("bean", instance.bean.ip.getMember().getName());
+    }
+
+    public static class Injected
+    {
+        @Inject
+        private MyBean bean;
     }
 
     public static class MyBean
     {
+        private InjectionPoint ip;
     }
 }


Mime
View raw message