You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2013/11/07 12:05:30 UTC

svn commit: r1539593 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/container/ test/java/org/apache/webbeans/newtests/managed/specialized/

Author: rmannibucau
Date: Thu Nov  7 11:05:29 2013
New Revision: 1539593

URL: http://svn.apache.org/r1539593
Log:
OWB-912 Instance filtering is too restrictive

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/SpecializeDeactivationTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=1539593&r1=1539592&r2=1539593&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java Thu Nov  7 11:05:29 2013
@@ -530,11 +530,14 @@ public class InjectionResolver
         resolvedComponents = findByQualifier(resolvedComponents, injectionPointType, qualifiers);
 
         // Ambigious resolution, check for specialization
+        /*
+        // super beans are deactivated so it is useless
         if (resolvedComponents.size() > 1)
         {
             //Look for specialization
             resolvedComponents = findBySpecialization(resolvedComponents);
         }
+        */
 
         resolvedBeansByType.put(cacheKey, resolvedComponents);
         if (logger.isLoggable(Level.FINE))
@@ -690,7 +693,11 @@ public class InjectionResolver
 
         if(set.size() > 1)
         {
-            throwAmbiguousResolutionException(set);
+            set = findBySpecialization(set);
+            if(set.size() > 1)
+            {
+                throwAmbiguousResolutionException(set);
+            }
         }
 
         return (Bean<? extends X>)set.iterator().next();
@@ -716,10 +723,13 @@ public class InjectionResolver
             return Collections.emptySet();
         }
 
+        /*
+        // specialized bean are disabled so no need to refilter
         if(set.size() > 1)
         {
             set = findBySpecialization(set);
         }
+        */
 
         return set;
     }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/SpecializeDeactivationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/SpecializeDeactivationTest.java?rev=1539593&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/SpecializeDeactivationTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/SpecializeDeactivationTest.java Thu Nov  7 11:05:29 2013
@@ -0,0 +1,167 @@
+/*
+ * 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.webbeans.newtests.managed.specialized;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.Specializes;
+import javax.inject.Inject;
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class SpecializeDeactivationTest extends AbstractUnitTest
+{
+    @Inject
+    private Init init;
+
+    @Before
+    public void reset() {
+        Impl1.called = false;
+        Impl2.called = false;
+        SpeImpl1.called = false;
+    }
+
+    @Test
+    public void normal()
+    {
+        startContainer(Arrays.<Class<?>>asList(Init.class, API.class, Impl1.class, Impl2.class),
+            Collections.<String>emptyList(), true);
+
+        assertEquals(2, init.init());
+        assertTrue(Impl1.called);
+        assertTrue(Impl2.called);
+    }
+
+    @Test
+    public void specialize()
+    {
+        startContainer(Arrays.<Class<?>>asList(Init.class, API.class, Impl1.class, Impl2.class, SpeImpl1.class),
+            Collections.<String>emptyList(), true);
+
+        assertEquals(2, init.init());
+        assertTrue(SpeImpl1.called);
+        assertTrue(Impl2.called);
+    }
+
+    @Test
+    public void specializeProducers()
+    {
+        startContainer(Arrays.<Class<?>>asList(Init.class, API.class, Prod1.class, Prod2.class, Spe1.class),
+            Collections.<String>emptyList(), true);
+
+        assertEquals(2, init.init());
+        assertTrue(SpeImpl1.called);
+        assertTrue(Impl2.called);
+    }
+
+    public static interface API
+    {
+        void init();
+    }
+
+    public static class Prod1
+    {
+        @Produces
+        public API api1()
+        {
+            return new Impl1();
+        }
+    }
+
+    public static class Spe1 extends Prod1
+    {
+        @Produces
+        @Override
+        @Specializes
+        public API api1()
+        {
+            return new SpeImpl1();
+        }
+    }
+
+    public static class Prod2
+    {
+        @Produces
+        public API api1()
+        {
+            return new Impl2();
+        }
+    }
+
+    public static class Impl1 implements API
+    {
+        public static boolean called = false;
+
+        @Override
+        public void init()
+        {
+            called = true;
+        }
+    }
+
+    @Specializes
+    public static class SpeImpl1 extends Impl1
+    {
+        public static boolean called = false;
+
+        @Override
+        public void init()
+        {
+            called = true;
+        }
+    }
+
+    public static class Impl2 implements API
+    {
+        public static boolean called = false;
+
+        @Override
+        public void init()
+        {
+            called = true;
+        }
+    }
+
+    public static class Init
+    {
+        @Inject
+        @Any
+        private Instance<API> impls;
+
+        public int init()
+        {
+            int i = 0;
+            for (final API api : impls)
+            {
+                api.init();
+                i++;
+            }
+            return i;
+        }
+    }
+}