[jboss-cvs] JBossAS SVN: r73659 - in projects/ejb3/trunk/common: src/main/java/org/jboss/ejb3/common and 15 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat May 24 18:26:13 EDT 2008
Author: ALRubinger
Date: 2008-05-24 18:26:13 -0400 (Sat, 24 May 2008)
New Revision: 73659
Added:
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/
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/spi/
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/DuplicateBindException.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3RegistrarLocator.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/NotBoundException.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/SimplePojo.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/
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/Ejb3RegistrarTestCaseBase.java
projects/ejb3/trunk/common/src/test/resources/org/
projects/ejb3/trunk/common/src/test/resources/org/jboss/
projects/ejb3/trunk/common/src/test/resources/org/jboss/ejb3/
projects/ejb3/trunk/common/src/test/resources/org/jboss/ejb3/test/
projects/ejb3/trunk/common/src/test/resources/org/jboss/ejb3/test/common/
projects/ejb3/trunk/common/src/test/resources/org/jboss/ejb3/test/common/registrar/
projects/ejb3/trunk/common/src/test/resources/org/jboss/ejb3/test/common/registrar/unit/
projects/ejb3/trunk/common/src/test/resources/org/jboss/ejb3/test/common/registrar/unit/Ejb3McRegistrarTestCase-beans.xml
Modified:
projects/ejb3/trunk/common/pom.xml
Log:
[EJBTHREE-1379] Create an EJB3 Object Store and MC Implementation, with Tests
Modified: projects/ejb3/trunk/common/pom.xml
===================================================================
--- projects/ejb3/trunk/common/pom.xml 2008-05-24 21:38:41 UTC (rev 73658)
+++ projects/ejb3/trunk/common/pom.xml 2008-05-24 22:26:13 UTC (rev 73659)
@@ -72,6 +72,26 @@
<artifactId>jboss-logging-log4j</artifactId>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ <version>2.0.0.Beta13</version>
+ </dependency>
+
+ <!-- MC doesn't declare this as a proper dependency -->
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-managed</artifactId>
+ <version>2.0.0.Beta10</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-test</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Added: 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 (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java 2008-05-24 22:26:13 UTC (rev 73659)
@@ -0,0 +1,251 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.ejb3.common.registrar.plugin.mc;
+
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.ejb3.common.registrar.spi.DuplicateBindException;
+import org.jboss.ejb3.common.registrar.spi.Ejb3Registrar;
+import org.jboss.ejb3.common.registrar.spi.NotBoundException;
+import org.jboss.kernel.Kernel;
+import org.jboss.logging.Logger;
+
+/**
+ * Ejb3McRegistrar
+ *
+ * Microcontainer-based Implementation of the Ejb3Registrar
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ * @see {@link Ejb3Registrar}
+ */
+public class Ejb3McRegistrar implements Ejb3Registrar
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(Ejb3McRegistrar.class);
+
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * The Kernel instance pointing to the underlying Object Store
+ */
+ private Kernel kernel;
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public Ejb3McRegistrar(Kernel kernel)
+ {
+ this.setKernel(kernel);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Required Implementations -------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the value bound at the specified name,
+ * throwing NotBoundException if there is nothing
+ * bound at the key
+ *
+ * @param name
+ * @throws NotBoundException
+ * @return
+ */
+ public Object lookup(Object name) throws NotBoundException
+ {
+ // Get Controller Context
+ ControllerContext context = this.getKernel().getController().getInstalledContext(name);
+
+ // Ensure Bound
+ if (context == null || context.getTarget() == null)
+ {
+ throw new NotBoundException("Requested value bound at name \"" + name + "\" is not bound.");
+ }
+
+ // If there's an error with the context, throw it
+ Throwable error = context.getError();
+ if (error != null)
+ {
+ throw new RuntimeException("Could not lookup object at name \"" + name
+ + "\" due to an error with the underlying " + ControllerContext.class.getSimpleName(), error);
+ }
+
+ // Return
+ return context.getTarget();
+ }
+
+ /**
+ * Binds the specified value to the key of specified name,
+ * throwing a DuplicateBindException in the case the
+ * name is not unique
+ *
+ * @param name
+ * @param value
+ * @throws DuplicateBindException
+ */
+ public void bind(Object name, Object value) throws DuplicateBindException
+ {
+ // Ensure there's nothing already at this location
+ Object existing = null;
+ try
+ {
+ existing = this.lookup(name);
+ }
+ // Expected
+ catch (NotBoundException e)
+ {
+ // Install
+ this.install(name, value);
+ return;
+ }
+
+ // Something is already here, throw an exception
+ throw new DuplicateBindException("Cannot install " + value + " under name \"" + name
+ + "\" as there is already an existing object there: " + existing);
+ }
+
+ /**
+ * Binds the specified value to the key of specified name,
+ * optionally unbinding the current value if one exists
+ *
+ * @param name
+ * @param value
+ */
+ public void rebind(Object name, Object value)
+ {
+ // Initialize
+ boolean alreadyBound = true;
+
+ // Determine if already bound
+ try
+ {
+ this.lookup(name);
+ }
+ // We need to unbind first
+ catch (NotBoundException nbe)
+ {
+ alreadyBound = false;
+ }
+
+ // If this name is already bound
+ if (alreadyBound)
+ {
+ try
+ {
+ // Unbind
+ this.unbind(name);
+ }
+ // Should not occur, if so we've got an error in implementation
+ catch (NotBoundException e)
+ {
+ throw new RuntimeException("Lookup in registry for name \"" + name
+ + "\" has reported an object already bound, but attempt to unbind has failed with "
+ + NotBoundException.class.getSimpleName(), e);
+ }
+ }
+
+ // Install
+ this.install(name, value);
+ }
+
+ /**
+ * Unbinds the object at the specified name, throwing
+ * NotBoundException if no object exists at that name
+ *
+ * @param name
+ * @throws NotBoundException
+ */
+ public void unbind(Object name) throws NotBoundException
+ {
+ // Ensure there is an object bound at this location
+ try
+ {
+ this.lookup(name);
+ }
+ catch (NotBoundException nbe)
+ {
+ throw new NotBoundException("Could not unbind object at name \"" + name + "\" as none is currently bound");
+ }
+
+ // Uninstall
+ this.getKernel().getController().uninstall(name);
+ }
+
+ /**
+ * Returns a provider implementation-specific class
+ * to break contract and invoke upon vendor-specific
+ * features.
+ *
+ * @return
+ */
+ public Kernel getProvider()
+ {
+ return this.getKernel();
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Internal Helper Methods --------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Installs the specified value into MC at the specified name
+ */
+ private void install(Object name, Object value)
+ {
+ // Construct BMDB
+ BeanMetaDataBuilder bmdb = BeanMetaDataBuilder.createBuilder(name.toString(), value.getClass().getName());
+
+ // Install into MC
+ try
+ {
+ this.getKernel().getController().install(bmdb.getBeanMetaData(), value);
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException("Could not install at name \"" + name + "\" value " + value, e);
+ }
+ log.info("Installed in " + this.getKernel().getController() + " at \"" + name + "\": " + value);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Accessors / Mutators -----------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private Kernel getKernel()
+ {
+ return kernel;
+ }
+
+ private void setKernel(Kernel kernel)
+ {
+ this.kernel = kernel;
+ }
+
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/DuplicateBindException.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/DuplicateBindException.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/DuplicateBindException.java 2008-05-24 22:26:13 UTC (rev 73659)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.ejb3.common.registrar.spi;
+
+/**
+ * DuplicateBindException
+ *
+ * Signals that a bind operation cannot complete because
+ * a key is already bound
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ * @see {@link Ejb3Registrar}
+ */
+public class DuplicateBindException extends Exception
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final long serialVersionUID = 1L;
+
+ // --------------------------------------------------------------------------------||
+ // Constructors -------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public DuplicateBindException()
+ {
+ }
+
+ public DuplicateBindException(String message)
+ {
+ super(message);
+ }
+
+ public DuplicateBindException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public DuplicateBindException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java 2008-05-24 22:26:13 UTC (rev 73659)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.ejb3.common.registrar.spi;
+
+/**
+ * Ejb3Registrar
+ *
+ * Defines the contract for implementations of
+ * the EJB3 Object Store, providing mechanisms
+ * to bind, unbind, and lookup generic Objects
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Ejb3Registrar
+{
+ /**
+ * Obtains the value bound at the specified name,
+ * throwing NotBoundException if there is nothing
+ * bound at the key
+ *
+ * @param name
+ * @throws NotBoundException
+ * @return
+ */
+ Object lookup(Object name) throws NotBoundException;
+
+ /**
+ * Binds the specified value to the key of specified name,
+ * throwing a DuplicateBindException in the case the
+ * name is not unique
+ *
+ * @param name
+ * @param value
+ * @throws DuplicateBindException
+ */
+ void bind(Object name, Object value) throws DuplicateBindException;
+
+ /**
+ * Binds the specified value to the key of specified name,
+ * optionally unbinding the current value if one exists
+ *
+ * @param name
+ * @param value
+ */
+ void rebind(Object name, Object value);
+
+ /**
+ * Unbinds the object at the specified name, throwing
+ * NotBoundException if no object exists at that name
+ *
+ * @param name
+ * @throws NotBoundException
+ */
+ void unbind(Object name) throws NotBoundException;
+
+ /**
+ * Returns a provider implementation-specific class
+ * to break contract and invoke upon vendor-specific
+ * features.
+ *
+ * @return
+ */
+ Object getProvider();
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3RegistrarLocator.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3RegistrarLocator.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3RegistrarLocator.java 2008-05-24 22:26:13 UTC (rev 73659)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.ejb3.common.registrar.spi;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Ejb3RegistrarLocator
+ *
+ * Provides simple mechanism for locating and setting
+ * the Ejb3Registrar. Once set, the Ejb3Registrar is
+ * immutable and cannot be replaced.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class Ejb3RegistrarLocator
+{
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(Ejb3RegistrarLocator.class);
+
+ /**
+ * Singleton instance
+ */
+ private static Ejb3RegistrarLocator instance;
+
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * The Registrar implementation of record, may only be set once and is then
+ * immutable
+ */
+ private Ejb3Registrar registrar;
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private Ejb3RegistrarLocator(Ejb3Registrar registrar)
+ {
+ this.setRegistrar(registrar);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Singleton ----------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Ejb3Registrar associated with this
+ * process; in the case one has not yet been bound,
+ * a RuntimeException will be thrown
+ *
+ * @return
+ */
+ public static Ejb3Registrar locateRegistrar()
+ {
+ // If no registrar implementation has been set
+ if (Ejb3RegistrarLocator.instance == null)
+ {
+ // Throw unchecked exception to the user
+ throw new RuntimeException(new NotBoundException("Could not retrieve " + Ejb3Registrar.class.getSimpleName()
+ + " as a registrar implementation has not yet been bound."));
+ }
+
+ // Return the registrar
+ return Ejb3RegistrarLocator.instance.getRegistrar();
+ }
+
+ /**
+ * Binds the specified Ejb3Registrar implementation
+ * as the registrar of record for the life of this process,
+ * immutable once set
+ *
+ * @param registrar
+ * @throws DuplicateBindException
+ */
+ public synchronized static void bindRegistrar(Ejb3Registrar registrar) throws DuplicateBindException
+ {
+ // Immutable once bound
+ if (Ejb3RegistrarLocator.instance != null)
+ {
+ throw new DuplicateBindException(Ejb3Registrar.class.getSimpleName()
+ + " is already bound and is now immutable");
+ }
+
+ // Make a new instance and set registrar
+ Ejb3RegistrarLocator.instance = new Ejb3RegistrarLocator(registrar);
+ log.debug("Bound " + Ejb3Registrar.class.getSimpleName() + ": " + registrar);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Accessors / Mutators -----------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private Ejb3Registrar getRegistrar()
+ {
+ return this.registrar;
+ }
+
+ private void setRegistrar(Ejb3Registrar registrar)
+ {
+ this.registrar = registrar;
+ }
+
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/NotBoundException.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/NotBoundException.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/NotBoundException.java 2008-05-24 22:26:13 UTC (rev 73659)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.ejb3.common.registrar.spi;
+
+/**
+ * NotBoundException
+ *
+ * Signals that an operation cannot complete because
+ * a requested object could not be found in the Ejb3Registry
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ * @see {@link Ejb3Registrar}
+ */
+public class NotBoundException extends Exception
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final long serialVersionUID = 1L;
+
+ // --------------------------------------------------------------------------------||
+ // Constructors -------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public NotBoundException()
+ {
+ }
+
+ public NotBoundException(String message)
+ {
+ super(message);
+ }
+
+ public NotBoundException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public NotBoundException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+}
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/SimplePojo.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/SimplePojo.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/SimplePojo.java 2008-05-24 22:26:13 UTC (rev 73659)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.ejb3.test.common.registrar;
+
+/**
+ * SimplePojo
+ *
+ * A simple object used in testing MC Bindings via the Ejb3Registrar
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class SimplePojo
+{
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private String property;
+
+ // --------------------------------------------------------------------------------||
+ // Accessors / Mutators -----------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public String getProperty()
+ {
+ return property;
+ }
+
+ public void setProperty(final String property)
+ {
+ this.property = property;
+ }
+}
Added: 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 (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3McRegistrarTestCase.java 2008-05-24 22:26:13 UTC (rev 73659)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.ejb3.test.common.registrar.unit;
+
+import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.test.mc.bootstrap.EmbeddedTestMcBootstrap;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * Ejb3McRegistrarTestCase
+ *
+ * Test Cases for the Microcontainer
+ * implementation of the Ejb3Registrar
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class Ejb3McRegistrarTestCase extends Ejb3RegistrarTestCaseBase
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static EmbeddedTestMcBootstrap bootstrap;
+
+ // --------------------------------------------------------------------------------||
+ // Lifecycle Methods --------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ @BeforeClass
+ public static void beforeClass() throws Throwable
+ {
+ // Create and set a new MC Bootstrap
+ Ejb3McRegistrarTestCase.setBootstrap(EmbeddedTestMcBootstrap.createEmbeddedMcBootstrap());
+
+ // Bind the Ejb3Registrar
+ Ejb3RegistrarLocator.bindRegistrar(new Ejb3McRegistrar(Ejb3McRegistrarTestCase.getBootstrap().getKernel()));
+
+ // Deploy
+ Ejb3McRegistrarTestCase.bootstrap.deploy(Ejb3McRegistrarTestCase.class);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception
+ {
+ // Shutdown MC
+ Ejb3McRegistrarTestCase.bootstrap.shutdown();
+
+ // Set Bootstrap to null
+ Ejb3McRegistrarTestCase.setBootstrap(null);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Accessors / Mutators -----------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public static EmbeddedTestMcBootstrap getBootstrap()
+ {
+ return Ejb3McRegistrarTestCase.bootstrap;
+ }
+
+ public static void setBootstrap(EmbeddedTestMcBootstrap bootstrap)
+ {
+ Ejb3McRegistrarTestCase.bootstrap = bootstrap;
+ }
+
+}
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3RegistrarTestCaseBase.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3RegistrarTestCaseBase.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/registrar/unit/Ejb3RegistrarTestCaseBase.java 2008-05-24 22:26:13 UTC (rev 73659)
@@ -0,0 +1,199 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.ejb3.test.common.registrar.unit;
+
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar;
+import org.jboss.ejb3.common.registrar.spi.DuplicateBindException;
+import org.jboss.ejb3.common.registrar.spi.Ejb3Registrar;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.common.registrar.spi.NotBoundException;
+import org.jboss.ejb3.test.common.registrar.SimplePojo;
+import org.junit.Test;
+
+/**
+ * Ejb3RegistrarTestCaseBase
+ *
+ * Common Test Cases for implementations
+ * of the Ejb3Registrar
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class Ejb3RegistrarTestCaseBase
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * The name of the POJO as defined in the *-beans.xml
+ */
+ private static final String REGISTRY_NAME_POJO = "org.jboss.ejb3.SimplePojo";
+
+ // --------------------------------------------------------------------------------||
+ // Tests --------------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that a simple lookup succeeds
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testRegistrarLookup() throws Throwable
+ {
+ SimplePojo pojo = (SimplePojo) Ejb3RegistrarLocator.locateRegistrar().lookup(
+ Ejb3RegistrarTestCaseBase.REGISTRY_NAME_POJO);
+ TestCase.assertNotNull("Retrieved POJO from Registry was null", pojo);
+ }
+
+ /**
+ * Ensures that a new binding/lookup roundtrip succeeds
+ * with the same object retrived as that which was placed into the registry
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testRegistrarBindAndLookup() throws Throwable
+ {
+ // Initialize
+ String bindName = "org.jboss.ejb3.TestBind" + UUID.randomUUID();
+ String propertyValue = "propValue";
+ SimplePojo pojo = new SimplePojo();
+ pojo.setProperty(propertyValue);
+
+ // Bind
+ Ejb3RegistrarLocator.locateRegistrar().bind(bindName, pojo);
+
+ // Lookup
+ SimplePojo retrieved = (SimplePojo) Ejb3RegistrarLocator.locateRegistrar().lookup(bindName);
+
+ // Test
+ TestCase
+ .assertTrue("Retrieved value is not equal by reference to what was put in to registry", pojo == retrieved);
+ TestCase.assertEquals("Set property was not equal to that which was put into Registry", propertyValue, retrieved
+ .getProperty());
+ }
+
+ /**
+ * Tests that a rebind results in a new object replacing
+ * the old in the Registry
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testRegistrarRebind() throws Throwable
+ {
+ // Initialize
+ String bindName = Ejb3RegistrarTestCaseBase.REGISTRY_NAME_POJO;
+
+ // Lookup the default pojo
+ SimplePojo pojoExisting = (SimplePojo) Ejb3RegistrarLocator.locateRegistrar().lookup(bindName);
+ TestCase.assertNotNull("Retrieved POJO from Registry was null", pojoExisting);
+
+ // Make a new POJO
+ SimplePojo pojoNew = new SimplePojo();
+
+ // Rebind into existing address
+ Ejb3RegistrarLocator.locateRegistrar().rebind(bindName, pojoNew);
+
+ // Lookup
+ SimplePojo retrieved = (SimplePojo) Ejb3RegistrarLocator.locateRegistrar().lookup(bindName);
+
+ // Test
+ TestCase.assertTrue("Old value and retrieved from registry should not be equal by reference",
+ pojoExisting != retrieved);
+ TestCase.assertTrue("Placed value and retrieved from registry must be equal by reference", pojoNew == retrieved);
+
+ }
+
+ @Test
+ public void testRegistrarDuplicateBindFails() throws Throwable
+ {
+ // Initialize
+ String bindName = Ejb3RegistrarTestCaseBase.REGISTRY_NAME_POJO;
+
+ // Make a new POJO
+ SimplePojo pojoNew = new SimplePojo();
+
+ // Attempt to bind into existing address
+ try
+ {
+ Ejb3RegistrarLocator.locateRegistrar().bind(bindName, pojoNew);
+ }
+ // Expected
+ catch (DuplicateBindException dbe)
+ {
+ return;
+ }
+
+ // Should not be reached
+ TestCase.fail("Operation to bind into existing name in registry should fail with "
+ + DuplicateBindException.class.getName());
+ }
+
+ @Test
+ public void testRegistrarEmptyLookupFails() throws Throwable
+ {
+ // Initialize an unused name
+ String bindName = "org.jboss.ejb3.unused";
+
+ // Attempt to lookup
+ try
+ {
+ Ejb3RegistrarLocator.locateRegistrar().lookup(bindName);
+ }
+ // Expected
+ catch (NotBoundException nbe)
+ {
+ return;
+ }
+
+ // Should not be reached
+ TestCase.fail("Attempt to lookup an unbound name should result in " + NotBoundException.class.getName());
+ }
+
+ @Test
+ public void testRegistrarImmutableAfterBound() throws Throwable
+ {
+ try
+ {
+ // Attempt to bind a new registrar
+ Ejb3RegistrarLocator.bindRegistrar(new Ejb3McRegistrar(null));
+ }
+ // Expected
+ catch (DuplicateBindException dbe)
+ {
+ return;
+ }
+
+ // Should not be reached
+ TestCase.fail("Attempts to rebind the " + Ejb3Registrar.class.getSimpleName()
+ + " implementation should fail after already bound");
+ }
+
+}
Added: projects/ejb3/trunk/common/src/test/resources/org/jboss/ejb3/test/common/registrar/unit/Ejb3McRegistrarTestCase-beans.xml
===================================================================
--- projects/ejb3/trunk/common/src/test/resources/org/jboss/ejb3/test/common/registrar/unit/Ejb3McRegistrarTestCase-beans.xml (rev 0)
+++ projects/ejb3/trunk/common/src/test/resources/org/jboss/ejb3/test/common/registrar/unit/Ejb3McRegistrarTestCase-beans.xml 2008-05-24 22:26:13 UTC (rev 73659)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="org.jboss.ejb3.SimplePojo"
+ class="org.jboss.ejb3.test.common.registrar.SimplePojo" />
+
+</deployment>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list