[jboss-cvs] JBossAS SVN: r73327 - in projects/ejb3/trunk/proxy/src/test: java/org and 26 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 13 02:05:25 EDT 2008


Author: ALRubinger
Date: 2008-05-13 02:05:25 -0400 (Tue, 13 May 2008)
New Revision: 73327

Added:
   projects/ejb3/trunk/proxy/src/test/java/org/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/EmbeddedTestMcBootstrap.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/MockSessionProxyFactory.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/ProxyFactoryRegistryUnitTestCaseBase.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/inmemory/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/unit/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/unit/InMemoryProxyFactoryRegistryUnitTestCase.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/jndi/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/jndi/registry/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/jndi/registry/unit/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/jndi/registry/unit/JndiProxyFactoryRegistryUnitTestCase.java
   projects/ejb3/trunk/proxy/src/test/resources/log4j.xml
   projects/ejb3/trunk/proxy/src/test/resources/org/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/inmemory/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/unit/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/unit/InMemoryProxyFactoryRegistryUnitTestCase-beans.xml
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/jndi/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/jndi/registry/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/jndi/registry/unit/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/jndi/registry/unit/JndiProxyFactoryRegistryUnitTestCase-beans.xml
Log:
[EJBTHREE-1345] Added Tests for ProxyFactoryRegistries.  The JNDI Implementation tests need additional to start/stop JNP Server and Inject proper naming Context into the JndiProxyFactoryRegistry

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/EmbeddedTestMcBootstrap.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/EmbeddedTestMcBootstrap.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/EmbeddedTestMcBootstrap.java	2008-05-13 06:05:25 UTC (rev 73327)
@@ -0,0 +1,305 @@
+/*
+ * 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.proxy.common;
+
+import java.net.URL;
+
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.deployment.AbstractKernelDeployer;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+import org.jboss.logging.Logger;
+
+/**
+ * EmbeddedTestMcBootstrap
+ * 
+ * A MicroContainer Bootstrap for general use in testing 
+ * runtimes
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class EmbeddedTestMcBootstrap extends BasicBootstrap
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(EmbeddedTestMcBootstrap.class);
+
+   private static final String DEFAULT_SUFFIX_DEPLOYABLE_XML = "-beans.xml";
+
+   // --------------------------------------------------------------------------------||
+   // Instance Members ---------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private BasicXMLDeployer deployer;
+
+   // --------------------------------------------------------------------------------||
+   // Constructors -------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public EmbeddedTestMcBootstrap()
+   {
+      super();
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Static Methods -----------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Creates, runs, and returns a new Embedded MC Bootstrap 
+    */
+   public static EmbeddedTestMcBootstrap createEmbeddedMcBootstrap()
+   {
+      EmbeddedTestMcBootstrap bootstrap = new EmbeddedTestMcBootstrap();
+      log.debug("Starting " + bootstrap + "...");
+      bootstrap.run();
+      log.info("Started: " + bootstrap);
+      return bootstrap;
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Overridden Implementations -----------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   @Override
+   protected void bootstrap() throws Throwable
+   {
+      // Call super implementation
+      super.bootstrap();
+
+      // Create and set an XML Deployer
+      this.setDeployer(new BasicXMLDeployer(this.getKernel()));
+
+      // Add a shutdown hook
+      Runtime.getRuntime().addShutdownHook(new ShutdownDeployerThread(this.getDeployer()));
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Functional Methods -------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Deploys the specified URL
+    * 
+    * @param url
+    */
+   public void deploy(URL url)
+   {
+      try
+      {
+         log.debug("Deploying " + url.toString() + "...");
+         this.getDeployer().deploy(url);
+         log.info("Deployed: " + url.toString());
+      }
+      catch (Throwable e)
+      {
+         throw new RuntimeException("Could not deploy " + url.toString(), e);
+      }
+   }
+
+   /**
+    * Deploys the specified URL expressed as a String
+    * 
+    * @param url
+    */
+   public void deploy(ClassLoader cl, String url)
+   {
+      URL deployable = this.getResource(cl, url);
+      this.deploy(deployable);
+   }
+
+   /**
+    * Deploy a URL in the form "fullyQualifiedClassName-beans.xml" constructed
+    * from the specified testClass
+    * 
+    * @param testClass
+    */
+   public void deploy(Class<?> testClass)
+   {
+      this.deploy(testClass, null);
+   }
+
+   /**
+    * Deploy a URL in the form "packageName.filename-beans.xml" constructed
+    * from the specified testClass and filename
+    * 
+    * @param testClass
+    * @param filename
+    */
+   public void deploy(Class<?> testClass, String filename)
+   {
+      this.deploy(testClass.getClassLoader(), this.getDeployableXmlUrl(testClass, filename));
+   }
+
+   /**
+    * Undeploys the specified URL
+    * 
+    * @param url
+    */
+   public void undeploy(URL url)
+   {
+      try
+      {
+         log.debug("Undeploying " + url.toString() + "...");
+         this.getDeployer().undeploy(url);
+         log.info("Undeployed: " + url.toString());
+      }
+      catch (Throwable e)
+      {
+         throw new RuntimeException("Could not undeploy " + url.toString(), e);
+      }
+   }
+
+   /**
+    * Undeploys the specified URL expressed as a String
+    * 
+    * @param url
+    */
+   public void undeploy(ClassLoader cl, String url)
+   {
+      URL deployable = this.getResource(cl, url);
+      this.undeploy(deployable);
+   }
+
+   /**
+    * Undeploy a URL in the form "fullyQualifiedClassName-beans.xml" constructed
+    * from the specified testClass
+    * 
+    * @param testClass
+    */
+   public void undeploy(Class<?> testClass)
+   {
+      this.undeploy(testClass, null);
+   }
+
+   /**
+    * Undeploy a URL in the form "packageName.filename-beans.xml" constructed
+    * from the specified testClass and filename
+    * 
+    * @param testClass
+    * @param filename
+    */
+   public void undeploy(Class<?> testClass, String filename)
+   {
+      this.undeploy(testClass.getClassLoader(), this.getDeployableXmlUrl(testClass, filename));
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Accessors / Mutators -----------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   protected BasicXMLDeployer getDeployer()
+   {
+      return deployer;
+   }
+
+   protected void setDeployer(BasicXMLDeployer deployer)
+   {
+      this.deployer = deployer;
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Inner Classes ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * ShutdownDeployerThread
+    * 
+    * A Simple Thread that, when run, will shut down its deployer
+    *
+    * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+    * @version $Revision: $
+    */
+   protected final class ShutdownDeployerThread extends Thread
+   {
+      private AbstractKernelDeployer deployer;
+
+      public ShutdownDeployerThread(AbstractKernelDeployer deployer)
+      {
+         this.deployer = deployer;
+      }
+
+      @Override
+      public void run()
+      {
+         super.run();
+         log.debug("Shutting down " + this.deployer + "...");
+         getDeployer().shutdown();
+         log.info("Shut down: " + getDeployer());
+      }
+
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Helper Methods -----------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private String getDeployableXmlUrl(Class<?> clazz, String filename)
+   {
+      // Initialize
+      StringBuffer url = new StringBuffer();
+
+      // If the filename is specified
+      if (filename != null)
+      {
+         // Assemble filename in form "packagename.filename"
+         url.append(clazz.getClass().getPackage().toString());
+         url.append('.');
+         url.append(filename);
+      }
+      // Use default filename for the test class
+      else
+      {
+         // Assemble filename in form "fullyQualifiedClassName"
+         url.append(clazz.getName());
+      }
+
+      // Make a String
+      String flatten = url.toString();
+
+      // Adjust for filename structure instead of package structure
+      flatten = flatten.replace('.', '/');
+
+      // Append Suffix
+      flatten = flatten + EmbeddedTestMcBootstrap.DEFAULT_SUFFIX_DEPLOYABLE_XML;
+
+      // Return
+      return flatten;
+   }
+
+   private URL getResource(ClassLoader cl, String resource)
+   {
+      // Ensure specified
+      assert cl != null : "Specified " + ClassLoader.class.getSimpleName() + " is null";
+      assert resource != null && !resource.equals("") : "Resource must be specified";
+
+      // Obtain URL
+      URL url = cl.getResource(resource);
+      if (url == null)
+      {
+         throw new RuntimeException("Resource \"" + resource + "\" could not be obtained from current classloader");
+      }
+      return url;
+   }
+}

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/MockSessionProxyFactory.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/MockSessionProxyFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/MockSessionProxyFactory.java	2008-05-13 06:05:25 UTC (rev 73327)
@@ -0,0 +1,92 @@
+/*
+ * 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.proxy.common.registry;
+
+import org.jboss.ejb3.proxy.factory.session.SessionProxyFactory;
+
+/**
+ * MockSessionProxyFactory
+ *
+ * A Mock Session Proxy Factory for use in testing
+ * the Proxy Factory Registry only
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MockSessionProxyFactory implements SessionProxyFactory
+{
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.proxy.factory.session.SessionProxyFactory#createProxyBusiness()
+    */
+   public Object createProxyBusiness()
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.proxy.factory.session.SessionProxyFactory#createProxyBusiness(java.lang.String)
+    */
+   public Object createProxyBusiness(String businessInterfaceName)
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.proxy.factory.session.SessionProxyFactory#createProxyBusinessAndHome()
+    */
+   public Object createProxyBusinessAndHome()
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.proxy.factory.session.SessionProxyFactory#createProxyHome()
+    */
+   public Object createProxyHome()
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.proxy.factory.ProxyFactory#start()
+    */
+   public void start() throws Exception
+   {
+      // TODO Auto-generated method stub
+
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.proxy.factory.ProxyFactory#stop()
+    */
+   public void stop() throws Exception
+   {
+      // TODO Auto-generated method stub
+
+   }
+
+}

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/ProxyFactoryRegistryUnitTestCaseBase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/ProxyFactoryRegistryUnitTestCaseBase.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/ProxyFactoryRegistryUnitTestCaseBase.java	2008-05-13 06:05:25 UTC (rev 73327)
@@ -0,0 +1,378 @@
+/*
+ * 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.proxy.common.registry;
+
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.ejb3.proxy.factory.ProxyFactory;
+import org.jboss.ejb3.proxy.spi.registry.ProxyFactoryAlreadyRegisteredException;
+import org.jboss.ejb3.proxy.spi.registry.ProxyFactoryNotRegisteredException;
+import org.jboss.ejb3.proxy.spi.registry.ProxyFactoryRegistry;
+import org.jboss.ejb3.test.proxy.common.EmbeddedTestMcBootstrap;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * ProxyFactoryRegistryUnitTestCaseBase
+ * 
+ * Base upon which Proxy Factory Registry tests may build
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class ProxyFactoryRegistryUnitTestCaseBase
+{
+
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(ProxyFactoryRegistryUnitTestCaseBase.class);
+
+   public static final String MC_BEAN_NAME_PROXY_FACTORY_REGISTRY = "org.jboss.ejb3.ProxyFactoryRegistry";
+
+   private static final String REGISTRY_KEY_PREFIX = "TestRegistrationKey-";
+
+   private static EmbeddedTestMcBootstrap bootstrap;
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Tests that the Registry was successfully installed by performing a lookup
+    * via MC.
+    */
+   @Test
+   public void testJndiProxyFactoryRegistryInstall()
+   {
+      ProxyFactoryRegistry registry = this.getProxyFactoryRegistry();
+      TestCase.assertNotNull(registry);
+   }
+
+   /**
+    * Tests that a Proxy Factory may be registered and looked up, a 
+    * full round trip.  The object obtained from the registry must be 
+    * referencially equal to the object registered.
+    */
+   @Test
+   public void testRegistrationAndLookup()
+   {
+      // Initialize
+      String key = ProxyFactoryRegistryUnitTestCaseBase.REGISTRY_KEY_PREFIX + UUID.randomUUID();
+
+      // Create a new Proxy Factory
+      ProxyFactory factory = this.createMockProxyFactory();
+
+      // Get the registry
+      ProxyFactoryRegistry registry = this.getProxyFactoryRegistry();
+
+      // Lookup (Should Fail)
+      try
+      {
+         Object obj = registry.getProxyFactory(key);
+         TestCase.fail("Obtaining Proxy Factory " + obj + " under key " + key + " should have failed with "
+               + ProxyFactoryNotRegisteredException.class.getName());
+      }
+      catch (ProxyFactoryNotRegisteredException e)
+      {
+         log.info("As expected, registry does not yet contain key " + key);
+      }
+
+      // Register
+      try
+      {
+         registry.registerProxyFactory(key, factory);
+         log.info(factory + " stored into " + registry + " under key " + key);
+      }
+      catch (ProxyFactoryAlreadyRegisteredException e)
+      {
+         log.error(e);
+         TestCase.fail(factory + " should be able to be registered with " + registry + " under key " + key);
+      }
+
+      // Lookup
+      ProxyFactory lookup = null;
+      try
+      {
+         lookup = registry.getProxyFactory(key);
+         log.info(lookup + " obtained from  " + registry + " under key " + key);
+      }
+      catch (ProxyFactoryNotRegisteredException e)
+      {
+         log.error(e);
+         TestCase.fail(factory + " should have been found in " + registry + " under key " + key + ", but instead "
+               + e.getClass().getName() + " was encountered with message:\n" + e.getMessage());
+      }
+
+      // Ensure the factory looked up references the same object as the one placed in
+      TestCase.assertTrue("The factory obtained from the registry, " + lookup
+            + ", is not the same as the factory put in, " + factory, factory == lookup);
+   }
+
+   /**
+    * Tests that a Proxy Factory may be registered and deregistered, 
+    * checking along the way that testing that "isRegistered" works
+    * as expected
+    */
+   @Test
+   public void testRegistrationAndDeregistration()
+   {
+      // Initialize
+      String key = ProxyFactoryRegistryUnitTestCaseBase.REGISTRY_KEY_PREFIX + UUID.randomUUID();
+
+      // Create a new Proxy Factory
+      ProxyFactory factory = this.createMockProxyFactory();
+
+      // Get the registry
+      ProxyFactoryRegistry registry = this.getProxyFactoryRegistry();
+
+      // Ensure Proxy Factory is not registered
+      TestCase.assertEquals("Key " + key + " should not be registered yet in " + registry, false, registry
+            .isRegistered(key));
+
+      // Register
+      try
+      {
+         registry.registerProxyFactory(key, factory);
+         log.info(factory + " stored into " + registry + " under key " + key);
+      }
+      catch (ProxyFactoryAlreadyRegisteredException e)
+      {
+         log.error(e);
+         TestCase.fail(factory + " should be able to be registered with " + registry + " under key " + key);
+      }
+
+      // Ensure Proxy Factory is Registered
+      TestCase.assertTrue("Registry " + registry + " should contain " + factory + " under key " + key
+            + " but does not appear as registered", registry.isRegistered(key));
+
+      // Deregister
+      try
+      {
+         registry.deregisterProxyFactory(key);
+      }
+      catch (ProxyFactoryNotRegisteredException e)
+      {
+         log.error(e);
+         TestCase.fail("Key " + key + " should have been valid for registry " + registry
+               + ", but could not be deregistered.");
+      }
+
+      // Ensure Proxy Factory is no longer registered
+      TestCase.assertEquals("Key " + key + " for registry " + registry
+            + " has been deregistered, but has come up as registered", false, registry.isRegistered(key));
+
+   }
+
+   /**
+    * Tests that doubly-registering under the same key 
+    * fails as expected
+    */
+   @Test
+   public void testDuplicateKeyRegistrationFails()
+   {
+      // Initialize
+      String key = ProxyFactoryRegistryUnitTestCaseBase.REGISTRY_KEY_PREFIX + UUID.randomUUID();
+
+      // Create new Proxy Factories
+      ProxyFactory factory1 = this.createMockProxyFactory();
+      ProxyFactory factory2 = this.createMockProxyFactory();
+
+      // Get the registry
+      ProxyFactoryRegistry registry = this.getProxyFactoryRegistry();
+
+      // Register 1
+      try
+      {
+         registry.registerProxyFactory(key, factory1);
+         log.info(factory1 + " stored into " + registry + " under key " + key);
+      }
+      catch (ProxyFactoryAlreadyRegisteredException e)
+      {
+         log.error(e);
+         TestCase.fail(factory1 + " should be able to be registered with " + registry + " under key " + key);
+      }
+
+      // Register 2
+      try
+      {
+         registry.registerProxyFactory(key, factory2);
+      }
+      // Expected
+      catch (ProxyFactoryAlreadyRegisteredException e)
+      {
+         log.info(factory2 + " could not be stored into " + registry + " under key " + key
+               + " as expected because of duplicate key");
+         return;
+      }
+
+      // Not not be reached
+      TestCase.fail("Registry " + registry + " should not be able to register factories under the same key, " + key
+            + ", twice");
+   }
+
+   /**
+    * Tests that the same factory may be registered under
+    * 2 different keys
+    */
+   @Test
+   public void testDuplicateFactoryRegistrationOK()
+   {
+      // Initialize
+      String key1 = ProxyFactoryRegistryUnitTestCaseBase.REGISTRY_KEY_PREFIX + UUID.randomUUID();
+      String key2 = ProxyFactoryRegistryUnitTestCaseBase.REGISTRY_KEY_PREFIX + UUID.randomUUID();
+
+      // Create Proxy Factory
+      ProxyFactory factory = this.createMockProxyFactory();
+
+      // Get the registry
+      ProxyFactoryRegistry registry = this.getProxyFactoryRegistry();
+
+      // Register with key 1
+      try
+      {
+         registry.registerProxyFactory(key1, factory);
+         log.info(factory + " stored into " + registry + " under key " + key1);
+      }
+      catch (ProxyFactoryAlreadyRegisteredException e)
+      {
+         log.error(e);
+         TestCase.fail(factory + " should be able to be registered with " + registry + " under key " + key1);
+      }
+
+      // Register 2
+      try
+      {
+         registry.registerProxyFactory(key2, factory);
+      }
+      catch (ProxyFactoryAlreadyRegisteredException e)
+      {
+         log.error(e);
+         TestCase.fail(factory + " should be able to be registered with " + registry + " under key " + key2);
+      }
+
+      // Lookup 1
+      ProxyFactory lookup1 = null;
+      try
+      {
+         lookup1 = registry.getProxyFactory(key1);
+         log.info(lookup1 + " obtained from  " + registry + " under key " + key1);
+      }
+      catch (ProxyFactoryNotRegisteredException e)
+      {
+         log.error(e);
+         TestCase.fail(factory + " should have been found in " + registry + " under key " + key1 + ", but instead "
+               + e.getClass().getName() + " was encountered with message:\n" + e.getMessage());
+      }
+
+      // Lookup 2
+      ProxyFactory lookup2 = null;
+      try
+      {
+         lookup2 = registry.getProxyFactory(key2);
+         log.info(lookup2 + " obtained from  " + registry + " under key " + key2);
+      }
+      catch (ProxyFactoryNotRegisteredException e)
+      {
+         log.error(e);
+         TestCase.fail(factory + " should have been found in " + registry + " under key " + key2 + ", but instead "
+               + e.getClass().getName() + " was encountered with message:\n" + e.getMessage());
+      }
+
+      // Ensure all factories are equal
+      String message = "Object placed in registry should be equal to object obtained from lookup";
+      TestCase.assertTrue(message, factory == lookup1);
+      TestCase.assertTrue(message, lookup1 == lookup2); // Transitive (if A==B && B==C then A==C)
+
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Helper Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the ProxyFactoryRegistry from the MC
+    */
+   private ProxyFactoryRegistry getProxyFactoryRegistry()
+   {
+      ControllerContext context = ProxyFactoryRegistryUnitTestCaseBase.getBootstrap().getKernel().getController()
+            .getInstalledContext(ProxyFactoryRegistryUnitTestCaseBase.MC_BEAN_NAME_PROXY_FACTORY_REGISTRY);
+      ProxyFactoryRegistry registry = (ProxyFactoryRegistry) context.getTarget();
+      return registry;
+   }
+
+   /**
+    * Creates and returns a new Mock ProxyFactory
+    * @return
+    */
+   private ProxyFactory createMockProxyFactory()
+   {
+      return new MockSessionProxyFactory();
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   @BeforeClass
+   public static void beforeClass()
+   {
+      // Create and set a new MC Bootstrap
+      ProxyFactoryRegistryUnitTestCaseBase.setBootstrap(EmbeddedTestMcBootstrap.createEmbeddedMcBootstrap());
+   }
+
+   @Before
+   public void beforeTest() throws Exception
+   {
+      // Deploy the default MC XML
+      ProxyFactoryRegistryUnitTestCaseBase.getBootstrap().deploy(this.getClass());
+   }
+
+   @After
+   public void afterTest() throws Exception
+   {
+      // Undeploy the default MC XML
+      ProxyFactoryRegistryUnitTestCaseBase.getBootstrap().undeploy(this.getClass());
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Accessors / Mutators -----------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   public static EmbeddedTestMcBootstrap getBootstrap()
+   {
+      return ProxyFactoryRegistryUnitTestCaseBase.bootstrap;
+   }
+
+   public static void setBootstrap(EmbeddedTestMcBootstrap bootstrap)
+   {
+      ProxyFactoryRegistryUnitTestCaseBase.bootstrap = bootstrap;
+   }
+
+}

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/unit/InMemoryProxyFactoryRegistryUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/unit/InMemoryProxyFactoryRegistryUnitTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/unit/InMemoryProxyFactoryRegistryUnitTestCase.java	2008-05-13 06:05:25 UTC (rev 73327)
@@ -0,0 +1,61 @@
+/*
+ * 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.proxy.plugin.inmemory.registry.unit;
+
+import org.jboss.ejb3.test.proxy.common.registry.ProxyFactoryRegistryUnitTestCaseBase;
+import org.jboss.logging.Logger;
+
+/**
+ * JndiProxyFactoryRegistryUnitTestCase
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class InMemoryProxyFactoryRegistryUnitTestCase extends ProxyFactoryRegistryUnitTestCaseBase
+{
+
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(InMemoryProxyFactoryRegistryUnitTestCase.class);
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   @Override
+   public void beforeTest() throws Exception
+   {
+      super.beforeTest();
+   }
+
+   @Override
+   public void afterTest() throws Exception
+   {
+      super.afterTest();
+   }
+}

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/jndi/registry/unit/JndiProxyFactoryRegistryUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/jndi/registry/unit/JndiProxyFactoryRegistryUnitTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/plugin/jndi/registry/unit/JndiProxyFactoryRegistryUnitTestCase.java	2008-05-13 06:05:25 UTC (rev 73327)
@@ -0,0 +1,62 @@
+/*
+ * 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.proxy.plugin.jndi.registry.unit;
+
+import org.jboss.ejb3.test.proxy.common.registry.ProxyFactoryRegistryUnitTestCaseBase;
+import org.jboss.logging.Logger;
+
+/**
+ * JndiProxyFactoryRegistryUnitTestCase
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class JndiProxyFactoryRegistryUnitTestCase extends ProxyFactoryRegistryUnitTestCaseBase
+{
+
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(JndiProxyFactoryRegistryUnitTestCase.class);
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   @Override
+   public void beforeTest() throws Exception
+   {
+      super.beforeTest();
+   }
+
+   @Override
+   public void afterTest() throws Exception
+   {
+      super.afterTest();
+   }
+
+}

Added: projects/ejb3/trunk/proxy/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/log4j.xml	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/resources/log4j.xml	2008-05-13 06:05:25 UTC (rev 73327)
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!--                                                                       -->
+<!--  Log4j Configuration                                                  -->
+<!--                                                                       -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 68671 2008-01-08 10:04:25Z wolfc $ -->
+
+<!--
+   | For more configuration infromation and examples see the Jakarta Log4j
+   | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+  <!-- ================================= -->
+  <!-- Preserve messages in a local file -->
+  <!-- ================================= -->
+
+  <!-- A time/date based rolling appender -->
+  <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
+    <param name="File" value="target/test.log"/>
+    <param name="Threshold" value="INFO"/>
+    <param name="Append" value="false"/>
+
+    <!-- Rollover at midnight each day -->
+    <param name="DatePattern" value="'.'yyyy-MM-dd"/>
+
+    <!-- Rollover at the top of each hour
+    <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
+    -->
+
+    <layout class="org.apache.log4j.PatternLayout">
+      <!-- The default pattern: Date Priority [Category] Message\n -->
+      <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+
+      <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
+      <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+       -->
+    </layout>	    
+  </appender>
+
+  <!-- ============================== -->
+  <!-- Append messages to the console -->
+  <!-- ============================== -->
+
+  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out"/>
+
+    <layout class="org.apache.log4j.PatternLayout">
+      <!-- The default pattern: Date Priority [Category] Message\n -->
+      <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+    </layout>
+  </appender>
+
+
+  <!-- ================ -->
+  <!-- Limit categories -->
+  <!-- ================ -->
+  
+  <category name="org.jboss">
+    <priority value="INFO"/>
+  </category>
+  
+  <category name="org.jboss.ejb3.test.proxy">
+    <priority value="ALL"/>
+  </category>
+  
+  <category name="org.jboss.ejb3.proxy">
+    <priority value="ALL"/>
+  </category>
+  
+  <!-- ======================= -->
+  <!-- Setup the Root category -->
+  <!-- ======================= -->
+
+  <root>
+    <appender-ref ref="CONSOLE"/>
+    <appender-ref ref="FILE"/>
+  </root>
+  
+</log4j:configuration>

Added: projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/unit/InMemoryProxyFactoryRegistryUnitTestCase-beans.xml
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/unit/InMemoryProxyFactoryRegistryUnitTestCase-beans.xml	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/inmemory/registry/unit/InMemoryProxyFactoryRegistryUnitTestCase-beans.xml	2008-05-13 06:05:25 UTC (rev 73327)
@@ -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.ProxyFactoryRegistry" class="org.jboss.ejb3.proxy.plugin.inmemory.registry.InMemoryProxyFactoryRegistry" />
+
+</deployment>
+

Added: projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/jndi/registry/unit/JndiProxyFactoryRegistryUnitTestCase-beans.xml
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/jndi/registry/unit/JndiProxyFactoryRegistryUnitTestCase-beans.xml	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/plugin/jndi/registry/unit/JndiProxyFactoryRegistryUnitTestCase-beans.xml	2008-05-13 06:05:25 UTC (rev 73327)
@@ -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.ProxyFactoryRegistry" class="org.jboss.ejb3.proxy.plugin.jndi.registry.JndiProxyFactoryRegistry" />
+
+</deployment>
+




More information about the jboss-cvs-commits mailing list