openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1183022 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/newtests/managed/instance/ test/java/org/apache/webbeans/newtests/managed/newcomp/ ...
Date Thu, 13 Oct 2011 18:39:14 GMT
Author: struberg
Date: Thu Oct 13 18:39:14 2011
New Revision: 1183022

URL: http://svn.apache.org/viewvc?rev=1183022&view=rev
Log:
OWB-619 only create @New beans for existing injection points

According to the spec we must not create 1 NewBean for each bean,
but only if they get used in an injection point.


Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/
      - copied from r1182358, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/newcomp/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponentTest.java
  (contents, props changed)
      - copied, changed from r1182358, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/newcomp/NewComponentTest.java
Removed:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/newcomp/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/newcomp/NewComponentTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponent.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/ProducerNewComponent.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/producer/Producer1ConsumerComponentTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/producer/ProducerComponentTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/scopes/ScopeAdapterTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1183022&r1=1183021&r2=1183022&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
Thu Oct 13 18:39:14 2011
@@ -166,7 +166,7 @@ public class BeansDeployer
                 
                 //Deploy additional Annotated Types
                 deployAdditionalAnnotatedTypes();
-                
+
                 //Check Specialization
                 checkSpecializations(scanner);
                 
@@ -194,8 +194,7 @@ public class BeansDeployer
             WebBeansUtil.throwRuntimeExceptions(e);
         }
     }
-    
-    
+
 
     /**
      * Configure Default Beans.
@@ -521,7 +520,7 @@ public class BeansDeployer
             deploySingleAnnotatedType(implClass, type);                           
         }
     }
-    
+
     /**
      * Common helper method used to deploy annotated types discovered through
      * scanning or during beforeBeanDiscovery.

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1183022&r1=1183021&r2=1183022&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Thu Oct 13 18:39:14 2011
@@ -645,58 +645,6 @@ public final class WebBeansUtil
 
 
     /**
-     * Returns a new managed bean from given bean.
-     *
-     * @param <T> bean type parameter
-     * @param bean bean instance
-     * @return the new bean from given managed bean
-     */
-    public static <T> NewManagedBean<T> createNewBean(AbstractInjectionTargetBean<T>
bean)
-    {
-        Asserts.assertNotNull(bean, "bean argument can not be null");
-
-        NewManagedBean<T> comp = null;
-
-        comp = new NewManagedBean<T>(bean.getReturnType(), WebBeansType.NEW, bean.getWebBeansContext());
-
-        comp.getTypes().addAll(bean.getTypes());
-
-        if(bean instanceof ManagedBean)
-        {
-            comp.setConstructor(((ManagedBean)bean).getConstructor());
-        }
-
-        for(Field injectedField : bean.getInjectedFields())
-        {
-            comp.addInjectedField(injectedField);
-        }
-
-        for(Method injectedMethod : bean.getInjectedMethods())
-        {
-            comp.addInjectedMethod(injectedMethod);
-        }
-
-        List<InterceptorData> interceptorList = bean.getInterceptorStack();
-        if(!interceptorList.isEmpty())
-        {
-            comp.getInterceptorStack().addAll(interceptorList);
-        }
-
-
-        comp.setImplScopeType(new DependentScopeLiteral());
-        comp.addQualifier(new NewLiteral(bean.getBeanClass()));
-        comp.setName(null);
-
-        Set<InjectionPoint> injectionPoints = bean.getInjectionPoints();
-        for(InjectionPoint injectionPoint : injectionPoints)
-        {
-            comp.addInjectionPoint(injectionPoint);
-        }
-
-        return comp;
-    }
-
-    /**
      * Creates a new manager bean instance.
      * @return new manager bean instance
      */
@@ -2732,7 +2680,6 @@ public final class WebBeansUtil
 
             if(!isAnnotatedTypeDecoratorOrInterceptor(annotatedType))
             {
-                beanManager.addBean(WebBeansUtil.createNewBean(managedBean));
                 beanManager.addBean(managedBean);
                 for (ProducerMethodBean<?> producerMethod : producerMethods)
                 {
@@ -2761,7 +2708,6 @@ public final class WebBeansUtil
                     "managed beans. Look at logs for further details");
             if(!isAnnotatedTypeDecoratorOrInterceptor(annotatedType))
             {
-                beanManager.addBean(WebBeansUtil.createNewBean(managedBean));
                 beanManager.addBean(managedBean);
             }
         }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java?rev=1183022&r1=1183021&r2=1183022&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
Thu Oct 13 18:39:14 2011
@@ -38,7 +38,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Set;
 
-public class InjectedInstanceComponentTest extends AbstractUnitTest {
+public class InjectedInstanceComponentTest extends AbstractUnitTest
+{
 
         @Test
     public void testInstanceInjectedComponent()
@@ -73,7 +74,8 @@ public class InjectedInstanceComponentTe
 
     @Ignore
     @Test
-    public void testManualInstanceBeanResolving() {
+    public void testManualInstanceBeanResolving()
+    {
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
 
         startContainer(beanClasses, null);

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponent.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponent.java?rev=1183022&r1=1182358&r2=1183022&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponent.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponent.java
Thu Oct 13 18:39:14 2011
@@ -16,19 +16,28 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.test.component.newcomp;
+package org.apache.webbeans.newtests.managed.newcomp;
 
+import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.New;
 import javax.inject.Inject;
 
 import org.apache.webbeans.test.component.dependent.DependentOwnerComponent;
 
+@Dependent
 public class NewComponent
 {
-    @Inject @New DependentOwnerComponent owner;
+    private @Inject @New DependentOwnerComponent owner;
+
+    private @Inject @New(DependentOwnerComponent.class) DependentOwnerComponent grandParent;
 
     public DependentOwnerComponent owner()
     {
         return owner;
     }
+
+    public DependentOwnerComponent getGrandParent()
+    {
+        return grandParent;
+    }
 }

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponentTest.java
(from r1182358, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/newcomp/NewComponentTest.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponentTest.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponentTest.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/newcomp/NewComponentTest.java&r1=1182358&r2=1183022&rev=1183022&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/newcomp/NewComponentTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponentTest.java
Thu Oct 13 18:39:14 2011
@@ -16,79 +16,59 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.test.unittests.newcomp;
+package org.apache.webbeans.newtests.managed.newcomp;
 
-import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
 
-import junit.framework.Assert;
 
-import org.apache.webbeans.component.AbstractOwbBean;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.ContextFactory;
-import org.apache.webbeans.test.TestContext;
+import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.test.component.CheckWithCheckPayment;
 import org.apache.webbeans.test.component.IPayment;
 import org.apache.webbeans.test.component.dependent.DependentComponent;
 import org.apache.webbeans.test.component.dependent.DependentOwnerComponent;
-import org.apache.webbeans.test.component.newcomp.NewComponent;
-import org.apache.webbeans.test.component.newcomp.ProducerNewComponent;
-import org.junit.Before;
 import org.junit.Test;
+import org.junit.Assert;
 
-public class NewComponentTest extends TestContext
-{
-    public NewComponentTest()
-    {
-        super(NewComponentTest.class.getName());
-    }
-
-    @Before
-    public void init()
-    {
-        super.init();
-
-    }
 
+public class NewComponentTest extends AbstractUnitTest
+{
     @Test
     public void testDependent()
     {
-        clear();
-
-        defineManagedBean(DependentComponent.class);
-        defineManagedBean(DependentOwnerComponent.class);
-        defineManagedBean(NewComponent.class);
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(DependentComponent.class);
+        beanClasses.add(DependentOwnerComponent.class);
+        beanClasses.add(NewComponent.class);
 
-        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
-        contextFactory.initRequestContext(null);
+        startContainer(beanClasses, null);
 
-        List<AbstractOwbBean<?>> comps = getComponents();
+        NewComponent newComponent = getInstance(NewComponent.class);
+        Assert.assertNotNull(newComponent);
 
-        Assert.assertEquals(3, comps.size());
+        Assert.assertNotNull(newComponent.owner());
+        Assert.assertNotNull(newComponent.getGrandParent());
+        Assert.assertNotSame(newComponent.owner(), newComponent.getGrandParent());
 
-        NewComponent comp = (NewComponent) getManager().getInstance(comps.get(2));
 
-        DependentOwnerComponent own = comp.owner();
-
-        Assert.assertNotNull(own);
-
-        contextFactory.destroyRequestContext(null);
+        shutDownContainer();
     }
 
     @Test
     public void testDepedent2()
     {
-        clear();
-        defineManagedBean(CheckWithCheckPayment.class);
-        defineManagedBean(ProducerNewComponent.class);
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(CheckWithCheckPayment.class);
+        beanClasses.add(IPayment.class);
+        beanClasses.add(ProducerNewComponent.class);
+        beanClasses.add(NewComponent.class);
 
-        WebBeansContext.getInstance().getContextFactory().initRequestContext(null);
-        Assert.assertEquals(5, getDeployedComponents());
+        startContainer(beanClasses, null);
 
-        IPayment payment = (IPayment) getManager().getInstanceByName("paymentProducer");
+        IPayment payment = getInstance(IPayment.class);
         Assert.assertNotNull(payment);
+        Assert.assertTrue(payment instanceof CheckWithCheckPayment);
 
-        IPayment payment2 = (IPayment) getManager().getInstanceByName("paymentProducer");
-
-        Assert.assertNotSame(payment, payment2);
+        shutDownContainer();
     }
 }

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/NewComponentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/ProducerNewComponent.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/ProducerNewComponent.java?rev=1183022&r1=1182358&r2=1183022&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/ProducerNewComponent.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/newcomp/ProducerNewComponent.java
Thu Oct 13 18:39:14 2011
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.test.component.newcomp;
+package org.apache.webbeans.newtests.managed.newcomp;
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.RequestScoped;

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java?rev=1183022&r1=1183021&r2=1183022&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
Thu Oct 13 18:39:14 2011
@@ -298,13 +298,12 @@ public abstract class TestContext implem
      */
     protected <T> AbstractInjectionTargetBean<T> defineManagedBean(Class<T>
clazz)
     {
-        ManagedBean<T> bean = null;
+        ManagedBean<T> bean;
 
         WebBeansContext webBeansContext = WebBeansContext.getInstance();
         bean = webBeansContext.getManagedBeanConfigurator().define(clazz, WebBeansType.MANAGED);
         if (bean != null)
         {
-            manager.addBean(WebBeansUtil.createNewBean(bean));
             DecoratorUtil.checkManagedBeanDecoratorConditions(bean,null);
             WebBeansDecoratorConfig.configureDecorators(bean);
             webBeansContext.getDefinitionUtil().defineBeanInterceptorStack(bean);

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/producer/Producer1ConsumerComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/producer/Producer1ConsumerComponentTest.java?rev=1183022&r1=1183021&r2=1183022&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/producer/Producer1ConsumerComponentTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/producer/Producer1ConsumerComponentTest.java
Thu Oct 13 18:39:14 2011
@@ -66,7 +66,7 @@ public class Producer1ConsumerComponentT
         contextFactory.initRequestContext(null);
         contextFactory.initApplicationContext(null);
 
-        Assert.assertEquals(7, getDeployedComponents());
+        Assert.assertEquals(4, getDeployedComponents());
 
         Object obj = getManager().getInstance(comps.get(0));
         

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/producer/ProducerComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/producer/ProducerComponentTest.java?rev=1183022&r1=1183021&r2=1183022&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/producer/ProducerComponentTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/producer/ProducerComponentTest.java
Thu Oct 13 18:39:14 2011
@@ -67,7 +67,7 @@ public class ProducerComponentTest exten
     {
         clear();
         defineManagedBean(Producer1.class);
-        Assert.assertEquals(3, getDeployedComponents());
+        Assert.assertEquals(2, getDeployedComponents());
 
     }
 
@@ -76,7 +76,7 @@ public class ProducerComponentTest exten
     {
         clear();
         defineManagedBean(Producer2.class);
-        Assert.assertEquals(4, getDeployedComponents());
+        Assert.assertEquals(3, getDeployedComponents());
     }
 
     @Test
@@ -85,7 +85,7 @@ public class ProducerComponentTest exten
         clear();
         defineManagedBean(Producer3.class);
 
-        Assert.assertEquals(6, getDeployedComponents());
+        Assert.assertEquals(5, getDeployedComponents());
     }
 
     @Test
@@ -95,7 +95,7 @@ public class ProducerComponentTest exten
         defineManagedBean(ParametrizedProducer.class);
 
         WebBeansContext.getInstance().getContextFactory().initRequestContext(null);
-        Assert.assertEquals(4, getDeployedComponents());
+        Assert.assertEquals(3, getDeployedComponents());
 
         TypeLiteral<List<ParametrizedModel1>> model1 = new TypeLiteral<List<ParametrizedModel1>>()
         {

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/scopes/ScopeAdapterTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/scopes/ScopeAdapterTest.java?rev=1183022&r1=1183021&r2=1183022&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/scopes/ScopeAdapterTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/scopes/ScopeAdapterTest.java
Thu Oct 13 18:39:14 2011
@@ -63,7 +63,7 @@ public class ScopeAdapterTest extends Te
 
         List<AbstractOwbBean<?>> comps = getComponents();
 
-        Assert.assertEquals(7, getDeployedComponents());
+        Assert.assertEquals(4, getDeployedComponents());
 
         getManager().getInstance(comps.get(0));
         getManager().getInstance(comps.get(1));



Mime
View raw message