openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1187534 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/container/BeanManagerImpl.java test/java/org/apache/webbeans/newtests/portable/BeanManagerTest.java
Date Fri, 21 Oct 2011 20:22:32 GMT
Author: struberg
Date: Fri Oct 21 20:22:31 2011
New Revision: 1187534

URL: http://svn.apache.org/viewvc?rev=1187534&view=rev
Log:
OWB-625 fix Exceptions in BeanManager#resolve if given set is null or empty

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/BeanManagerTest.java
      - copied, changed from r1185080, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1187534&r1=1187533&r2=1187534&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Fri Oct 21 20:22:31 2011
@@ -1078,7 +1078,12 @@ public class BeanManagerImpl implements 
     }
 
     public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans)
-    { 
+    {
+        if (beans == null || beans.isEmpty())
+        {
+            return null;
+        }
+
         Set set = new HashSet<Bean<Object>>();
         for(Bean<? extends X> obj : beans)
         {

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/BeanManagerTest.java
(from r1185080, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/BeanManagerTest.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/BeanManagerTest.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java&r1=1185080&r2=1187534&rev=1187534&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/BeanManagerTest.java
Fri Oct 21 20:22:31 2011
@@ -18,31 +18,21 @@
  */
 package org.apache.webbeans.newtests.portable;
 
-import java.util.ArrayList;
-import java.util.Collection;
-
-import javax.enterprise.inject.spi.Bean;
-
 import junit.framework.Assert;
-
-import org.apache.webbeans.annotation.DefaultLiteral;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.exception.inject.DefinitionException;
 import org.apache.webbeans.newtests.AbstractUnitTest;
-import org.apache.webbeans.newtests.portable.scopeextension.ExternalTestScopeExtension;
-import org.apache.webbeans.newtests.portable.scopeextension.ExternalTestScoped;
-import org.apache.webbeans.newtests.portable.scopeextension.ExternalTestScopedBean;
-import org.apache.webbeans.newtests.portable.scopeextension.ExternalUnserializableTestScopedBean;
-import org.apache.webbeans.portable.events.discovery.BeforeShutdownImpl;
 import org.junit.Test;
 
+import javax.enterprise.inject.spi.BeanManager;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
 /**
- * This test checks if an extension gets loaded correctly and
- * if all specified events get fired.
+ * Various tests for the BeanManager
  */
-public class ExtensionTest extends AbstractUnitTest
+public class BeanManagerTest extends AbstractUnitTest
 {
-    public ExtensionTest()
+    public BeanManagerTest()
     {
     }
 
@@ -51,56 +41,19 @@ public class ExtensionTest extends Abstr
      * This test adds a scope and tests if the lifecycle works
      */
     @Test
-    public void testScopeExtension()
+    public void testResolve()
     {
         Collection<Class<?>> classes = new ArrayList<Class<?>>();
-        classes.add(ExternalTestScopedBean.class);
-        addExtension(new ExternalTestScopeExtension());
         startContainer(classes);
 
-        WebBeansContext webBeansContext = WebBeansContext.getInstance();
-        webBeansContext.getContextFactory().initApplicationContext(null);
+        BeanManager bm = getInstance(BeanManager.class);
+        Assert.assertNotNull(bm);
 
-        @SuppressWarnings("unchecked")
-        Bean<ExternalTestScopedBean> bean = (Bean<ExternalTestScopedBean>) getBeanManager().getBeans(ExternalTestScopedBean.class,

-                                                                                        
            new DefaultLiteral()).iterator().next();
-        
-        ExternalTestScopedBean instance = (ExternalTestScopedBean) getBeanManager().getReference(bean,
ExternalTestScopedBean.class, 
-                                                                                        
        getBeanManager().createCreationalContext(bean));
-        
-        Assert.assertNotNull(instance);
-        
-        Assert.assertTrue(getBeanManager().isPassivatingScope(ExternalTestScoped.class));
-        
-        //Fire shut down
-        getBeanManager().fireEvent(new BeforeShutdownImpl());
+        // this must not throw a NPE
+        Assert.assertNull(bm.resolve(null));
 
-        webBeansContext.getContextFactory().destroyApplicationContext(null);
+        Assert.assertNull(bm.resolve(Collections.EMPTY_SET));
 
         shutDownContainer();
-        
     }
-    
-    /**
-     * Classes in a passivatable scope must be Serializable
-     */
-    @Test
-    public void testUnserializableBean() 
-    {
-        try 
-        {
-            Collection<Class<?>> classes = new ArrayList<Class<?>>();
-            classes.add(ExternalUnserializableTestScopedBean.class);
-            addExtension(new ExternalTestScopeExtension());
-            startContainer(classes);
-            
-            // we must not get here since an Exception is expected!
-            Assert.fail();
-        }
-        catch (DefinitionException dex)
-        {
-            // this is expected!
-        }
-    }
-
 }



Mime
View raw message