[weld-commits] Weld SVN: r4212 - in core/trunk/tests/src: test/java/org/jboss/weld/test/unit and 1 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Wed Oct 21 11:18:12 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-10-21 11:18:12 -0400 (Wed, 21 Oct 2009)
New Revision: 4212

Added:
   core/trunk/tests/src/test/java/org/jboss/weld/test/unit/clearresolver/
   core/trunk/tests/src/test/java/org/jboss/weld/test/unit/clearresolver/PreinstantiateBeanManager.java
   core/trunk/tests/src/test/java/org/jboss/weld/test/unit/clearresolver/WeldBean.java
Modified:
   core/trunk/tests/src/main/java/org/jboss/weld/mock/TestContainer.java
Log:
[WELD-220] Make it possible to obtain the bean manager before the beans are deployed in TestContainer.

Modified: core/trunk/tests/src/main/java/org/jboss/weld/mock/TestContainer.java
===================================================================
--- core/trunk/tests/src/main/java/org/jboss/weld/mock/TestContainer.java	2009-10-21 14:59:56 UTC (rev 4211)
+++ core/trunk/tests/src/main/java/org/jboss/weld/mock/TestContainer.java	2009-10-21 15:18:12 UTC (rev 4212)
@@ -39,7 +39,7 @@
    private final MockServletLifecycle lifecycle;
    private final Collection<Class<?>> classes;
    private final Collection<URL> beansXml;
-
+   
    /**
     * Create a container, specifying the classes and beans.xml to deploy
     * 
@@ -72,8 +72,20 @@
       return new Status(null);
    }
    
+   /**
+    * Starts the container and begins the application
+    */
    public void startContainer()
    {
+      startContainer(true);
+   }
+   
+   /**
+    * Starts the container
+    * @param beginApplication whether or not beginApplication() should be called
+    */
+   public void startContainer(boolean beginApplication)
+   {
       MockBeanDeploymentArchive archive = lifecycle.getDeployment().getArchive();
       archive.setBeanClasses(classes);
       if (beansXml != null)
@@ -81,6 +93,18 @@
          archive.setBeansXmlFiles(beansXml);
       }
       lifecycle.initialize();
+      if (beginApplication)
+      {
+         beginApplication();
+      }
+   }
+   
+   /**
+    * Deploys the application. Intended use is in conjunction with {@link #startContainer(boolean)}.
+    * {@link #startContainer()} does this step automatically 
+    */
+   public void beginApplication()
+   {
       lifecycle.beginApplication();
    }
    

Added: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/clearresolver/PreinstantiateBeanManager.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/clearresolver/PreinstantiateBeanManager.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/clearresolver/PreinstantiateBeanManager.java	2009-10-21 15:18:12 UTC (rev 4212)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.weld.test.unit.clearresolver;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.weld.mock.MockEELifecycle;
+import org.jboss.weld.mock.TestContainer;
+import org.testng.annotations.Test;
+
+/**
+ * @author kkhan
+ *
+ */
+public class PreinstantiateBeanManager
+{
+
+   @Test
+   public void test()
+   {
+      //Start the container, but do not deploy weld yet
+      List<Class<?>> classes = new ArrayList<Class<?>>();
+      classes.add(WeldBean.class);
+      TestContainer container = new TestContainer(new MockEELifecycle(), classes, null);
+      container.startContainer(false);
+      
+      BeanManager bootstrapManager = container.getBeanManager();
+      assert bootstrapManager != null;
+
+      //Check the bean is null since it is not there yet
+      Set<Bean<?>> beans = bootstrapManager.getBeans(WeldBean.class);
+      assert beans == null || beans.size() == 0;
+      
+      
+      //Start the application
+      container.beginApplication();
+      container.ensureRequestActive();
+      
+      //Check the manager is the same as before
+      BeanManager manager = container.getBeanManager();
+      assert manager != null;
+      assert bootstrapManager == manager;
+      
+      //Check we can get the bean
+      Bean<? extends Object> bean = manager.resolve(manager.getBeans(WeldBean.class));
+      WeldBean weldBean = (WeldBean) manager.getReference(bean, WeldBean.class, manager.createCreationalContext(bean));
+      assert weldBean != null;
+      
+      container.stopContainer();
+   }
+   
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/clearresolver/WeldBean.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/clearresolver/WeldBean.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/clearresolver/WeldBean.java	2009-10-21 15:18:12 UTC (rev 4212)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.weld.test.unit.clearresolver;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class WeldBean
+{
+
+}



More information about the weld-commits mailing list