openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1503028 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ test/java/org/apache/webbeans/newtests/promethods/ test/java/org/apache/webbeans/newtests/promethods/beans/ test/java/org/apache/webbeans/newtests...
Date Sun, 14 Jul 2013 19:08:14 GMT
Author: arne
Date: Sun Jul 14 19:08:13 2013
New Revision: 1503028

URL: http://svn.apache.org/r1503028
Log:
OWB-878: Fixed check of @Produces result

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/RequestScopedNullPersonProducerBean.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/SessionScopedPersonProducerBean.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/PersonProducerTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/common/Person.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java?rev=1503028&r1=1503027&r2=1503028&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
Sun Jul 14 19:08:13 2013
@@ -28,6 +28,7 @@ import javax.enterprise.inject.spi.Produ
 import org.apache.webbeans.component.spi.BeanAttributes;
 import org.apache.webbeans.component.spi.ProducerFactory;
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.util.WebBeansUtil;
 
 
 /**
@@ -78,6 +79,35 @@ public class AbstractProducerBean<T> ext
     {
         // Do nothing
     }
+    
+    /**
+     * Check null control.
+     * 
+     * @param instance bean instance
+     */
+    protected void checkNullInstance(Object instance, String producerName)
+    {
+        String errorMessage = "WebBeans producer : %s" +
+                              " return type in the component implementation class : %s" +
+                              " scope type must be @Dependent to create null instance";
+        WebBeansUtil.checkNullInstance(instance, getScope(), errorMessage, producerName,
+                getBeanClass().getName());
+    }
+
+    /**
+     * Check passivation check.
+     */
+    protected void checkScopeType(String producerName)
+    {
+        String errorMessage = "WebBeans producer : %s" +
+                              " return type in the component implementation class : %s" +
+                              " with passivating scope @%s" +
+                              " must be Serializable";
+        getWebBeansContext().getWebBeansUtil().checkSerializableScopeType(getScope(),
+                Serializable.class.isAssignableFrom(getReturnType()), errorMessage, producerName,
getBeanClass().getName(),
+                getScope().getName());
+
+    }
 
     protected boolean isPassivationCapable(Class<?> returnType, Integer modifiers)
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java?rev=1503028&r1=1503027&r2=1503028&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
Sun Jul 14 19:08:13 2013
@@ -18,13 +18,11 @@
  */
 package org.apache.webbeans.component;
 
-import java.io.Serializable;
 import java.lang.reflect.Field;
 
 import javax.enterprise.context.spi.CreationalContext;
 
 import org.apache.webbeans.component.spi.ProducerFactory;
-import org.apache.webbeans.util.WebBeansUtil;
 
 /**
  * Defines the producer field component implementation.
@@ -56,8 +54,8 @@ public class ProducerFieldBean<T> extend
         T instance = null;
         
         instance = super.create(creationalContext);
-        checkNullInstance(instance);
-        checkScopeType();
+        checkNullInstance(instance, producerField.getName());
+        checkScopeType(producerField.getName());
 
         return instance;
 
@@ -83,34 +81,6 @@ public class ProducerFieldBean<T> extend
         producerField = field;
     }
 
-    /**
-     * Check null instance.
-     * 
-     * @param instance bean instance
-     */
-    protected void checkNullInstance(Object instance)
-    {
-        String errorMessage = "WebBeans producer field : %s" +
-                              " return type in the component implementation class : %s" +
-                              " scope must be @Dependent to create null instance";
-        WebBeansUtil.checkNullInstance(instance, getScope(), errorMessage, producerField.getName(),
-                getBeanClass().getName());
-    }
-
-    /**
-     * Check scope type passivation controls.
-     */
-    protected void checkScopeType()
-    {
-        String errorMessage = "WebBeans producer method : %s" + 
-                              " return type in the component implementation class : %s" +
-                              " with passivating scope @%s" +
-                              " must be Serializable";
-        getWebBeansContext().getWebBeansUtil().checkSerializableScopeType(getScope(),
-                getReturnType() instanceof Serializable, errorMessage, producerField.getName(),

-                getBeanClass().getName(), getScope().getName());
-    }
-    
     @Override
     public boolean isPassivationCapable()
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java?rev=1503028&r1=1503027&r2=1503028&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
Sun Jul 14 19:08:13 2013
@@ -18,14 +18,12 @@
  */
 package org.apache.webbeans.component;
 
-import java.io.Serializable;
 import java.lang.reflect.Method;
 
 import javax.enterprise.context.spi.CreationalContext;
 
 import org.apache.webbeans.component.creation.MethodProducerFactory;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.util.WebBeansUtil;
 
 /**
  * Concrete implementation of the {@link AbstractOwbBean}.
@@ -118,41 +116,12 @@ public class ProducerMethodBean<T> exten
     {
         T instance = super.create(creationalContext);
         // Check null instance
-        checkNullInstance(instance);
+        checkNullInstance(instance, creatorMethod.getName());
 
         // Check scope type
-        checkScopeType();
+        checkScopeType(creatorMethod.getName());
         return instance;
     }
-    
-    /**
-     * Check null control.
-     * 
-     * @param instance bean instance
-     */
-    protected void checkNullInstance(Object instance)
-    {
-        String errorMessage = "WebBeans producer method : %s" +
-                              " return type in the component implementation class : %s" +
-                              " scope type must be @Dependent to create null instance";
-        WebBeansUtil.checkNullInstance(instance, getScope(), errorMessage, creatorMethod.getName(),
-                getBeanClass().getName());
-    }
-
-    /**
-     * Check passivation check.
-     */
-    protected void checkScopeType()
-    {
-        String errorMessage = "WebBeans producer method : %s" +
-                              " return type in the component implementation class : %s" +
-                              " with passivating scope @%s" +
-                              " must be Serializable";
-        getWebBeansContext().getWebBeansUtil().checkSerializableScopeType(getScope(),
-                getReturnType() instanceof Serializable, errorMessage, creatorMethod.getName(),
getBeanClass().getName(),
-                getScope().getName());
-
-    }
 
     @Override
     public boolean isPassivationCapable()

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/PersonProducerTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/PersonProducerTest.java?rev=1503028&r1=1503027&r2=1503028&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/PersonProducerTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/PersonProducerTest.java
Sun Jul 14 19:08:13 2013
@@ -23,12 +23,15 @@ import java.util.Collection;
 import java.util.Set;
 
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.IllegalProductException;
 import javax.enterprise.inject.spi.Bean;
 
 import junit.framework.Assert;
 
 import org.apache.webbeans.component.ProducerMethodBean;
 import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.promethods.beans.SessionScopedPersonProducerBean;
+import org.apache.webbeans.newtests.promethods.beans.RequestScopedNullPersonProducerBean;
 import org.apache.webbeans.newtests.promethods.beans.PersonProducerBean;
 import org.apache.webbeans.newtests.promethods.common.Person;
 import org.junit.Test;
@@ -93,4 +96,48 @@ public class PersonProducerTest extends 
         
         shutDownContainer();
     }
+    
+    @Test
+    public void testSessionScopedNullPersonProducer()
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+        
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(Person.class);
+        beanClasses.add(SessionScopedPersonProducerBean.class);
+        
+        startContainer(beanClasses, beanXmls);  
+        
+        try
+        {
+            getInstance("person").toString();
+            Assert.fail("expected IllegalProductException");
+        }
+        catch (IllegalProductException e)
+        {
+            //expected
+        }
+    }
+    
+    @Test
+    public void testRequestScopedNullPersonProducer()
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+        
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(Person.class);
+        beanClasses.add(RequestScopedNullPersonProducerBean.class);
+        
+        startContainer(beanClasses, beanXmls);  
+        
+        try
+        {
+            getInstance("nullPerson").toString();
+            Assert.fail("expected IllegalProductException");
+        }
+        catch (IllegalProductException e)
+        {
+            //expected
+        }
+    }
 }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/RequestScopedNullPersonProducerBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/RequestScopedNullPersonProducerBean.java?rev=1503028&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/RequestScopedNullPersonProducerBean.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/RequestScopedNullPersonProducerBean.java
Sun Jul 14 19:08:13 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.promethods.beans;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+import org.apache.webbeans.newtests.promethods.common.Person;
+
+public class RequestScopedNullPersonProducerBean
+{
+    
+    @Produces @Named("nullPerson") @RequestScoped
+    public Person nullProducer()
+    {
+        return null;
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/SessionScopedPersonProducerBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/SessionScopedPersonProducerBean.java?rev=1503028&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/SessionScopedPersonProducerBean.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/SessionScopedPersonProducerBean.java
Sun Jul 14 19:08:13 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.promethods.beans;
+
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+import org.apache.webbeans.newtests.promethods.common.Person;
+
+public class SessionScopedPersonProducerBean
+{
+    
+    @Produces @Named("person") @SessionScoped
+    public Person producer()
+    {
+        return new Person();
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/common/Person.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/common/Person.java?rev=1503028&r1=1503027&r2=1503028&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/common/Person.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/common/Person.java
Sun Jul 14 19:08:13 2013
@@ -18,9 +18,7 @@
  */
 package org.apache.webbeans.newtests.promethods.common;
 
-import java.io.Serializable;
-
-public class Person implements Serializable
+public class Person
 {
 
 }



Mime
View raw message