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

svn commit: r1481392 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/inject/ test/java/org/apache/webbeans/newtests/injection/serialization/ test/java/org/apache/webbeans/newtests/injection/serialization/beans/

Author: arne
Date: Sat May 11 18:55:04 2013
New Revision: 1481392

URL: http://svn.apache.org/r1481392
Log:
OWB-344: Fixed handling of injection of non-passivation-capable @Dependent produced beans into passivation-capable @Dependent beans

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/ProducerWithNonSerializableResultBean.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/SerializableDependentInjectionTarget.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=1481392&r1=1481391&r2=1481392&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java Sat May 11 18:55:04 2013
@@ -30,7 +30,6 @@ import javax.enterprise.inject.spi.Injec
 import javax.enterprise.inject.spi.Producer;
 
 import org.apache.webbeans.component.AbstractProducerBean;
-import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectionResolver;
@@ -84,7 +83,7 @@ public abstract class AbstractInjectable
             {
                 if(injectedBean instanceof AbstractProducerBean)
                 {
-                    if((creationalContext.getBean() instanceof OwbBean) && ((OwbBean<?>) creationalContext.getBean()).isPassivationCapable())
+                    if((creationalContext.getBean() instanceof Bean) && beanManager.isPassivatingScope(((Bean<?>) creationalContext.getBean()).getScope()))
                     {
                         dependentProducer = true;   
                     }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java?rev=1481392&r1=1481391&r2=1481392&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java Sat May 11 18:55:04 2013
@@ -21,12 +21,18 @@ package org.apache.webbeans.newtests.inj
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.newtests.injection.serialization.beans.NonSerializableDependentBean;
+import org.apache.webbeans.newtests.injection.serialization.beans.ProducerWithNonSerializableResultBean;
+import org.apache.webbeans.newtests.injection.serialization.beans.SerializableDependentInjectionTarget;
 import org.apache.webbeans.newtests.injection.serialization.beans.SerializableInjectionTargetFailA;
 import org.junit.Test;
 
 import java.util.ArrayList;
 import java.util.Collection;
 
+import javax.enterprise.inject.spi.Bean;
+
+import junit.framework.Assert;
+
 /**
  * <p>This test performs a few tests to ensure correct handling of injecting
  * &#064;Dependent scoped beans into beans of passivating scopes with
@@ -61,4 +67,27 @@ public class DependentPassivationCriteri
             shutDownContainer();
         }
     }
+
+    /**
+     * This test must not fail with a deployment exception nor with an IllegalProductException,
+     * since only dependent beans are involved.
+     */
+    @Test
+    public void testInjectNonSerializableDependentIntoSerializableDependent()
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(ProducerWithNonSerializableResultBean.class);
+        beanClasses.add(SerializableDependentInjectionTarget.class);
+
+        try
+        {
+            startContainer(beanClasses, beanXmls);
+            SerializableDependentInjectionTarget serializableDependentInjectionTarget = getInstance(SerializableDependentInjectionTarget.class);
+            Assert.assertNotNull(serializableDependentInjectionTarget.getInjectedBean());
+        }
+        finally {
+            shutDownContainer();
+        }
+    }
 }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/ProducerWithNonSerializableResultBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/ProducerWithNonSerializableResultBean.java?rev=1481392&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/ProducerWithNonSerializableResultBean.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/ProducerWithNonSerializableResultBean.java Sat May 11 18:55:04 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.injection.serialization.beans;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+
+/**
+ * Producer method with non serializable producer method result.
+ * See specification issues CDI-140, CDI-141 and CDI-153.
+ */
+@ApplicationScoped
+public class ProducerWithNonSerializableResultBean
+{
+
+    /**
+     * Non serializable parameters did crush in CDI-1.0 but are fine in CDI-1.1.
+     */
+    @Produces
+    public NonSerializableDependentBean newNonSerializableBean()
+    {
+        return new NonSerializableDependentBean();
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/SerializableDependentInjectionTarget.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/SerializableDependentInjectionTarget.java?rev=1481392&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/SerializableDependentInjectionTarget.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/SerializableDependentInjectionTarget.java Sat May 11 18:55:04 2013
@@ -0,0 +1,34 @@
+/*
+ * 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.injection.serialization.beans;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.Dependent;
+import javax.inject.Inject;
+
+@Dependent
+public class SerializableDependentInjectionTarget implements Serializable
+{
+    private @Inject NonSerializableDependentBean injectedBean;
+    
+    public NonSerializableDependentBean getInjectedBean() {
+        return injectedBean;
+    }
+}