[jboss-cvs] JBossAS SVN: r73366 - projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 13 16:43:17 EDT 2008
Author: ALRubinger
Date: 2008-05-13 16:43:17 -0400 (Tue, 13 May 2008)
New Revision: 73366
Added:
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/MockLifecycleSessionProxyFactory.java
Modified:
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/ProxyFactoryRegistryUnitTestCaseBase.java
Log:
[EJBTHREE-1345] Added tests for Registry invocation of ProxyFactory lifecycle methods
Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/MockLifecycleSessionProxyFactory.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/MockLifecycleSessionProxyFactory.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/MockLifecycleSessionProxyFactory.java 2008-05-13 20:43:17 UTC (rev 73366)
@@ -0,0 +1,137 @@
+/*
+ * 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;
+
+/**
+ * MockLifecycleSessionProxyFactory
+ *
+ * A Mock Session Proxy Factory for use in testing
+ * lifecycle method invocations of the Proxy Factory Registry only
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MockLifecycleSessionProxyFactory implements SessionProxyFactory
+{
+ // --------------------------------------------------------------------------------||
+ // Class Members -----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * The valid states for this Proxy Factory, to be set
+ * properly by the lifecycle methods
+ */
+ public enum State{
+ CREATED, STARTED, STOPPED
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private State state;
+
+ // --------------------------------------------------------------------------------||
+ // Constructors -------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public MockLifecycleSessionProxyFactory()
+ {
+ this.setState(State.CREATED);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Lifecycle Implementations ------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Lifecycle Start
+ */
+ public void start() throws Exception
+ {
+ this.setState(State.STARTED);
+ }
+
+ /**
+ * Lifecycle Stop
+ */
+ public void stop() throws Exception
+ {
+ this.setState(State.STOPPED);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Accessors / Mutators -----------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public State getState()
+ {
+ return state;
+ }
+
+ protected void setState(final State state)
+ {
+ this.state = state;
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Stubs --------------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /* (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;
+ }
+}
Modified: 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 2008-05-13 19:13:23 UTC (rev 73365)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/registry/ProxyFactoryRegistryUnitTestCaseBase.java 2008-05-13 20:43:17 UTC (rev 73366)
@@ -311,8 +311,68 @@
}
+ @Test
+ public void testRegistryInvokesProxyFactoryLifecycle() throws Throwable
+ {
+ // Initialize
+ String key = ProxyFactoryRegistryUnitTestCaseBase.REGISTRY_KEY_PREFIX + UUID.randomUUID();
+
+ // Create a new Proxy Factory
+ MockLifecycleSessionProxyFactory factory = new MockLifecycleSessionProxyFactory();
+
+ // Get the registry
+ ProxyFactoryRegistry registry = this.getProxyFactoryRegistry();
+
+ // Test Lifecycle Created
+ TestCase.assertEquals("Lifecycle of " + factory + " should be " + MockLifecycleSessionProxyFactory.State.CREATED
+ + " before registered", MockLifecycleSessionProxyFactory.State.CREATED, factory.getState());
+
+ // 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 reference looked up and the reference placed in have state of STARTED
+ TestCase.assertEquals("Lifecycle of " + lookup + " should be " + MockLifecycleSessionProxyFactory.State.STARTED
+ + " before registered", MockLifecycleSessionProxyFactory.State.STARTED,
+ MockLifecycleSessionProxyFactory.class.cast(lookup).getState());
+ TestCase.assertEquals("Lifecycle of " + factory + " should be " + MockLifecycleSessionProxyFactory.State.STARTED
+ + " before registered", MockLifecycleSessionProxyFactory.State.STARTED, factory.getState());
+
+ // Deregister
+ registry.deregisterProxyFactory(key);
+
+ // Ensure the reference looked up and the reference placed in have state of STOPPED
+ TestCase.assertEquals("Lifecycle of " + lookup + " should be " + MockLifecycleSessionProxyFactory.State.STOPPED
+ + " before registered", MockLifecycleSessionProxyFactory.State.STOPPED,
+ MockLifecycleSessionProxyFactory.class.cast(lookup).getState());
+ TestCase.assertEquals("Lifecycle of " + factory + " should be " + MockLifecycleSessionProxyFactory.State.STOPPED
+ + " before registered", MockLifecycleSessionProxyFactory.State.STOPPED, factory.getState());
+ }
+
// --------------------------------------------------------------------------------||
- // Helper Methods --------------------------------------------------------------||
+ // Helper Methods -----------------------------------------------------------------||
// --------------------------------------------------------------------------------||
/**
@@ -320,7 +380,8 @@
*/
private ProxyFactoryRegistry getProxyFactoryRegistry() throws Throwable
{
- ProxyFactoryRegistry registry = ProxyFactoryRegistryUnitTestCaseBase.getBootstrap().lookup(ProxyFactoryRegistryUnitTestCaseBase.MC_BEAN_NAME_PROXY_FACTORY_REGISTRY, ProxyFactoryRegistry.class);
+ ProxyFactoryRegistry registry = ProxyFactoryRegistryUnitTestCaseBase.getBootstrap().lookup(
+ ProxyFactoryRegistryUnitTestCaseBase.MC_BEAN_NAME_PROXY_FACTORY_REGISTRY, ProxyFactoryRegistry.class);
return registry;
}
More information about the jboss-cvs-commits
mailing list