[jboss-cvs] JBossAS SVN: r77597 - in projects/ejb3/trunk/common/src: test/java/org/jboss/ejb3/test/common/registrar/unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Aug 28 09:39:59 EDT 2008


Author: ALRubinger
Date: 2008-08-28 09:39:58 -0400 (Thu, 28 Aug 2008)
New Revision: 77597

Modified:
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3McRegistrarTestCase.java
Log:
[EJBTHREE-1472] Allow an object in MC in ControllerState other than INSTALLED to be unbound

Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java	2008-08-28 13:28:14 UTC (rev 77596)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java	2008-08-28 13:39:58 UTC (rev 77597)
@@ -77,7 +77,7 @@
    // --------------------------------------------------------------------------------||
    // Required Implementations -------------------------------------------------------||
    // --------------------------------------------------------------------------------||
-   
+
    /**
     * Lists out all installed (bound) objects in form
     * key == name , value == object.  Primarily for 
@@ -130,8 +130,26 @@
     */
    public Object lookup(final Object name) throws NotBoundException
    {
+      return this.lookup(name, true);
+   }
+
+   /**
+    * Obtains the value bound at the specified name, 
+    * throwing NotBoundException if there is nothing
+    * bound at the key.  If the "checkInstalled"
+    * flag is true, this implementation will
+    * also ensure that the lookup value is of
+    * ControllerState.INSTALLED, else NotBoundException
+    * 
+    * @param name
+    * @param checkInstalled
+    * @throws NotBoundException
+    * @return
+    */
+   public Object lookup(final Object name, boolean checkInstalled) throws NotBoundException
+   {
       // Get Controller Context
-      ControllerContext context = this.getKernel().getController().getInstalledContext(name);
+      ControllerContext context = this.getKernel().getController().getContext(name, null);
 
       // Ensure Bound
       if (context == null || context.getTarget() == null)
@@ -139,6 +157,21 @@
          throw new NotBoundException("Requested value bound at name \"" + name + "\" is not bound.");
       }
 
+      // If we're checking for installed
+      if (checkInstalled)
+      {
+         // Get State
+         ControllerState state = context.getState();
+
+         // If State is other than INSTALLED
+         if (!state.equals(ControllerState.INSTALLED))
+         {
+            throw new NotBoundException("Object is bound at key " + name
+                  + ", but is not fully installed, instead of state: " + state);
+         }
+
+      }
+
       // If there's an error with the context, throw it
       Throwable error = context.getError();
       if (error != null)
@@ -152,7 +185,7 @@
       log.debug("Returning from name \"" + name + "\": " + target);
       return target;
    }
-   
+
    /**
     * Obtains the value bound at the specified name, 
     * throwing NotBoundException if there is nothing
@@ -169,20 +202,20 @@
    {
       // Obtain object
       Object obj = this.lookup(name);
-      
+
       // Cast
       T returned = null;
       try
       {
          returned = type.cast(obj);
       }
-      catch(ClassCastException cce)
+      catch (ClassCastException cce)
       {
          throw new RuntimeException("Value returned from key \"" + name
                + "\" in Object Store was not of expected type " + type + ", but was instead "
                + obj.getClass().getName());
       }
-      
+
       // Return
       return returned;
    }
@@ -273,7 +306,7 @@
       // Ensure there is an object bound at this location
       try
       {
-         this.lookup(name);
+         this.lookup(name, false);
       }
       catch (NotBoundException nbe)
       {

Modified: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3McRegistrarTestCase.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3McRegistrarTestCase.java	2008-08-28 13:28:14 UTC (rev 77596)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3McRegistrarTestCase.java	2008-08-28 13:39:58 UTC (rev 77597)
@@ -21,11 +21,18 @@
  */
 package org.jboss.ejb3.test.common.registrar.unit;
 
+import junit.framework.TestCase;
+
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
 import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar;
 import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.common.registrar.spi.NotBoundException;
 import org.jboss.ejb3.test.mc.bootstrap.EmbeddedTestMcBootstrap;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Test;
 
 /**
  * Ejb3McRegistrarTestCase
@@ -46,6 +53,59 @@
    private static EmbeddedTestMcBootstrap bootstrap;
 
    // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Tests that an object bound with state other than "INSTALLED" may still be
+    * unbound from MC via the Ejb3Registrar
+    * 
+    * EJBTHREE-1472
+    */
+   @Test
+   public void testUnbindFromControllerStateOtherThanInstalled() throws Throwable
+   {
+      // Create a new key/value pair for binding into MC
+      String name = "MyObject";
+      Object value = new Object();
+
+      // Construct BMDB, adding an unmet dependency
+      BeanMetaDataBuilder bmdb = BeanMetaDataBuilder.createBuilder(name, value.getClass().getName());
+      bmdb.addDependency("SomeDependencyThatDoesn'tExist");
+
+      // Install into MC, though because of the unmet dependency will not reach "INSTALLED" state
+      try
+      {
+         getBootstrap().getKernel().getController().install(bmdb.getBeanMetaData(), value);
+      }
+      catch (Throwable e)
+      {
+         throw new RuntimeException("Could not install at name \"" + name + "\" value " + value, e);
+      }
+
+      // Ensure that the install didn't completely succeed
+      ControllerContext context = getBootstrap().getKernel().getController().getContext(name, null);
+      TestCase.assertTrue("The test object should not be fully installed for this test", !context.getState().equals(
+            ControllerState.INSTALLED));
+
+      // Unbind
+      Ejb3RegistrarLocator.locateRegistrar().unbind(name);
+
+      // Check that we've unbound
+      boolean isUnbound = false;
+      try
+      {
+         Ejb3RegistrarLocator.locateRegistrar().lookup(name);
+      }
+      catch (NotBoundException nbe)
+      {
+         isUnbound = true;
+      }
+      TestCase.assertTrue("The test object should be unbound", isUnbound);
+
+   }
+
+   // --------------------------------------------------------------------------------||
    // Lifecycle Methods --------------------------------------------------------------||
    // --------------------------------------------------------------------------------||
 
@@ -57,7 +117,7 @@
 
       // Bind the Ejb3Registrar
       Ejb3RegistrarLocator.bindRegistrar(new Ejb3McRegistrar(Ejb3McRegistrarTestCase.getBootstrap().getKernel()));
-      
+
       // Deploy
       Ejb3McRegistrarTestCase.bootstrap.deploy(Ejb3McRegistrarTestCase.class);
    }




More information about the jboss-cvs-commits mailing list