Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySFSBean.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySFSBean.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySFSBean.java (revision 0)
@@ -0,0 +1,33 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+/**
+ *
+ * MySFSBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+@Stateful
+@Remote (MyStatefulRemote.class)
+@Local (MyStatefulLocal.class)
+public class MySFSBean implements MyStatefulLocal, MyStatefulRemote
+{
+
+ /**
+ *
+ */
+ private int current = 0;
+
+ /**
+ * @see {@link MyStateful#getNextInt()}
+ */
+ public int getNextInt()
+ {
+ return current ++;
+ }
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulLocal.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulLocal.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulLocal.java (revision 0)
@@ -0,0 +1,13 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyStatefulLocal
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStatefulLocal extends MyStateful
+{
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessLocal.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessLocal.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessLocal.java (revision 0)
@@ -0,0 +1,13 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyAppLocal
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStatelessLocal extends MyStateless
+{
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulRemote.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulRemote.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulRemote.java (revision 0)
@@ -0,0 +1,13 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyStatefulRemote
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStatefulRemote extends MyStateful
+{
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessRemote.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessRemote.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessRemote.java (revision 0)
@@ -0,0 +1,13 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyStatelessRemote
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStatelessRemote extends MyStateless
+{
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySLSBean.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySLSBean.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySLSBean.java (revision 0)
@@ -0,0 +1,32 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import org.jboss.logging.Logger;
+
+/**
+ *
+ * MyStatelessBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+@Stateless
+@Local(MyStatelessLocal.class)
+@Remote(MyStatelessRemote.class)
+public class MySLSBean implements MyStatelessLocal, MyStatelessRemote
+{
+ /**
+ * Instance of logger
+ */
+ private static Logger logger = Logger.getLogger(MySLSBean.class);
+
+ public String getVersion()
+ {
+ return "1.0";
+ }
+
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateful.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateful.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateful.java (revision 0)
@@ -0,0 +1,19 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyStateful
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStateful
+{
+
+ /**
+ * Just a test method returning a counter value
+ *
+ * @return Return the next int
+ */
+ public int getNextInt();
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateless.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateless.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateless.java (revision 0)
@@ -0,0 +1,15 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyStateless
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStateless
+{
+ public String getVersion();
+
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySFSBean.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySFSBean.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySFSBean.java (revision 0)
@@ -0,0 +1,33 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+/**
+ *
+ * MySFSBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+@Stateful
+@Remote (MyStatefulRemote.class)
+@Local (MyStatefulLocal.class)
+public class MySFSBean implements MyStatefulLocal, MyStatefulRemote
+{
+
+ /**
+ *
+ */
+ private int current = 0;
+
+ /**
+ * @see {@link MyStateful#getNextInt()}
+ */
+ public int getNextInt()
+ {
+ return current ++;
+ }
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySLSBean.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySLSBean.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MySLSBean.java (revision 0)
@@ -0,0 +1,32 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import org.jboss.logging.Logger;
+
+/**
+ *
+ * MyStatelessBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+@Stateless
+@Local(MyStatelessLocal.class)
+@Remote(MyStatelessRemote.class)
+public class MySLSBean implements MyStatelessLocal, MyStatelessRemote
+{
+ /**
+ * Instance of logger
+ */
+ private static Logger logger = Logger.getLogger(MySLSBean.class);
+
+ public String getVersion()
+ {
+ return "1.0";
+ }
+
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateful.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateful.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateful.java (revision 0)
@@ -0,0 +1,19 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyStateful
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStateful
+{
+
+ /**
+ * Just a test method returning a counter value
+ *
+ * @return Return the next int
+ */
+ public int getNextInt();
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulLocal.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulLocal.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulLocal.java (revision 0)
@@ -0,0 +1,13 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyStatefulLocal
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStatefulLocal extends MyStateful
+{
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulRemote.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulRemote.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatefulRemote.java (revision 0)
@@ -0,0 +1,13 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyStatefulRemote
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStatefulRemote extends MyStateful
+{
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateless.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateless.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStateless.java (revision 0)
@@ -0,0 +1,15 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyStateless
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStateless
+{
+ public String getVersion();
+
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessLocal.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessLocal.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessLocal.java (revision 0)
@@ -0,0 +1,13 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyAppLocal
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStatelessLocal extends MyStateless
+{
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessRemote.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessRemote.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/MyStatelessRemote.java (revision 0)
@@ -0,0 +1,13 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar;
+
+/**
+ *
+ * MyStatelessRemote
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStatelessRemote extends MyStateless
+{
+
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase.java (revision 0)
@@ -0,0 +1,249 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar.unit;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+
+import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.proxy.jndiregistrar.JndiStatelessSessionRegistrar;
+import org.jboss.ejb3.test.mc.bootstrap.EmbeddedTestMcBootstrap;
+import org.jboss.ejb3.test.proxy.common.Utils;
+import org.jboss.ejb3.test.proxy.common.container.StatefulContainer;
+import org.jboss.ejb3.test.proxy.common.container.StatelessContainer;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MySFSBean;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MySLSBean;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MyStatefulLocal;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MyStatefulRemote;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MyStatelessLocal;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MyStatelessRemote;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * JndiSessionRegistrarBaseTestCase
+ *
+ * Tests for {@link JndiStatelessSessionRegistrar}
+ *
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class JndiSessionRegistrarBaseTestCase
+{
+
+ /**
+ * Bootstrap
+ */
+ private static EmbeddedTestMcBootstrap bootstrap;
+
+ /**
+ * Instance of logger
+ */
+ private static Logger logger = Logger.getLogger(JndiSessionRegistrarBaseTestCase.class);
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Throwable
+ {
+ bootstrap = new EmbeddedTestMcBootstrap();
+ bootstrap.run();
+
+ // Bind the Registrar
+ Ejb3RegistrarLocator.bindRegistrar(new Ejb3McRegistrar(bootstrap.getKernel()));
+
+ bootstrap.deploy(JndiSessionRegistrarBaseTestCase.class);
+
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Throwable
+ {
+ if (bootstrap != null)
+ bootstrap.shutdown();
+ bootstrap = null;
+ }
+
+ /**
+ * Test that the SLSB bean is unbound from the jndi, after the
+ * {@link JndiStatelessSessionRegistrar#unbindEjb(Context, org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData)}
+ * is called.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testUnbindEjbForSLSB() throws Throwable
+ {
+ // create the bean
+ StatelessContainer statelessSessionContainer = Utils.createSlsb(MySLSBean.class);
+
+ // bind the bean to the jndi
+ Ejb3RegistrarLocator.locateRegistrar().bind(statelessSessionContainer.getName(), statelessSessionContainer);
+
+ // lookup the bean to ensure its been bound to the jndi
+ Context ctx = new InitialContext();
+ MyStatelessRemote remote = (MyStatelessRemote) ctx.lookup(MySLSBean.class.getSimpleName() + "/remote");
+ logger.info("Lookup of remote SLSB returned " + remote);
+
+ assertNotNull("Failure - Lookup of remote SLSB returned null", remote);
+
+ assertTrue("Failure - Remote SLSB returned from lookup is NOT instance of " + MyStatelessRemote.class, (remote instanceof MyStatelessRemote));
+
+ MyStatelessLocal local = (MyStatelessLocal) ctx.lookup(MySLSBean.class.getSimpleName() + "/local");
+ logger.info("Lookup of local SLSB returned " + local);
+
+ assertNotNull("Failure - Lookup of local SLSB returned null", local);
+
+ assertTrue("Failure - Local SLSB returned from lookup is NOT instance of " + MyStatelessLocal.class, (local instanceof MyStatelessLocal));
+
+ // Now unbind the bean from the jndi
+ Ejb3RegistrarLocator.locateRegistrar().unbind(statelessSessionContainer.getName());
+ logger.debug("Unbound the SLSB");
+
+ // lookup the remote bean again, to ensure its unbound
+ try
+ {
+
+ Object obj = ctx.lookup(MySLSBean.class.getSimpleName() + "/remote");
+ fail("Failure - lookup returned object, even after the remote bean was un-bound " + obj);
+
+ }
+ catch (NameNotFoundException ne)
+ {
+ // NameNotFound indicates that the bean was successfully unbound
+ logger.debug("Remote SLSB has been successfully unbound from the JNDI");
+
+ }
+
+ // lookup the local bean again, to ensure its unbound
+ try
+ {
+ Object anotherObj = ctx.lookup(MySLSBean.class.getSimpleName() + "/local");
+ fail("Failure - lookup returned object,even after the local bean was un-bound " + anotherObj);
+ }
+ catch (NameNotFoundException ne)
+ {
+ // NameNotFound indicates that the bean was successfully unbound
+ logger.debug("Local SLSB has been successfully unbound from the JNDI");
+
+ }
+
+ }
+
+ /**
+ * Test that the {@link JndiStatelessSessionRegistrar#unbindEjb(Context, org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData)}
+ * unbinds only the object(s) related to the bean.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testUnbindEjbForNonEjbSpecificJNDIObjects() throws Throwable
+ {
+
+ // deploy the bean
+ StatelessContainer statelessSessionContainer = Utils.createSlsb(MySLSBean.class);
+
+ // bind in jndi
+ Ejb3RegistrarLocator.locateRegistrar().bind(statelessSessionContainer.getName(), statelessSessionContainer);
+
+ Context ctx = new InitialContext();
+ MyStatelessRemote remote = (MyStatelessRemote) ctx.lookup(MySLSBean.class.getSimpleName() + "/remote");
+
+ assertNotNull("Failure - Lookup of remote bean returned null", remote);
+
+ assertTrue("Failure - Remote bean returned from lookup is NOT instance of " + MyStatelessRemote.class, (remote instanceof MyStatelessRemote));
+
+ // Now bind to the JNDI, some object
+ ctx.bind("TestJndiName", "TestJndiObject");
+ // just a check to ensure the object was indeed bound
+ assertNotNull("Failure - could not bind object to JNDI",ctx.lookup("TestJndiName"));
+
+ // Now unbind the bean
+ Ejb3RegistrarLocator.locateRegistrar().unbind(statelessSessionContainer.getName());
+
+ try
+ {
+ // Now lookup the previously bound test string, to ensure that no other object was unbound from the JNDI, other than the bean
+ String test = (String) ctx.lookup("TestJndiName");
+
+ assertNotNull("Failure - Test string from JNDI is null ", test);
+
+ assertTrue("Failure - Test string was modified in JNDI ", test.equals("TestJndiObject"));
+
+ }
+ catch (NameNotFoundException ne)
+ {
+ fail("Failure - Object other than the bean was unbound " + ne.getMessage());
+ logger.error("Could not lookup test string in JNDI: ", ne);
+ }
+
+ }
+
+ /**
+ * Test that the SLSB bean is unbound from the jndi, after the
+ * {@link JndiStatelessSessionRegistrar#unbindEjb(Context, org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData)}
+ * is called.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testUnbindEjbForSFSB() throws Throwable
+ {
+ // create the SFSB container
+ StatefulContainer statefulSessionContainer = Utils.createSfsb(MySFSBean.class);
+
+ // bind the SFSB bean
+ Ejb3RegistrarLocator.locateRegistrar().bind(statefulSessionContainer.getName(), statefulSessionContainer);
+
+ Context ctx = new InitialContext();
+ // lookup remote sfsb
+ MyStatefulRemote remote = (MyStatefulRemote) ctx.lookup(MySFSBean.class.getSimpleName() + "/remote");
+ logger.info("Lookup of remote SFSB returned " + remote);
+
+ assertNotNull("Failure - Lookup of remote SFSB returned null", remote);
+
+ assertTrue("Failure - Remote SFSB returned from lookup is NOT instance of " + MyStatefulRemote.class, (remote instanceof MyStatefulRemote));
+
+ // lookup local
+ MyStatefulLocal local = (MyStatefulLocal) ctx.lookup(MySFSBean.class.getSimpleName() + "/local");
+ logger.info("Lookup of local SFSB returned " + local);
+
+ assertNotNull("Failure - Lookup of local SFSB returned null", local);
+
+ assertTrue("Failure - Local SFSB returned from lookup is NOT instance of " + MyStatefulLocal.class, (local instanceof MyStatefulLocal));
+
+ // Now unbind the bean from the jndi
+ Ejb3RegistrarLocator.locateRegistrar().unbind(statefulSessionContainer.getName());
+
+ logger.debug("Unbound the SFSB");
+
+ // test that the remote SFSB has been removed from the JNDI
+ try
+ {
+ Object obj = ctx.lookup(MySFSBean.class.getSimpleName() + "/remote");
+ fail("Failure - Lookup returned objected, even after remote SFSB was unbound: " + obj);
+ }
+ catch (NameNotFoundException ne)
+ {
+ logger.info("Successfully unbound remote SFSB");
+ }
+
+
+ // test that the local SFSB has been removed from the JNDI
+ try
+ {
+ Object obj = ctx.lookup(MySFSBean.class.getSimpleName() + "/local");
+ fail("Failure - Lookup returned objected, even after local SFSB was unbound: " + obj);
+ }
+ catch (NameNotFoundException ne)
+ {
+ logger.info("Successfully unbound local SFSB");
+ }
+
+ }
+}
Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase.java
===================================================================
--- proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase.java (revision 0)
+++ proxy/src/test/java/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase.java (revision 0)
@@ -0,0 +1,249 @@
+package org.jboss.ejb3.test.proxy.jndiregistrar.unit;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+
+import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.proxy.jndiregistrar.JndiStatelessSessionRegistrar;
+import org.jboss.ejb3.test.mc.bootstrap.EmbeddedTestMcBootstrap;
+import org.jboss.ejb3.test.proxy.common.Utils;
+import org.jboss.ejb3.test.proxy.common.container.StatefulContainer;
+import org.jboss.ejb3.test.proxy.common.container.StatelessContainer;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MySFSBean;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MySLSBean;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MyStatefulLocal;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MyStatefulRemote;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MyStatelessLocal;
+import org.jboss.ejb3.test.proxy.jndiregistrar.MyStatelessRemote;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * JndiSessionRegistrarBaseTestCase
+ *
+ * Tests for {@link JndiStatelessSessionRegistrar}
+ *
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class JndiSessionRegistrarBaseTestCase
+{
+
+ /**
+ * Bootstrap
+ */
+ private static EmbeddedTestMcBootstrap bootstrap;
+
+ /**
+ * Instance of logger
+ */
+ private static Logger logger = Logger.getLogger(JndiSessionRegistrarBaseTestCase.class);
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Throwable
+ {
+ bootstrap = new EmbeddedTestMcBootstrap();
+ bootstrap.run();
+
+ // Bind the Registrar
+ Ejb3RegistrarLocator.bindRegistrar(new Ejb3McRegistrar(bootstrap.getKernel()));
+
+ bootstrap.deploy(JndiSessionRegistrarBaseTestCase.class);
+
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Throwable
+ {
+ if (bootstrap != null)
+ bootstrap.shutdown();
+ bootstrap = null;
+ }
+
+ /**
+ * Test that the SLSB bean is unbound from the jndi, after the
+ * {@link JndiStatelessSessionRegistrar#unbindEjb(Context, org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData)}
+ * is called.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testUnbindEjbForSLSB() throws Throwable
+ {
+ // create the bean
+ StatelessContainer statelessSessionContainer = Utils.createSlsb(MySLSBean.class);
+
+ // bind the bean to the jndi
+ Ejb3RegistrarLocator.locateRegistrar().bind(statelessSessionContainer.getName(), statelessSessionContainer);
+
+ // lookup the bean to ensure its been bound to the jndi
+ Context ctx = new InitialContext();
+ MyStatelessRemote remote = (MyStatelessRemote) ctx.lookup(MySLSBean.class.getSimpleName() + "/remote");
+ logger.info("Lookup of remote SLSB returned " + remote);
+
+ assertNotNull("Failure - Lookup of remote SLSB returned null", remote);
+
+ assertTrue("Failure - Remote SLSB returned from lookup is NOT instance of " + MyStatelessRemote.class, (remote instanceof MyStatelessRemote));
+
+ MyStatelessLocal local = (MyStatelessLocal) ctx.lookup(MySLSBean.class.getSimpleName() + "/local");
+ logger.info("Lookup of local SLSB returned " + local);
+
+ assertNotNull("Failure - Lookup of local SLSB returned null", local);
+
+ assertTrue("Failure - Local SLSB returned from lookup is NOT instance of " + MyStatelessLocal.class, (local instanceof MyStatelessLocal));
+
+ // Now unbind the bean from the jndi
+ Ejb3RegistrarLocator.locateRegistrar().unbind(statelessSessionContainer.getName());
+ logger.debug("Unbound the SLSB");
+
+ // lookup the remote bean again, to ensure its unbound
+ try
+ {
+
+ Object obj = ctx.lookup(MySLSBean.class.getSimpleName() + "/remote");
+ fail("Failure - lookup returned object, even after the remote bean was un-bound " + obj);
+
+ }
+ catch (NameNotFoundException ne)
+ {
+ // NameNotFound indicates that the bean was successfully unbound
+ logger.debug("Remote SLSB has been successfully unbound from the JNDI");
+
+ }
+
+ // lookup the local bean again, to ensure its unbound
+ try
+ {
+ Object anotherObj = ctx.lookup(MySLSBean.class.getSimpleName() + "/local");
+ fail("Failure - lookup returned object,even after the local bean was un-bound " + anotherObj);
+ }
+ catch (NameNotFoundException ne)
+ {
+ // NameNotFound indicates that the bean was successfully unbound
+ logger.debug("Local SLSB has been successfully unbound from the JNDI");
+
+ }
+
+ }
+
+ /**
+ * Test that the {@link JndiStatelessSessionRegistrar#unbindEjb(Context, org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData)}
+ * unbinds only the object(s) related to the bean.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testUnbindEjbForNonEjbSpecificJNDIObjects() throws Throwable
+ {
+
+ // deploy the bean
+ StatelessContainer statelessSessionContainer = Utils.createSlsb(MySLSBean.class);
+
+ // bind in jndi
+ Ejb3RegistrarLocator.locateRegistrar().bind(statelessSessionContainer.getName(), statelessSessionContainer);
+
+ Context ctx = new InitialContext();
+ MyStatelessRemote remote = (MyStatelessRemote) ctx.lookup(MySLSBean.class.getSimpleName() + "/remote");
+
+ assertNotNull("Failure - Lookup of remote bean returned null", remote);
+
+ assertTrue("Failure - Remote bean returned from lookup is NOT instance of " + MyStatelessRemote.class, (remote instanceof MyStatelessRemote));
+
+ // Now bind to the JNDI, some object
+ ctx.bind("TestJndiName", "TestJndiObject");
+ // just a check to ensure the object was indeed bound
+ assertNotNull("Failure - could not bind object to JNDI",ctx.lookup("TestJndiName"));
+
+ // Now unbind the bean
+ Ejb3RegistrarLocator.locateRegistrar().unbind(statelessSessionContainer.getName());
+
+ try
+ {
+ // Now lookup the previously bound test string, to ensure that no other object was unbound from the JNDI, other than the bean
+ String test = (String) ctx.lookup("TestJndiName");
+
+ assertNotNull("Failure - Test string from JNDI is null ", test);
+
+ assertTrue("Failure - Test string was modified in JNDI ", test.equals("TestJndiObject"));
+
+ }
+ catch (NameNotFoundException ne)
+ {
+ fail("Failure - Object other than the bean was unbound " + ne.getMessage());
+ logger.error("Could not lookup test string in JNDI: ", ne);
+ }
+
+ }
+
+ /**
+ * Test that the SLSB bean is unbound from the jndi, after the
+ * {@link JndiStatelessSessionRegistrar#unbindEjb(Context, org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData)}
+ * is called.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testUnbindEjbForSFSB() throws Throwable
+ {
+ // create the SFSB container
+ StatefulContainer statefulSessionContainer = Utils.createSfsb(MySFSBean.class);
+
+ // bind the SFSB bean
+ Ejb3RegistrarLocator.locateRegistrar().bind(statefulSessionContainer.getName(), statefulSessionContainer);
+
+ Context ctx = new InitialContext();
+ // lookup remote sfsb
+ MyStatefulRemote remote = (MyStatefulRemote) ctx.lookup(MySFSBean.class.getSimpleName() + "/remote");
+ logger.info("Lookup of remote SFSB returned " + remote);
+
+ assertNotNull("Failure - Lookup of remote SFSB returned null", remote);
+
+ assertTrue("Failure - Remote SFSB returned from lookup is NOT instance of " + MyStatefulRemote.class, (remote instanceof MyStatefulRemote));
+
+ // lookup local
+ MyStatefulLocal local = (MyStatefulLocal) ctx.lookup(MySFSBean.class.getSimpleName() + "/local");
+ logger.info("Lookup of local SFSB returned " + local);
+
+ assertNotNull("Failure - Lookup of local SFSB returned null", local);
+
+ assertTrue("Failure - Local SFSB returned from lookup is NOT instance of " + MyStatefulLocal.class, (local instanceof MyStatefulLocal));
+
+ // Now unbind the bean from the jndi
+ Ejb3RegistrarLocator.locateRegistrar().unbind(statefulSessionContainer.getName());
+
+ logger.debug("Unbound the SFSB");
+
+ // test that the remote SFSB has been removed from the JNDI
+ try
+ {
+ Object obj = ctx.lookup(MySFSBean.class.getSimpleName() + "/remote");
+ fail("Failure - Lookup returned objected, even after remote SFSB was unbound: " + obj);
+ }
+ catch (NameNotFoundException ne)
+ {
+ logger.info("Successfully unbound remote SFSB");
+ }
+
+
+ // test that the local SFSB has been removed from the JNDI
+ try
+ {
+ Object obj = ctx.lookup(MySFSBean.class.getSimpleName() + "/local");
+ fail("Failure - Lookup returned objected, even after local SFSB was unbound: " + obj);
+ }
+ catch (NameNotFoundException ne)
+ {
+ logger.info("Successfully unbound local SFSB");
+ }
+
+ }
+}
Index: proxy/src/test/resources/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase-beans.xml
===================================================================
--- proxy/src/test/resources/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase-beans.xml (revision 0)
+++ proxy/src/test/resources/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase-beans.xml (revision 0)
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+ org.jboss.ejb3.proxy.objectfactory.session.stateless.StatelessSessionProxyObjectFactory
+
+
+ NameServer
+
+
+
+
+
+
+ org.jboss.ejb3.proxy.objectfactory.session.stateful.StatefulSessionProxyObjectFactory
+
+
+ NameServer
+
+
+
+
+
+
+
+
+
+
+
+
+
+ socket://0.0.0.0:3873
+
+
+
+
+
+
\ No newline at end of file
Index: proxy/src/test/resources/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase-beans.xml
===================================================================
--- proxy/src/test/resources/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase-beans.xml (revision 0)
+++ proxy/src/test/resources/org/jboss/ejb3/test/proxy/jndiregistrar/unit/JndiSessionRegistrarBaseTestCase-beans.xml (revision 0)
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+ org.jboss.ejb3.proxy.objectfactory.session.stateless.StatelessSessionProxyObjectFactory
+
+
+ NameServer
+
+
+
+
+
+
+ org.jboss.ejb3.proxy.objectfactory.session.stateful.StatefulSessionProxyObjectFactory
+
+
+ NameServer
+
+
+
+
+
+
+
+
+
+
+
+
+
+ socket://0.0.0.0:3873
+
+
+
+
+
+
\ No newline at end of file