You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2011/07/10 17:56:03 UTC

svn commit: r1144885 - 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: struberg
Date: Sun Jul 10 15:56:03 2011
New Revision: 1144885

URL: http://svn.apache.org/viewvc?rev=1144885&view=rev
Log:
OWB-589 add unit tests for serialization behaviour

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/NonSerializableDependentBean.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/SerializableInjectionTargetFailA.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.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=1144885&r1=1144884&r2=1144885&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 Sun Jul 10 15:56:03 2011
@@ -36,6 +36,7 @@ import org.apache.webbeans.component.Eve
 import org.apache.webbeans.component.InjectionPointBean;
 import org.apache.webbeans.component.InstanceBean;
 import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.context.creational.DependentCreationalContext;
@@ -91,9 +92,10 @@ public abstract class AbstractInjectable
     public <T> Object inject(InjectionPoint injectionPoint)
     {
         Object injected;
+        BeanManagerImpl beanManager = injectionOwnerBean.getWebBeansContext().getBeanManagerImpl();
 
         //Injected contextual beam
-        InjectionResolver instance = injectionOwnerBean.getWebBeansContext().getBeanManagerImpl().getInjectionResolver();
+        InjectionResolver instance = beanManager.getInjectionResolver();
 
         Bean<?> injectedBean = instance.getInjectionPointBean(injectionPoint);
         if(isInstanceProviderInjection(injectionPoint))
@@ -128,16 +130,18 @@ public abstract class AbstractInjectable
         }        
         
         //Gets injectable reference for injected bean
-        injected = injectionOwnerBean.getWebBeansContext().getBeanManagerImpl().getInjectableReference(injectionPoint, this.injectionOwnerCreationalContext);
-        
+        injected = beanManager.getInjectableReference(injectionPoint, this.injectionOwnerCreationalContext);
+
+        /*X TODO see spec issue CDI-140 */
         if(dependentProducer)
         {
             if(injected != null && !Serializable.class.isAssignableFrom(injected.getClass()))
             {
                 throw new IllegalProductException("If a producer method or field of scope @Dependent returns an serializable object for injection " +
-                                                        "into an injection point "+ injectionPoint +" that requires a passivation capable dependency");
+                                                  "into an injection point "+ injectionPoint +" that requires a passivation capable dependency");
             }
         }
+
         
         // add this dependent into bean dependent list
         if (!WebBeansUtil.isStaticInjection(injectionPoint) && WebBeansUtil.isDependent(injectedBean))

Added: 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=1144885&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java Sun Jul 10 15:56:03 2011
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+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.SerializableInjectionTargetFailA;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * <p>This test performs a few tests to ensure correct handling of injecting
+ * &#064;Dependent scoped beans into beans of passivating scopes with
+ * regard of Serialization handling.</p>
+ * <p>In general a non-Serializable &#064;Dependent scoped bean must not get
+ * injected into a passivating scoped bean. This is true for plain beans,
+ * producer fields and also for producer methods</p>
+ * <p>Injection <b>is</b> allowed if the injection point is transient or if
+ * the injection target bean either provides a writeObject(ObjectOutputStream)
+ * or a Externalizable#writeExternal(ObjectOutput) method.</p>
+ */
+public class DependentPassivationCriteriaTest extends AbstractUnitTest
+{
+    /**
+     * This tests if the container correctly detects a deployment exception
+     * according to spec 6.6.4:
+     * "
+     */
+    @Test(expected = WebBeansConfigurationException.class)
+    public void testInvalidNonSerializableDependentInjection()
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(NonSerializableDependentBean.class);
+        beanClasses.add(SerializableInjectionTargetFailA.class);
+
+        try
+        {
+            startContainer(beanClasses, beanXmls);
+        }
+        finally {
+            shutDownContainer();
+        }
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/NonSerializableDependentBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/NonSerializableDependentBean.java?rev=1144885&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/NonSerializableDependentBean.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/NonSerializableDependentBean.java Sun Jul 10 15:56:03 2011
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+/**
+ * A non-serializable &#064;Dependent scoped bean.
+ */
+public class NonSerializableDependentBean
+{
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/SerializableInjectionTargetFailA.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/SerializableInjectionTargetFailA.java?rev=1144885&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/SerializableInjectionTargetFailA.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/beans/SerializableInjectionTargetFailA.java Sun Jul 10 15:56:03 2011
@@ -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 javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+import java.io.Serializable;
+
+/**
+ *
+ */
+@SessionScoped
+public class SerializableInjectionTargetFailA implements Serializable
+{
+    // this must fail because a plain inject of a non-serializable
+    // bean into a passivating bean is not allowed.
+    private @Inject NonSerializableDependentBean injectedBean;
+}