[jboss-cvs] JBossAS SVN: r70425 - in projects/microcontainer/trunk/kernel/src: tests/org/jboss/test/kernel/inject/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 5 09:44:56 EST 2008


Author: alesj
Date: 2008-03-05 09:44:56 -0500 (Wed, 05 Mar 2008)
New Revision: 70425

Removed:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/WiredMicrocontainerTest.java
Modified:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTest.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/inject/test/WiredTestTestCase.java
Log:
Removing WiredMCTest from the main code.
The functionality has moved to its super class, MicrocontainerTest.

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-03-05 14:28:20 UTC (rev 70424)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTest.java	2008-03-05 14:44:56 UTC (rev 70425)
@@ -22,12 +22,16 @@
 package org.jboss.test.kernel.junit;
 
 import java.net.URL;
+import java.util.UUID;
 
 import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.deployment.KernelDeployment;
 import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
+import org.jboss.kernel.Kernel;
 import org.jboss.test.AbstractTestCaseWithSetup;
 import org.jboss.test.AbstractTestDelegate;
 
@@ -39,6 +43,12 @@
  */
 public class MicrocontainerTest extends AbstractTestCaseWithSetup
 {
+   /** Should we wire this bean */
+   private boolean autowireCandidate;
+
+   /** The test bean name */
+   private String testBeanName;
+
    /**
     * Get the test delegate
     * 
@@ -61,6 +71,12 @@
       super(name);
    }
    
+   public MicrocontainerTest(String name, boolean autowireCandidate)
+   {
+      super(name);
+      this.autowireCandidate = autowireCandidate;
+   }
+
    protected void setUp() throws Exception
    {
       super.setUp();
@@ -74,12 +90,88 @@
     */
    protected void afterSetUp() throws Exception
    {
+      if (autowireCandidate)
+         autowireThis();
+
       configureLogging();
       // Validate everything deployed
       getMCDelegate().validate();
    }
 
+   @Override
+   protected void tearDown() throws Exception
+   {
+      if (autowireCandidate)
+         clearAutowire();
+
+      super.tearDown();
+   }
+
    /**
+    * Autowire this test instance.
+    * Registering it into underlying controller.
+    *
+    * @throws Exception for any error
+    */
+   protected void autowireThis() throws Exception
+   {
+      String beanName = createTestBeanName();
+      KernelController controller = getController();
+      try
+      {
+         controller.install(new AbstractBeanMetaData(beanName, getClass().getName()), this);
+         // we're installed
+         testBeanName = beanName;
+      }
+      catch (Throwable t)
+      {
+         throw new Exception(t);
+      }
+   }
+
+   /**
+    * Get the test's bean name.
+    * By default it's random uuid.
+    *
+    * @return test's bean name
+    */
+   protected String createTestBeanName()
+   {
+      return UUID.randomUUID().toString();
+   }
+
+   /**
+    * Clear things after autowiring.
+    */
+   protected void clearAutowire()
+   {
+      if (testBeanName != null)
+      {
+         try
+         {
+            KernelController controller = getController();
+            controller.uninstall(testBeanName);
+         }
+         catch (Exception e)
+         {
+            getLog().warn("Exception while uninstalling test instance: " + e);  
+         }
+      }
+   }
+
+   /**
+    * Get the underlying controller.
+    *
+    * @return the controller
+    */
+   private KernelController getController()
+   {
+      MicrocontainerTestDelegate delegate = getMCDelegate();
+      Kernel kernel = delegate.kernel;
+      return kernel.getController();
+   }
+
+   /**
     * Get a bean
     * 
     * @param name the bean name
@@ -327,4 +419,14 @@
    {
       return (MicrocontainerTestDelegate) getDelegate();
    }
+
+   /**
+    * Set the autowire flag.
+    *
+    * @param autowireCandidate the autowire flag
+    */
+   public void setAutowireCandidate(boolean autowireCandidate)
+   {
+      this.autowireCandidate = autowireCandidate;
+   }
 }

Deleted: projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/WiredMicrocontainerTest.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/WiredMicrocontainerTest.java	2008-03-05 14:28:20 UTC (rev 70424)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/WiredMicrocontainerTest.java	2008-03-05 14:44:56 UTC (rev 70425)
@@ -1,104 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.test.kernel.junit;
-
-import java.util.UUID;
-
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
-
-/**
- * A Wired MicrocontainerTest.
- *
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- */
-public abstract class WiredMicrocontainerTest extends MicrocontainerTest
-{
-   /** The bean name */
-   private String beanName = createTestBeanName();
-
-   /**
-    * Create a new Wired Microcontainer test
-    *
-    * @param name the test name
-    */
-   protected WiredMicrocontainerTest(String name)
-   {
-      super(name);
-   }
-
-   protected void afterSetUp() throws Exception
-   {
-      KernelController controller = getController();
-      try
-      {
-         controller.install(new AbstractBeanMetaData(beanName, getClass().getName()), this);
-      }
-      catch (Throwable t)
-      {
-         throw new Exception(t);
-      }
-      super.afterSetUp();
-   }
-
-   /**
-    * Get the underlying controller.
-    *
-    * @return the controller
-    */
-   private KernelController getController()
-   {
-      MicrocontainerTestDelegate delegate = getMCDelegate();
-      Kernel kernel = delegate.kernel;
-      return kernel.getController();
-   }
-
-   protected void tearDown() throws Exception
-   {
-      KernelController controller = getController();
-      controller.uninstall(beanName);
-      super.tearDown();
-   }
-
-   /**
-    * Get the test's bean name.
-    * By default it's random uuid.
-    *
-    * @return test's bean name
-    */
-   protected String createTestBeanName()
-   {
-      return UUID.randomUUID().toString();
-   }
-
-   /**
-    * Get the test's bean name.
-    * By default it's what create method returns.
-    *
-    * @return test's bean name
-    */
-   protected String getTestBeanName()
-   {
-      return beanName;
-   }
-}

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/inject/test/WiredTestTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/inject/test/WiredTestTestCase.java	2008-03-05 14:28:20 UTC (rev 70424)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/inject/test/WiredTestTestCase.java	2008-03-05 14:44:56 UTC (rev 70425)
@@ -21,18 +21,18 @@
 */
 package org.jboss.test.kernel.inject.test;
 
-import org.jboss.test.kernel.junit.WiredMicrocontainerTest;
+import junit.framework.Test;
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.test.kernel.inject.support.StringValueObject;
 import org.jboss.test.kernel.inject.support.TesterInterface;
-import org.jboss.test.kernel.inject.support.StringValueObject;
-import org.jboss.beans.metadata.api.annotations.Inject;
-import junit.framework.Test;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
 
 /**
  * Test wired test. :-)
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class WiredTestTestCase extends WiredMicrocontainerTest
+public class WiredTestTestCase extends MicrocontainerTest
 {
    private TesterInterface tester;
    private StringValueObject valueObject;
@@ -40,7 +40,7 @@
 
    public WiredTestTestCase(String name)
    {
-      super(name);
+      super(name, true);
    }
 
    public static Test suite()




More information about the jboss-cvs-commits mailing list