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

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Thu Oct 29 18:36:36 EDT 2009


Author: pete.muir at jboss.org
Date: 2009-10-29 18:36:36 -0400 (Thu, 29 Oct 2009)
New Revision: 4428

Modified:
   core/trunk/tests/src/main/java/org/jboss/weld/mock/MockServletLifecycle.java
   core/trunk/tests/src/main/java/org/jboss/weld/mock/TestContainer.java
   core/trunk/tests/src/test/java/org/jboss/weld/test/unit/preinstantiatebeanmanager/PreinstantiateBeanManagerTest.java
Log:
WELD-220

Modified: core/trunk/tests/src/main/java/org/jboss/weld/mock/MockServletLifecycle.java
===================================================================
--- core/trunk/tests/src/main/java/org/jboss/weld/mock/MockServletLifecycle.java	2009-10-29 22:28:49 UTC (rev 4427)
+++ core/trunk/tests/src/main/java/org/jboss/weld/mock/MockServletLifecycle.java	2009-10-29 22:36:36 UTC (rev 4428)
@@ -79,7 +79,7 @@
       return deployment;
    }
    
-   protected WeldBootstrap getBootstrap()
+   public WeldBootstrap getBootstrap()
    {
       return bootstrap;
    }

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-29 22:28:49 UTC (rev 4427)
+++ core/trunk/tests/src/main/java/org/jboss/weld/mock/TestContainer.java	2009-10-29 22:36:36 UTC (rev 4428)
@@ -8,6 +8,19 @@
 /**
  * Control of the container, used for tests. Wraps up common operations.
  * 
+ * If you require more control over the container bootstrap lifecycle you should
+ * use the {@link #getLifecycle()} method. For example:
+ * 
+ * <code>TestContainer container = new TestContainer(...);
+ * container.getLifecycle().initialize();
+ * container.getLifecycle().getBootstrap().startInitialization();
+ * container.getLifecycle().getBootstrap().deployBeans();
+ * container.getLifecycle().getBootstrap().validateBeans();
+ * container.getLifecycle().getBootstrap().endInitialization();
+ * container.getLifecycle().stopContainer();</code>
+ * 
+ * Note that we can easily mix fine-grained calls to bootstrap, and coarse grained calls to {@link TestContainer}.
+ * 
  * @author pmuir
  *
  */
@@ -52,6 +65,7 @@
       this.lifecycle = lifecycle;
       this.classes = classes;
       this.beansXml = beansXml;
+      configureArchive();
    }
    
    /**
@@ -77,14 +91,14 @@
     */
    public void startContainer()
    {
-      startContainer(true);
+      getLifecycle().initialize();
+      getLifecycle().beginApplication();
    }
    
    /**
-    * Starts the container
-    * @param beginApplication whether or not beginApplication() should be called
+    * Configure's the archive with the classes and beans.xml
     */
-   public void startContainer(boolean beginApplication)
+   protected void configureArchive()
    {
       MockBeanDeploymentArchive archive = lifecycle.getDeployment().getArchive();
       archive.setBeanClasses(classes);
@@ -92,23 +106,9 @@
       {
          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();
-   }
-   
-   /**
     * Get the context lifecycle, allowing fine control over the contexts' state
     * 
     * @return
@@ -120,12 +120,12 @@
    
    public BeanManagerImpl getBeanManager()
    {
-      return lifecycle.getBootstrap().getManager(getDeployment().getArchive());
+      return getLifecycle().getBootstrap().getManager(getDeployment().getArchive());
    }
    
    public MockDeployment getDeployment()
    {
-      return lifecycle.getDeployment();
+      return getLifecycle().getDeployment();
    }
    
    /**
@@ -134,13 +134,13 @@
     */
    public void ensureRequestActive()
    {
-      if (!lifecycle.isSessionActive())
+      if (!getLifecycle().isSessionActive())
       {
-         lifecycle.beginSession();
+         getLifecycle().beginSession();
       }
-      if (!lifecycle.isRequestActive())
+      if (!getLifecycle().isRequestActive())
       {
-         lifecycle.beginRequest();
+         getLifecycle().beginRequest();
       }
    }
 
@@ -150,17 +150,17 @@
     */
    public void stopContainer()
    {
-      if (lifecycle.isRequestActive())
+      if (getLifecycle().isRequestActive())
       {
-         lifecycle.endRequest();
+         getLifecycle().endRequest();
       }
-      if (lifecycle.isSessionActive())
+      if (getLifecycle().isSessionActive())
       {
-         lifecycle.endSession();
+         getLifecycle().endSession();
       }
-      if (lifecycle.isApplicationActive())
+      if (getLifecycle().isApplicationActive())
       {
-         lifecycle.endApplication();
+         getLifecycle().endApplication();
       }
    }
 

Modified: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/preinstantiatebeanmanager/PreinstantiateBeanManagerTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/preinstantiatebeanmanager/PreinstantiateBeanManagerTest.java	2009-10-29 22:28:49 UTC (rev 4427)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/preinstantiatebeanmanager/PreinstantiateBeanManagerTest.java	2009-10-29 22:36:36 UTC (rev 4428)
@@ -41,7 +41,7 @@
       List<Class<?>> classes = new ArrayList<Class<?>>();
       classes.add(WeldBean.class);
       TestContainer container = new TestContainer(new MockEELifecycle(), classes, null);
-      container.startContainer(false);
+      container.getLifecycle().initialize();
       
       BeanManager bootstrapManager = container.getBeanManager();
       assert bootstrapManager != null;
@@ -52,7 +52,7 @@
       
       
       //Start the application
-      container.beginApplication();
+      container.getLifecycle().beginApplication();
       container.ensureRequestActive();
       
       //Check the manager is the same as before



More information about the weld-commits mailing list