[webbeans-commits] Webbeans SVN: r1426 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean and 2 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Fri Feb 6 08:22:00 EST 2009


Author: dallen6
Date: 2009-02-06 08:21:59 -0500 (Fri, 06 Feb 2009)
New Revision: 1426

Added:
   tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/passivating/Kajaani.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
   tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/integration/context/passivating/PassivatingContextTest.java
   tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/passivating/PassivatingContextTest.java
Log:
Fixed validation on passivating beans and tests for passivating contexts.

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java	2009-02-06 00:16:52 UTC (rev 1425)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java	2009-02-06 13:21:59 UTC (rev 1426)
@@ -40,6 +40,8 @@
 import org.jboss.webbeans.bean.NewSimpleBean;
 import org.jboss.webbeans.bean.ProducerMethodBean;
 import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.introspector.AnnotatedField;
+import org.jboss.webbeans.introspector.AnnotatedParameter;
 import org.jboss.webbeans.metadata.MetaDataCache;
 import org.jboss.webbeans.util.Beans;
 import org.jboss.webbeans.util.ListComparator;
@@ -112,6 +114,21 @@
                      }
                   }
                }
+               if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isPassivating())
+               {
+                  if (resolvedBean instanceof AbstractProducerBean)
+                  {
+                     AbstractProducerBean producerBean = (AbstractProducerBean) resolvedBean;
+                     if ((injectionPoint instanceof AnnotatedField) && ((AnnotatedField<?>) injectionPoint).isTransient())
+                     {
+                        injectionPoint.getBean();
+                     }
+                     else if (producerBean.getScopeType().equals(Dependent.class) && !Reflections.isSerializable(producerBean.getType()))
+                     {
+                        throw new IllegalProductException("Cannot inject @Depedent non-serializable type into " + injectionPoint);
+                     }
+                  }
+               }
             }
             else
             {

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java	2009-02-06 00:16:52 UTC (rev 1425)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java	2009-02-06 13:21:59 UTC (rev 1426)
@@ -37,12 +37,15 @@
 
 import org.jboss.webbeans.ManagerImpl;
 import org.jboss.webbeans.injection.AnnotatedInjectionPoint;
+import org.jboss.webbeans.introspector.AnnotatedField;
 import org.jboss.webbeans.introspector.AnnotatedItem;
+import org.jboss.webbeans.introspector.AnnotatedParameter;
 import org.jboss.webbeans.introspector.AnnotationStore.AnnotationMap;
 import org.jboss.webbeans.literal.CurrentLiteral;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.metadata.MergedStereotypes;
+import org.jboss.webbeans.metadata.MetaDataCache;
 import org.jboss.webbeans.util.Beans;
 import org.jboss.webbeans.util.Reflections;
 
@@ -119,7 +122,7 @@
    {
       super(manager);
       this.manager = manager;
-      injectionPoints = new HashSet<AnnotatedInjectionPoint<?,?>>();
+      injectionPoints = new HashSet<AnnotatedInjectionPoint<?, ?>>();
    }
 
    /**
@@ -167,7 +170,7 @@
       this.bindings = new HashSet<Annotation>();
       this.bindings.addAll(getAnnotatedItem().getMetaAnnotations(BindingType.class));
    }
-   
+
    protected void initDefaultBindings()
    {
       if (bindings.size() == 0)
@@ -228,7 +231,7 @@
             return;
          }
       }
-      
+
       if (beanNameDefaulted || getMergedStereotypes().isBeanNameDefaulted())
       {
          this.name = getDefaultName();
@@ -258,9 +261,12 @@
       {
          Annotation[] bindings = injectionPoint.getMetaAnnotationsAsArray(BindingType.class);
          Bean<?> resolvedBean = manager.resolveByType(injectionPoint.getType(), bindings).iterator().next();
-         if (Dependent.class.equals(resolvedBean.getScopeType()) && !resolvedBean.isSerializable())
+         if (MetaDataCache.instance().getScopeModel(this.getScopeType()).isPassivating())
          {
-            return false;
+            if (Dependent.class.equals(resolvedBean.getScopeType()) && !resolvedBean.isSerializable() && (((injectionPoint instanceof AnnotatedField) && !((AnnotatedField<?>) injectionPoint).isTransient()) || (injectionPoint instanceof AnnotatedParameter)) )
+            {
+               return false;
+            }
          }
       }
       return true;
@@ -326,7 +332,7 @@
          }
       }
    }
-   
+
    protected void postSpecialize()
    {
       if (getAnnotatedItem().isAnnotationPresent(Named.class) && getSpecializedBean().getAnnotatedItem().isAnnotationPresent(Named.class))
@@ -341,15 +347,15 @@
       }
       manager.getSpecializedBeans().put(getSpecializedBean(), this);
    }
-   
+
    protected void preSpecialize()
    {
-      
+
    }
-   
+
    protected void specialize()
    {
-      
+
    }
 
    /**
@@ -377,7 +383,7 @@
     * @return The default name
     */
    protected abstract String getDefaultName();
-   
+
    public abstract AbstractBean<?, ?> getSpecializedBean();
 
    /**
@@ -494,7 +500,7 @@
    {
       return _serializable;
    }
-   
+
    protected void initSerializable()
    {
       _serializable = isPrimitive() || getTypes().contains(Serializable.class);
@@ -525,7 +531,7 @@
    {
       return getAnnotatedItem().isAnnotationPresent(Specializes.class);
    }
-   
+
    @Override
    // TODO Fix this!!!
    public boolean equals(Object other)
@@ -541,7 +547,7 @@
          return false;
       }
    }
-   
+
    @Override
    public int hashCode()
    {
@@ -550,5 +556,5 @@
       result = 31 * result + getBindings().hashCode();
       return result;
    }
-   
+
 }

Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/integration/context/passivating/PassivatingContextTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/integration/context/passivating/PassivatingContextTest.java	2009-02-06 00:16:52 UTC (rev 1425)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/integration/context/passivating/PassivatingContextTest.java	2009-02-06 13:21:59 UTC (rev 1426)
@@ -1,5 +1,7 @@
 package org.jboss.webbeans.tck.integration.context.passivating;
 
+import java.io.IOException;
+
 import javax.inject.IllegalProductException;
 
 import org.jboss.webbeans.tck.AbstractTest;
@@ -56,4 +58,32 @@
       manager.getInstanceByType(Maarianhamina_Broken.class);
    }
 
+   /**
+    * the Web Bean is an EJB stateful session bean, and it is passivated by the
+    * EJB container.
+    */
+   // TODO requires an EJB instance
+   @Test(groups = { "contexts", "passivation", "stub", "integration" })
+   @SpecAssertion(section = "8.4", id = "unknown")
+   public void testStatefulEJBIsSerializedWhenPassivatedByEJBContainer() throws IOException, ClassNotFoundException
+   {
+      assert false;
+   }
+
+   /**
+    * If a producer method or field of scope @Dependent returns a
+    * non-serializable object for injection into a stateful session bean, into a
+    * non-transient field, Web Bean constructor parameter or initializer method
+    * parameter of a Web Bean which declares a passivating scope type, or into a
+    * parameter of a producer method which declares a passivating scope type, an
+    * IllegalProductException is thrown by the Web Bean manager.
+    * 
+    */
+   @Test(groups = { "contexts", "passivation", "stub", "integration" }, expectedExceptions = IllegalProductException.class)
+   @SpecAssertion(section = "8.4", id = "unknown")
+   public void testDependentScopedProducerFieldReturnsNonSerializableObjectForInjectionIntoStatefulSessionBeanFails() throws Exception
+   {
+      assert false;
+   }
+
 }

Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/passivating/Kajaani.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/passivating/Kajaani.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/passivating/Kajaani.java	2009-02-06 13:21:59 UTC (rev 1426)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.tck.unit.context.passivating;
+
+import java.io.Serializable;
+
+import javax.context.SessionScoped;
+
+ at SessionScoped
+public class Kajaani implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+   private Integer theNumber = 0;
+
+   public int getTheNumber()
+   {
+      return theNumber;
+   }
+
+   public void setTheNumber(int theNumber)
+   {
+      this.theNumber = theNumber;
+   }
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/passivating/Kajaani.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/passivating/PassivatingContextTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/passivating/PassivatingContextTest.java	2009-02-06 00:16:52 UTC (rev 1425)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/passivating/PassivatingContextTest.java	2009-02-06 13:21:59 UTC (rev 1426)
@@ -3,6 +3,8 @@
 import java.io.IOException;
 import java.util.Set;
 
+import javax.context.Context;
+import javax.context.SessionScoped;
 import javax.inject.DefinitionException;
 import javax.inject.IllegalProductException;
 import javax.inject.UnserializableDependencyException;
@@ -67,15 +69,19 @@
    /**
     * the Web Bean declares a passivating scope type, and context passivation
     * occurs, or
-    * 
-    * @throws IOException
-    * @throws ClassNotFoundException
     */
-   @Test(groups = { "contexts", "passivation", "stub" })
+   @Test(groups = { "contexts", "passivation" })
    @SpecAssertion(section = "8.4", id = "unknown")
    public void testSimpleWebBeanDeclaringPassivatingScopeIsSerializedWhenContextIsPassivated() throws IOException, ClassNotFoundException
    {
-      assert false;
+      deployBeans(Kajaani.class);
+      Kajaani instance = manager.getInstanceByType(Kajaani.class);
+      instance.setTheNumber(100);
+      Context sessionContext = manager.getContext(SessionScoped.class);
+      setContextInactive(sessionContext);
+      setContextActive(sessionContext);
+      instance = manager.getInstanceByType(Kajaani.class);
+      assert instance.getTheNumber() == 100;
    }
 
    @SuppressWarnings("unchecked")
@@ -89,21 +95,6 @@
    }
 
    /**
-    * the Web Bean is an EJB stateful session bean, and it is passivated by the
-    * EJB container.
-    * 
-    * @throws ClassNotFoundException
-    * @throws IOException
-    */
-   // TODO requires an EJB instance
-   @Test(groups = { "contexts", "passivation", "broken", "stub" })
-   @SpecAssertion(section = "8.4", id = "unknown")
-   public void testStatefulEJBIsSerializedWhenPassivatedByEJBContainer() throws IOException, ClassNotFoundException
-   {
-      assert false;
-   }
-
-   /**
     * On the other hand, dependent objects (including interceptors and
     * decorators with scope @Dependent) of a stateful session bean or of a Web
     * Bean with a passivating scope must be serialized and deserialized along
@@ -218,7 +209,7 @@
     * UnserializableDependencyException must be thrown by the Web Bean manager
     * at initialization time.
     */
-   @Test(groups = { "contexts", "passivation", "broken" })
+   @Test(groups = { "contexts", "passivation" })
    @SpecAssertion(section = "8.4", id = "unknown")
    public void testSimpleDependentWebBeanWithNonSerializableImplementationInjectedIntoTransientFieldOK()
    {
@@ -363,26 +354,7 @@
     * parameter of a Web Bean which declares a passivating scope type, or into a
     * parameter of a producer method which declares a passivating scope type, an
     * IllegalProductException is thrown by the Web Bean manager.
-    * 
     */
-   @Test(groups = { "contexts", "passivation", "stub" }, expectedExceptions = IllegalProductException.class)
-   @SpecAssertion(section = "8.4", id = "unknown")
-   public void testDependentScopedProducerFieldReturnsNonSerializableObjectForInjectionIntoStatefulSessionBeanFails() throws Exception
-   {
-      // TODO This doesn't test injction in a SFSB, but into a Enterprise bean
-      // deployBeans(CityProducer.class, Pietarsaari_Broken.class);
-      // manager.getInstanceByType(Pietarsaari_Broken.class);
-      assert false;
-   }
-
-   /**
-    * If a producer method or field of scope @Dependent returns a
-    * non-serializable object for injection into a stateful session bean, into a
-    * non-transient field, Web Bean constructor parameter or initializer method
-    * parameter of a Web Bean which declares a passivating scope type, or into a
-    * parameter of a producer method which declares a passivating scope type, an
-    * IllegalProductException is thrown by the Web Bean manager.
-    */
    @Test(groups = { "contexts", "passivation" }, expectedExceptions = IllegalProductException.class)
    @SpecAssertion(section = "8.4", id = "unknown")
    public void testDependentScopedProducerFieldReturnsNonSerializableObjectForInjectionIntoNonTransientFieldOfWebBeanWithPassivatingScopeFails()




More information about the weld-commits mailing list