[jboss-cvs] JBossAS SVN: r69865 - projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 15 13:42:18 EST 2008


Author: adrian at jboss.org
Date: 2008-02-15 13:42:17 -0500 (Fri, 15 Feb 2008)
New Revision: 69865

Modified:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTest.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTestDelegate.java
Log:
Add methods to the Microcontainer JUnit test support to allow programmatic deployment of KernelDeployments and BeanMetaData

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTest.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTest.java	2008-02-15 15:48:11 UTC (rev 69864)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTest.java	2008-02-15 18:42:17 UTC (rev 69865)
@@ -23,6 +23,7 @@
 
 import java.net.URL;
 
+import org.jboss.beans.metadata.spi.BeanMetaData;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.kernel.spi.deployment.KernelDeployment;
@@ -45,7 +46,7 @@
     * @return the delegate
     * @throws Exception for any error
     */
-   public static AbstractTestDelegate getDelegate(Class clazz) throws Exception
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
    {
       return new MicrocontainerTestDelegate(clazz);
    }
@@ -169,6 +170,39 @@
    }
    
    /**
+    * Deploy a bean
+    *
+    * @param beanMetaData the bean metadata
+    * @return the deployment
+    * @throws Exception for any error  
+    */
+   protected KernelControllerContext deploy(BeanMetaData beanMetaData) throws Exception
+   {
+      return getMCDelegate().deploy(beanMetaData);
+   }
+   
+   /**
+    * Deploy a deployment
+    *
+    * @param deployment the deployment
+    * @throws Exception for any error  
+    */
+   protected void deploy(KernelDeployment deployment) throws Exception
+   {
+      getMCDelegate().deploy(deployment);
+   }
+   
+   /**
+    * Undeploy a bean
+    *
+    * @param context the context
+    */
+   protected void undeploy(KernelControllerContext context)
+   {
+      getMCDelegate().undeploy(context);
+   }
+   
+   /**
     * Undeploy a deployment
     *
     * @param deployment the deployment

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTestDelegate.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTestDelegate.java	2008-02-15 15:48:11 UTC (rev 69864)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTestDelegate.java	2008-02-15 18:42:17 UTC (rev 69865)
@@ -23,6 +23,7 @@
 
 import java.net.URL;
 
+import org.jboss.beans.metadata.spi.BeanMetaData;
 import org.jboss.dependency.spi.Controller;
 import org.jboss.dependency.spi.ControllerMode;
 import org.jboss.dependency.spi.ControllerState;
@@ -59,7 +60,7 @@
     * @param clazz the test class
     * @throws Exception for any error
     */
-   public MicrocontainerTestDelegate(Class clazz) throws Exception
+   public MicrocontainerTestDelegate(Class<?> clazz) throws Exception
    {
       super(clazz);
    }
@@ -275,6 +276,80 @@
    }
    
    /**
+    * Deploy a bean
+    *
+    * @param beanMetaData the bean metadata
+    * @return the deployment
+    * @throws Exception for any error  
+    */
+   protected KernelControllerContext deploy(BeanMetaData beanMetaData) throws Exception
+   {
+      KernelController controller = kernel.getController();
+      log.debug("Deploying " + beanMetaData);
+      try
+      {
+         KernelControllerContext result = controller.install(beanMetaData);
+         log.debug("Deployed " + result.getName());
+         return result;
+      }
+      catch (Exception e)
+      {
+         throw e;
+      }
+      catch (Error e)
+      {
+         throw e;
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException("Error deploying bean: " + beanMetaData, t);
+      }
+   }
+   
+   /**
+    * Deploy a deployment
+    *
+    * @param deployment the deployment
+    * @throws Exception for any error  
+    */
+   protected void deploy(KernelDeployment deployment) throws Exception
+   {
+      log.debug("Deploying " + deployment);
+      try
+      {
+         deployer.deploy(deployment);
+         log.debug("Deployed " + deployment);
+      }
+      catch (Exception e)
+      {
+         throw e;
+      }
+      catch (Error e)
+      {
+         throw e;
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException("Error deploying deployment: " + deployment, t);
+      }
+   }
+   
+   /**
+    * Undeploy a bean
+    *
+    * @param context the context
+    */
+   protected void undeploy(KernelControllerContext context)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+      log.debug("Undeploying " + context.getName());
+      KernelController controller = kernel.getController();
+      controller.uninstall(context.getName());
+      log.debug("Undeployed " + context.getName());
+   }
+
+   /**
     * Undeploy a deployment
     * 
     * @param deployment the deployment




More information about the jboss-cvs-commits mailing list