Index: build/pom.xml =================================================================== --- build/pom.xml (revision 76285) +++ build/pom.xml (working copy) @@ -296,7 +296,7 @@ org.jboss.metadata jboss-metadata - 1.0.0.Beta31 + 1.0.0.Beta32 Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase.java =================================================================== --- proxy/src/test/java/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase.java (revision 0) +++ proxy/src/test/java/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase.java (revision 0) @@ -0,0 +1,441 @@ +/* + * 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.binding.unit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Iterator; +import java.util.List; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import org.jboss.ejb3.annotation.LocalBinding; +import org.jboss.ejb3.annotation.LocalHomeBinding; +import org.jboss.ejb3.annotation.RemoteBinding; +import org.jboss.ejb3.annotation.RemoteHomeBinding; +import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar; +import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator; +import org.jboss.ejb3.common.registrar.spi.NotBoundException; +import org.jboss.ejb3.test.mc.bootstrap.EmbeddedTestMcBootstrap; +import org.jboss.ejb3.test.proxy.common.Utils; +import org.jboss.ejb3.test.proxy.common.container.SessionContainer; +import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulBeanWithBindings; +import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulLocalBusiness; +import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulLocalHome; +import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulRemoteBusiness; +import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulRemoteHome; +import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessBeanWithBindings; +import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessLocal; +import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessLocalHome; +import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessRemote; +import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessRemoteHome; +import org.jboss.logging.Logger; +import org.jboss.metadata.ejb.jboss.RemoteBindingMetaData; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * JNDIBindingTestCase + * + * Test that the @RemoteBinding @RemoteHomeBinding @LocalBinding + * @LocalHomeBinding and @RemoteBindings work as expected. + * https://jira.jboss.org/jira/browse/EJBTHREE-1423 + * + * + * @author Jaikiran Pai + * @version $Revision: $ + */ +public class JNDIBindingTestCase +{ + + /** + * Bootstrap + */ + private static EmbeddedTestMcBootstrap bootstrap; + + /** + * Instance of logger + */ + private static Logger logger = Logger.getLogger(JNDIBindingTestCase.class); + + /** + * {@link SessionContainer} + */ + private SessionContainer sessionContainer; + + /** + * Start the necessary services + * + * @throws Throwable + */ + @BeforeClass + public static void setUpBeforeClass() throws Throwable + { + bootstrap = new EmbeddedTestMcBootstrap(); + bootstrap.run(); + + // Bind the Registrar + Ejb3RegistrarLocator.bindRegistrar(new Ejb3McRegistrar(bootstrap.getKernel())); + + // Reads a xml configuration to deploy the necessary services + bootstrap.deploy(JNDIBindingTestCase.class); + } + + /** + * Shutdown the services + * + * @throws Throwable + */ + @AfterClass + public static void tearDownAfterClass() throws Throwable + { + if (bootstrap != null) + { + bootstrap.shutdown(); + } + bootstrap = null; + } + + /** + * This method takes care of any cleanup required after each test. + */ + @After + public void cleanupAfterEachTest() + { + // Unbind the beans + if (sessionContainer != null) + { + logger.info("Unbinding: " + sessionContainer.getName()); + try + { + Ejb3RegistrarLocator.locateRegistrar().unbind(sessionContainer.getName()); + } + catch (NotBoundException nbe) + { + // we are ok with this exception, which indicates that the test case had + // already unbound the ejb related bindings. + logger.debug(sessionContainer.getName() + " was already unbound"); + + } + } + + } + + /** + * Test that the {@link RemoteBinding} is honoured for SLSB + * + * @throws Throwable + */ + @Test + public void testRemoteBindingForSlsb() throws Throwable + { + // create the bean + this.sessionContainer = Utils.createSlsb(MyStatelessBeanWithBindings.class); + + // bind it to JNDI + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + List remoteBindingsMetadata = sessionContainer.getMetaData().getRemoteBindings(); + + assertNotNull("No RemoteBindingMetadata available", remoteBindingsMetadata); + // make sure that the remotebinding metadata list has 1 @RemoteBinding information + assertEquals("RemoteBindingMetadata does not have any RemoteBinding information available", remoteBindingsMetadata.size(), 1); + + // Ensure that the RemoteBindingMetaData is created properly with the specified jndiBinding name. + Iterator remoteBindingsMetadataIterator = remoteBindingsMetadata.iterator(); + RemoteBindingMetaData remoteBindingMetadata = remoteBindingsMetadataIterator.next(); + + assertEquals("RemoteBinding JNDI name does not match " + MyStatelessBeanWithBindings.REMOTE_JNDI_NAME, MyStatelessBeanWithBindings.REMOTE_JNDI_NAME, remoteBindingMetadata + .getJndiName()); + + // Now ensure that the RemoteBindingMetaData is used for binding the + // remote interface of the bean. + Context ctx = new InitialContext(); + Object remoteBean = ctx.lookup(remoteBindingMetadata.getJndiName()); + logger.info("Object is : " + remoteBean); + assertNotNull("Remote bean returned from JNDI lookup is null", remoteBean); + assertTrue("Remote bean returned from JNDI lookup is NOT an instance of " + MyStatelessRemote.class, (remoteBean instanceof MyStatelessRemote)); + + } + + /** + * Test that the {@link LocalBinding} is honoured for SLSB + * + * @throws Throwable + */ + @Test + public void testLocalBindingForSlsb() throws Throwable + { + //create the bean + this.sessionContainer = Utils.createSlsb(MyStatelessBeanWithBindings.class); + + //bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + // Ensure that the local jndi name is set to the @LocalBinding value + String localJndiName = sessionContainer.getMetaData().getLocalJndiName(); + + assertNotNull("Local jndi name is null", localJndiName); + assertEquals("Local jndi name does not match the jndiBinding value specified in @LocalBinding", MyStatelessBeanWithBindings.LOCAL_JNDI_NAME, localJndiName); + + // Lookup using the local jndi name and check that the Local object is bound in the JNDI + Context ctx = new InitialContext(); + Object local = ctx.lookup(localJndiName); + + assertNotNull("Local object bound to JNDI is null", local); + assertTrue("Object bound to local JNDI name is NOT an instance of " + MyStatelessLocal.class, (local instanceof MyStatelessLocal)); + + } + + /** + * Test that the {@link LocalHomeBinding} is honoured for SLSB + * + * @throws Throwable + */ + @Test + public void testLocalHomeBindingForSlsb() throws Throwable + { + // create bean + this.sessionContainer = Utils.createSlsb(MyStatelessBeanWithBindings.class); + + // bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + // Ensure that the localhome jndi name is set to the @LocalHomeBinding value + String localHomeJndiName = sessionContainer.getMetaData().getLocalHomeJndiName(); + + assertNotNull("Local home jndi name is null", localHomeJndiName); + assertEquals("Local home jndi name does not match the jndiBinding value specified in @LocalHomeBinding", MyStatelessBeanWithBindings.LOCAL_HOME_JNDI_NAME, localHomeJndiName); + + // lookup using the localhome jndi name and ensure the localhome is bound to this name + Context ctx = new InitialContext(); + Object localHome = ctx.lookup(localHomeJndiName); + + assertNotNull("Local home is null",localHome); + assertTrue("Local home is not an instance of " + MyStatelessLocalHome.class, (localHome instanceof MyStatelessLocalHome)); + + } + + /** + * Test that the {@link RemoteHomeBinding} is honoured for SLSB + * + * @throws Throwable + */ + @Test + public void testRemoteHomeBindingForSlsb() throws Throwable + { + // create the bean + this.sessionContainer = Utils.createSlsb(MyStatelessBeanWithBindings.class); + + // bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + // check the remotehome jndi name + String remoteHomeJndiName = sessionContainer.getMetaData().getHomeJndiName(); + + assertNotNull("Remote home jndi name is null", remoteHomeJndiName); + assertEquals("Remote home jndi name does not match the jndibinding value specified in @RemoteHomeBinding", MyStatelessBeanWithBindings.REMOTE_HOME_JNDI_NAME,remoteHomeJndiName); + + // lookup using the remote home jndi name and ensure the remotehome is bound to this name + Context ctx = new InitialContext(); + Object remoteHome = ctx.lookup(remoteHomeJndiName); + + assertNotNull("Remote home is null",remoteHome); + assertTrue("Remote home is not an instance of " + MyStatelessRemoteHome.class, (remoteHome instanceof MyStatelessRemoteHome)); + } + + /** + * Test that the {@link RemoteBindings} is honoured for beans + * + * TODO: Need to understand how clientBindUrl works and how RemoteBindings is expected to + * work. + * + * @throws Throwable + */ +// @Test +// public void testMultipleRemoteBindings() throws Throwable +// { +// //create the bean +// this.sessionContainer = Utils.createSlsb(MyStatelessBeanWithMultipleRemoteBindings.class); +// +// // bind the bean +// Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); +// +// List remoteBindingsMetadata = this.sessionContainer.getMetaData().getRemoteBindings(); +// +// assertTrue("Not enough @RemoteBinding found in the RemoteBindingMetadata list", remoteBindingsMetadata.size() > 0); +// +// Context ctx = new InitialContext(); +// for (RemoteBindingMetaData remoteBindingMetadata : remoteBindingsMetadata) +// { +// String jndiName = remoteBindingMetadata.getJndiName(); +// +// assertNotNull("Jndi name for @RemoteBinding is null", jndiName); +// +// if (remoteBindingMetadata.getClientBindUrl().equals(MyStatelessBeanWithMultipleRemoteBindings.CUSTOM_CLIENT_BIND_URL)) +// { +// // check the jndi name +// assertEquals("Remote jndi name does not match the one specified in @RemoteBinding (with clientBindUrl)", jndiName, +// MyStatelessBeanWithMultipleRemoteBindings.ANOTHER_REMOTE_JNDI_NAME); +// // lookup using this jndi name and check that the correct object is bound +// Object remote = ctx.lookup(jndiName); +// assertNotNull("Remote object bound to JNDI with @RemoteBinding and clientBindUrl is null", remote); +// assertTrue("Remote object bound to JNDI with @RemoteBinding and clientBindUrl is not an instance of " + MyStatelessRemote.class, (remote instanceof MyStatelessRemote)); +// +// } +// else +// { +// +// // check the jndi name +// assertEquals("Remote jndi name does not match the one specified in @RemoteBinding (without clientBindUrl)", jndiName, +// MyStatelessBeanWithMultipleRemoteBindings.REMOTE_JNDI_NAME); +// // lookup using this jndi name and check that the correct object is bound +// Object remote = ctx.lookup(jndiName); +// assertNotNull("Remote object bound to JNDI with @RemoteBinding without clientBindUrl is null", remote); +// assertTrue("Remote object bound to JNDI with @RemoteBinding without clientBindUrl is not an instance of " + MyStatelessRemote.class, +// (remote instanceof MyStatelessRemote)); +// } +// } +// } + + /** + * Test that the {@link RemoteBinding} is honoured for SFSB + * + * @throws Throwable + */ + @Test + public void testRemoteBindingForSfsb() throws Throwable + { + //create bean + this.sessionContainer = Utils.createSfsb(MyStatefulBeanWithBindings.class); + + // bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + List remoteBindingsMetadata = this.sessionContainer.getMetaData().getRemoteBindings(); + + assertEquals("Expected 1 @RemoteBinding metadata for Sfsb", remoteBindingsMetadata.size(), 1); + + RemoteBindingMetaData remoteBindingMetadata = remoteBindingsMetadata.get(0); + String remoteJndiName = remoteBindingMetadata.getJndiName(); + + assertNotNull("Remote jndi name is null for Sfsb", remoteJndiName); + assertEquals("Remote jndi name does not match the jndiBinding value specified in @RemoteBinding", MyStatefulBeanWithBindings.REMOTE_JNDI_NAME, remoteJndiName); + + // lookup and check the object + Context ctx = new InitialContext(); + Object remote = ctx.lookup(remoteJndiName); + + assertNotNull("Remote object bound to jndi is null", remote); + assertTrue("Remote object bound to jndi is not an instance of " + MyStatefulRemoteBusiness.class, (remote instanceof MyStatefulRemoteBusiness)); + + } + + /** + * Test that the {@link LocalBinding} is honoured for SFSB + * + * @throws Throwable + */ + @Test + public void testLocalBindingForSfsb() throws Throwable + { + // create the bean + this.sessionContainer = Utils.createSfsb(MyStatefulBeanWithBindings.class); + + // bind to jndi + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + String localJndiName = this.sessionContainer.getMetaData().getLocalJndiName(); + + assertNotNull("Local jndi name is null", localJndiName); + assertEquals("Local jndi name does not match the jndiBindingValue specified in @LocalBinding for Sfsb", MyStatefulBeanWithBindings.LOCAL_JNDI_NAME, localJndiName); + + // lookup and check the bound object + Context ctx = new InitialContext(); + Object local = ctx.lookup(localJndiName); + + assertNotNull("Local object bound to jndi is null", local); + assertTrue("Local object bound to jndi is not an instance of " + MyStatefulLocalBusiness.class, (local instanceof MyStatefulLocalBusiness)); + + } + + /** + * Test that the {@link LocalHomeBinding} is honoured for SFSB + * @throws Throwable + */ + @Test + public void testLocalHomeBindingForSfsb() throws Throwable + { + // create the bean + this.sessionContainer = Utils.createSfsb(MyStatefulBeanWithBindings.class); + + // bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(),sessionContainer); + + String localHomeJndiName = this.sessionContainer.getMetaData().getLocalHomeJndiName(); + + assertNotNull("Local home jndi name is null",localHomeJndiName); + assertEquals("Local home jndi name does not match the jndiBinding value specified in @LocalHomeBinding",MyStatefulBeanWithBindings.LOCAL_HOME_JNDI_NAME,localHomeJndiName); + + // lookup and check the object bound + Context ctx = new InitialContext(); + Object localHome = ctx.lookup(localHomeJndiName); + + assertNotNull("Local home bound to jndi is null",localHome); + assertTrue("Local home bound to jndi is not an instance of " + MyStatefulLocalHome.class, (localHome instanceof MyStatefulLocalHome)); + + } + + /** + * Test that the {@link RemoteHomeBinding} is honoured for SFSB + * + * @throws Throwable + */ + @Test + public void testRemoteHomeBindingForSfsb() throws Throwable + { + // create the bean + this.sessionContainer = Utils.createSfsb(MyStatefulBeanWithBindings.class); + + // bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(),sessionContainer); + + String remoteHomeJndiName = this.sessionContainer.getMetaData().getHomeJndiName(); + + assertNotNull("Remote home jndi name is null",remoteHomeJndiName); + assertEquals("Remote home jndi name does not match the jndiBinding value specified in @RemoteHomeBinding",MyStatefulBeanWithBindings.REMOTE_HOME_JNDI_NAME,remoteHomeJndiName); + + // lookup and check the object bound + Context ctx = new InitialContext(); + Object remoteHome = ctx.lookup(remoteHomeJndiName); + + assertNotNull("Remote home bound to jndi is null",remoteHome); + assertTrue("Remote home bound to jndi is not an instance of " + MyStatefulRemoteHome.class, (remoteHome instanceof MyStatefulRemoteHome)); + } + +} Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase.java =================================================================== --- proxy/src/test/java/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase.java (revision 0) +++ proxy/src/test/java/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase.java (revision 0) @@ -0,0 +1,441 @@ +/* + * 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.binding.unit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Iterator; +import java.util.List; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import org.jboss.ejb3.annotation.LocalBinding; +import org.jboss.ejb3.annotation.LocalHomeBinding; +import org.jboss.ejb3.annotation.RemoteBinding; +import org.jboss.ejb3.annotation.RemoteHomeBinding; +import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar; +import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator; +import org.jboss.ejb3.common.registrar.spi.NotBoundException; +import org.jboss.ejb3.test.mc.bootstrap.EmbeddedTestMcBootstrap; +import org.jboss.ejb3.test.proxy.common.Utils; +import org.jboss.ejb3.test.proxy.common.container.SessionContainer; +import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulBeanWithBindings; +import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulLocalBusiness; +import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulLocalHome; +import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulRemoteBusiness; +import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulRemoteHome; +import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessBeanWithBindings; +import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessLocal; +import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessLocalHome; +import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessRemote; +import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessRemoteHome; +import org.jboss.logging.Logger; +import org.jboss.metadata.ejb.jboss.RemoteBindingMetaData; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * JNDIBindingTestCase + * + * Test that the @RemoteBinding @RemoteHomeBinding @LocalBinding + * @LocalHomeBinding and @RemoteBindings work as expected. + * https://jira.jboss.org/jira/browse/EJBTHREE-1423 + * + * + * @author Jaikiran Pai + * @version $Revision: $ + */ +public class JNDIBindingTestCase +{ + + /** + * Bootstrap + */ + private static EmbeddedTestMcBootstrap bootstrap; + + /** + * Instance of logger + */ + private static Logger logger = Logger.getLogger(JNDIBindingTestCase.class); + + /** + * {@link SessionContainer} + */ + private SessionContainer sessionContainer; + + /** + * Start the necessary services + * + * @throws Throwable + */ + @BeforeClass + public static void setUpBeforeClass() throws Throwable + { + bootstrap = new EmbeddedTestMcBootstrap(); + bootstrap.run(); + + // Bind the Registrar + Ejb3RegistrarLocator.bindRegistrar(new Ejb3McRegistrar(bootstrap.getKernel())); + + // Reads a xml configuration to deploy the necessary services + bootstrap.deploy(JNDIBindingTestCase.class); + } + + /** + * Shutdown the services + * + * @throws Throwable + */ + @AfterClass + public static void tearDownAfterClass() throws Throwable + { + if (bootstrap != null) + { + bootstrap.shutdown(); + } + bootstrap = null; + } + + /** + * This method takes care of any cleanup required after each test. + */ + @After + public void cleanupAfterEachTest() + { + // Unbind the beans + if (sessionContainer != null) + { + logger.info("Unbinding: " + sessionContainer.getName()); + try + { + Ejb3RegistrarLocator.locateRegistrar().unbind(sessionContainer.getName()); + } + catch (NotBoundException nbe) + { + // we are ok with this exception, which indicates that the test case had + // already unbound the ejb related bindings. + logger.debug(sessionContainer.getName() + " was already unbound"); + + } + } + + } + + /** + * Test that the {@link RemoteBinding} is honoured for SLSB + * + * @throws Throwable + */ + @Test + public void testRemoteBindingForSlsb() throws Throwable + { + // create the bean + this.sessionContainer = Utils.createSlsb(MyStatelessBeanWithBindings.class); + + // bind it to JNDI + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + List remoteBindingsMetadata = sessionContainer.getMetaData().getRemoteBindings(); + + assertNotNull("No RemoteBindingMetadata available", remoteBindingsMetadata); + // make sure that the remotebinding metadata list has 1 @RemoteBinding information + assertEquals("RemoteBindingMetadata does not have any RemoteBinding information available", remoteBindingsMetadata.size(), 1); + + // Ensure that the RemoteBindingMetaData is created properly with the specified jndiBinding name. + Iterator remoteBindingsMetadataIterator = remoteBindingsMetadata.iterator(); + RemoteBindingMetaData remoteBindingMetadata = remoteBindingsMetadataIterator.next(); + + assertEquals("RemoteBinding JNDI name does not match " + MyStatelessBeanWithBindings.REMOTE_JNDI_NAME, MyStatelessBeanWithBindings.REMOTE_JNDI_NAME, remoteBindingMetadata + .getJndiName()); + + // Now ensure that the RemoteBindingMetaData is used for binding the + // remote interface of the bean. + Context ctx = new InitialContext(); + Object remoteBean = ctx.lookup(remoteBindingMetadata.getJndiName()); + logger.info("Object is : " + remoteBean); + assertNotNull("Remote bean returned from JNDI lookup is null", remoteBean); + assertTrue("Remote bean returned from JNDI lookup is NOT an instance of " + MyStatelessRemote.class, (remoteBean instanceof MyStatelessRemote)); + + } + + /** + * Test that the {@link LocalBinding} is honoured for SLSB + * + * @throws Throwable + */ + @Test + public void testLocalBindingForSlsb() throws Throwable + { + //create the bean + this.sessionContainer = Utils.createSlsb(MyStatelessBeanWithBindings.class); + + //bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + // Ensure that the local jndi name is set to the @LocalBinding value + String localJndiName = sessionContainer.getMetaData().getLocalJndiName(); + + assertNotNull("Local jndi name is null", localJndiName); + assertEquals("Local jndi name does not match the jndiBinding value specified in @LocalBinding", MyStatelessBeanWithBindings.LOCAL_JNDI_NAME, localJndiName); + + // Lookup using the local jndi name and check that the Local object is bound in the JNDI + Context ctx = new InitialContext(); + Object local = ctx.lookup(localJndiName); + + assertNotNull("Local object bound to JNDI is null", local); + assertTrue("Object bound to local JNDI name is NOT an instance of " + MyStatelessLocal.class, (local instanceof MyStatelessLocal)); + + } + + /** + * Test that the {@link LocalHomeBinding} is honoured for SLSB + * + * @throws Throwable + */ + @Test + public void testLocalHomeBindingForSlsb() throws Throwable + { + // create bean + this.sessionContainer = Utils.createSlsb(MyStatelessBeanWithBindings.class); + + // bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + // Ensure that the localhome jndi name is set to the @LocalHomeBinding value + String localHomeJndiName = sessionContainer.getMetaData().getLocalHomeJndiName(); + + assertNotNull("Local home jndi name is null", localHomeJndiName); + assertEquals("Local home jndi name does not match the jndiBinding value specified in @LocalHomeBinding", MyStatelessBeanWithBindings.LOCAL_HOME_JNDI_NAME, localHomeJndiName); + + // lookup using the localhome jndi name and ensure the localhome is bound to this name + Context ctx = new InitialContext(); + Object localHome = ctx.lookup(localHomeJndiName); + + assertNotNull("Local home is null",localHome); + assertTrue("Local home is not an instance of " + MyStatelessLocalHome.class, (localHome instanceof MyStatelessLocalHome)); + + } + + /** + * Test that the {@link RemoteHomeBinding} is honoured for SLSB + * + * @throws Throwable + */ + @Test + public void testRemoteHomeBindingForSlsb() throws Throwable + { + // create the bean + this.sessionContainer = Utils.createSlsb(MyStatelessBeanWithBindings.class); + + // bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + // check the remotehome jndi name + String remoteHomeJndiName = sessionContainer.getMetaData().getHomeJndiName(); + + assertNotNull("Remote home jndi name is null", remoteHomeJndiName); + assertEquals("Remote home jndi name does not match the jndibinding value specified in @RemoteHomeBinding", MyStatelessBeanWithBindings.REMOTE_HOME_JNDI_NAME,remoteHomeJndiName); + + // lookup using the remote home jndi name and ensure the remotehome is bound to this name + Context ctx = new InitialContext(); + Object remoteHome = ctx.lookup(remoteHomeJndiName); + + assertNotNull("Remote home is null",remoteHome); + assertTrue("Remote home is not an instance of " + MyStatelessRemoteHome.class, (remoteHome instanceof MyStatelessRemoteHome)); + } + + /** + * Test that the {@link RemoteBindings} is honoured for beans + * + * TODO: Need to understand how clientBindUrl works and how RemoteBindings is expected to + * work. + * + * @throws Throwable + */ +// @Test +// public void testMultipleRemoteBindings() throws Throwable +// { +// //create the bean +// this.sessionContainer = Utils.createSlsb(MyStatelessBeanWithMultipleRemoteBindings.class); +// +// // bind the bean +// Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); +// +// List remoteBindingsMetadata = this.sessionContainer.getMetaData().getRemoteBindings(); +// +// assertTrue("Not enough @RemoteBinding found in the RemoteBindingMetadata list", remoteBindingsMetadata.size() > 0); +// +// Context ctx = new InitialContext(); +// for (RemoteBindingMetaData remoteBindingMetadata : remoteBindingsMetadata) +// { +// String jndiName = remoteBindingMetadata.getJndiName(); +// +// assertNotNull("Jndi name for @RemoteBinding is null", jndiName); +// +// if (remoteBindingMetadata.getClientBindUrl().equals(MyStatelessBeanWithMultipleRemoteBindings.CUSTOM_CLIENT_BIND_URL)) +// { +// // check the jndi name +// assertEquals("Remote jndi name does not match the one specified in @RemoteBinding (with clientBindUrl)", jndiName, +// MyStatelessBeanWithMultipleRemoteBindings.ANOTHER_REMOTE_JNDI_NAME); +// // lookup using this jndi name and check that the correct object is bound +// Object remote = ctx.lookup(jndiName); +// assertNotNull("Remote object bound to JNDI with @RemoteBinding and clientBindUrl is null", remote); +// assertTrue("Remote object bound to JNDI with @RemoteBinding and clientBindUrl is not an instance of " + MyStatelessRemote.class, (remote instanceof MyStatelessRemote)); +// +// } +// else +// { +// +// // check the jndi name +// assertEquals("Remote jndi name does not match the one specified in @RemoteBinding (without clientBindUrl)", jndiName, +// MyStatelessBeanWithMultipleRemoteBindings.REMOTE_JNDI_NAME); +// // lookup using this jndi name and check that the correct object is bound +// Object remote = ctx.lookup(jndiName); +// assertNotNull("Remote object bound to JNDI with @RemoteBinding without clientBindUrl is null", remote); +// assertTrue("Remote object bound to JNDI with @RemoteBinding without clientBindUrl is not an instance of " + MyStatelessRemote.class, +// (remote instanceof MyStatelessRemote)); +// } +// } +// } + + /** + * Test that the {@link RemoteBinding} is honoured for SFSB + * + * @throws Throwable + */ + @Test + public void testRemoteBindingForSfsb() throws Throwable + { + //create bean + this.sessionContainer = Utils.createSfsb(MyStatefulBeanWithBindings.class); + + // bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + List remoteBindingsMetadata = this.sessionContainer.getMetaData().getRemoteBindings(); + + assertEquals("Expected 1 @RemoteBinding metadata for Sfsb", remoteBindingsMetadata.size(), 1); + + RemoteBindingMetaData remoteBindingMetadata = remoteBindingsMetadata.get(0); + String remoteJndiName = remoteBindingMetadata.getJndiName(); + + assertNotNull("Remote jndi name is null for Sfsb", remoteJndiName); + assertEquals("Remote jndi name does not match the jndiBinding value specified in @RemoteBinding", MyStatefulBeanWithBindings.REMOTE_JNDI_NAME, remoteJndiName); + + // lookup and check the object + Context ctx = new InitialContext(); + Object remote = ctx.lookup(remoteJndiName); + + assertNotNull("Remote object bound to jndi is null", remote); + assertTrue("Remote object bound to jndi is not an instance of " + MyStatefulRemoteBusiness.class, (remote instanceof MyStatefulRemoteBusiness)); + + } + + /** + * Test that the {@link LocalBinding} is honoured for SFSB + * + * @throws Throwable + */ + @Test + public void testLocalBindingForSfsb() throws Throwable + { + // create the bean + this.sessionContainer = Utils.createSfsb(MyStatefulBeanWithBindings.class); + + // bind to jndi + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer); + + String localJndiName = this.sessionContainer.getMetaData().getLocalJndiName(); + + assertNotNull("Local jndi name is null", localJndiName); + assertEquals("Local jndi name does not match the jndiBindingValue specified in @LocalBinding for Sfsb", MyStatefulBeanWithBindings.LOCAL_JNDI_NAME, localJndiName); + + // lookup and check the bound object + Context ctx = new InitialContext(); + Object local = ctx.lookup(localJndiName); + + assertNotNull("Local object bound to jndi is null", local); + assertTrue("Local object bound to jndi is not an instance of " + MyStatefulLocalBusiness.class, (local instanceof MyStatefulLocalBusiness)); + + } + + /** + * Test that the {@link LocalHomeBinding} is honoured for SFSB + * @throws Throwable + */ + @Test + public void testLocalHomeBindingForSfsb() throws Throwable + { + // create the bean + this.sessionContainer = Utils.createSfsb(MyStatefulBeanWithBindings.class); + + // bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(),sessionContainer); + + String localHomeJndiName = this.sessionContainer.getMetaData().getLocalHomeJndiName(); + + assertNotNull("Local home jndi name is null",localHomeJndiName); + assertEquals("Local home jndi name does not match the jndiBinding value specified in @LocalHomeBinding",MyStatefulBeanWithBindings.LOCAL_HOME_JNDI_NAME,localHomeJndiName); + + // lookup and check the object bound + Context ctx = new InitialContext(); + Object localHome = ctx.lookup(localHomeJndiName); + + assertNotNull("Local home bound to jndi is null",localHome); + assertTrue("Local home bound to jndi is not an instance of " + MyStatefulLocalHome.class, (localHome instanceof MyStatefulLocalHome)); + + } + + /** + * Test that the {@link RemoteHomeBinding} is honoured for SFSB + * + * @throws Throwable + */ + @Test + public void testRemoteHomeBindingForSfsb() throws Throwable + { + // create the bean + this.sessionContainer = Utils.createSfsb(MyStatefulBeanWithBindings.class); + + // bind the bean + Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(),sessionContainer); + + String remoteHomeJndiName = this.sessionContainer.getMetaData().getHomeJndiName(); + + assertNotNull("Remote home jndi name is null",remoteHomeJndiName); + assertEquals("Remote home jndi name does not match the jndiBinding value specified in @RemoteHomeBinding",MyStatefulBeanWithBindings.REMOTE_HOME_JNDI_NAME,remoteHomeJndiName); + + // lookup and check the object bound + Context ctx = new InitialContext(); + Object remoteHome = ctx.lookup(remoteHomeJndiName); + + assertNotNull("Remote home bound to jndi is null",remoteHome); + assertTrue("Remote home bound to jndi is not an instance of " + MyStatefulRemoteHome.class, (remoteHome instanceof MyStatefulRemoteHome)); + } + +} Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulBeanWithBindings.java =================================================================== --- proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulBeanWithBindings.java (revision 0) +++ proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulBeanWithBindings.java (revision 0) @@ -0,0 +1,86 @@ +/* + * 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.ejb.sfsb; + +import javax.ejb.Local; +import javax.ejb.LocalHome; +import javax.ejb.Remote; +import javax.ejb.RemoteHome; +import javax.ejb.Stateful; + +import org.jboss.ejb3.annotation.LocalBinding; +import org.jboss.ejb3.annotation.LocalHomeBinding; +import org.jboss.ejb3.annotation.RemoteBinding; +import org.jboss.ejb3.annotation.RemoteHomeBinding; + +/** + * + * MyStatefulBeanWithBindings + * + * @author Jaikiran Pai + * @version $Revision: $ + */ +@Stateful +@Remote (MyStatefulRemoteBusiness.class) +@Local (MyStatefulLocalBusiness.class) +@RemoteHome (MyStatefulRemoteHome.class) +@LocalHome (MyStatefulLocalHome.class) +@RemoteBinding (jndiBinding=MyStatefulBeanWithBindings.REMOTE_JNDI_NAME) +@LocalBinding (jndiBinding=MyStatefulBeanWithBindings.LOCAL_JNDI_NAME) +@LocalHomeBinding (jndiBinding=MyStatefulBeanWithBindings.LOCAL_HOME_JNDI_NAME) +@RemoteHomeBinding (jndiBinding=MyStatefulBeanWithBindings.REMOTE_HOME_JNDI_NAME) +public class MyStatefulBeanWithBindings implements MyStatefulRemoteBusiness, MyStatefulLocalBusiness +{ + /** + * Counter + */ + private int counter; + + /** + * Remote jndi name + */ + public static final String REMOTE_JNDI_NAME = "AnyName"; + + /** + * Local jndi name + */ + public static final String LOCAL_JNDI_NAME = "SomeLocalJndiName"; + + /** + * Local home jndi name + */ + public static final String LOCAL_HOME_JNDI_NAME = "MyLocalHomeJndiName"; + + /** + * Remote home jndi name + */ + public static final String REMOTE_HOME_JNDI_NAME = "SomeHome"; + + /** + * @see {@link MyStateful#getNextCounter()} + */ + public int getNextCounter() + { + return counter ++; + } + +} Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/MyStatelessBeanWithBindings.java =================================================================== --- proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/MyStatelessBeanWithBindings.java (revision 0) +++ proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/MyStatelessBeanWithBindings.java (revision 0) @@ -0,0 +1,82 @@ +/* + * 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.ejb.slsb; + +import javax.ejb.Local; +import javax.ejb.LocalHome; +import javax.ejb.Remote; +import javax.ejb.RemoteHome; +import javax.ejb.Stateless; + +import org.jboss.ejb3.annotation.LocalBinding; +import org.jboss.ejb3.annotation.LocalHomeBinding; +import org.jboss.ejb3.annotation.RemoteBinding; +import org.jboss.ejb3.annotation.RemoteHomeBinding; + +/** + * + * MyStatelessBeanWithBindings + * + * @author Jaikiran Pai + * @version $Revision: $ + */ +@Stateless +@Remote(MyStatelessRemote.class) +@Local(MyStatelessLocal.class) +@LocalHome (MyStatelessLocalHome.class) +@LocalBinding(jndiBinding = MyStatelessBeanWithBindings.LOCAL_JNDI_NAME) +@LocalHomeBinding(jndiBinding = MyStatelessBeanWithBindings.LOCAL_HOME_JNDI_NAME) +@RemoteHome(MyStatelessRemoteHome.class) +@RemoteBinding(jndiBinding = MyStatelessBeanWithBindings.REMOTE_JNDI_NAME) +@RemoteHomeBinding(jndiBinding = MyStatelessBeanWithBindings.REMOTE_HOME_JNDI_NAME) +public class MyStatelessBeanWithBindings implements MyStatelessLocal, MyStatelessRemote +{ + + /** + * Remote JNDI Name. + */ + public static final String REMOTE_JNDI_NAME = "SomeRemoteName"; + + /** + * Local JNDI name. + */ + public static final String LOCAL_JNDI_NAME = "MyLocalJNDIName"; + + /** + * Local Home JNDI Name. + */ + public static final String LOCAL_HOME_JNDI_NAME = "MyLocalHomeJNDIName"; + + /** + * Remote home JNDI Name + */ + public static final String REMOTE_HOME_JNDI_NAME = "MyRemoteHomeJNDIName"; + + /** + * @see {@link MyStateless#sayHi(String)} + */ + public String sayHi(String name) + { + return "Hi " + name; + } + +} Index: proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/MyStatelessBeanWithMultipleRemoteBindings.java =================================================================== --- proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/MyStatelessBeanWithMultipleRemoteBindings.java (revision 0) +++ proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/MyStatelessBeanWithMultipleRemoteBindings.java (revision 0) @@ -0,0 +1,70 @@ +/* + * 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.ejb.slsb; + +import javax.ejb.Remote; +import javax.ejb.Stateless; + +import org.jboss.ejb3.annotation.RemoteBinding; +import org.jboss.ejb3.annotation.RemoteBindings; + +/** + * + * MyStatelessBeanWithMultipleRemoteBindings + * + * @author Jaikiran Pai + * @version $Revision: $ + */ +@Stateless +@RemoteBindings ( + { + @RemoteBinding (jndiBinding=MyStatelessBeanWithMultipleRemoteBindings.REMOTE_JNDI_NAME), + @RemoteBinding (jndiBinding=MyStatelessBeanWithMultipleRemoteBindings.ANOTHER_REMOTE_JNDI_NAME, clientBindUrl=MyStatelessBeanWithMultipleRemoteBindings.CUSTOM_CLIENT_BIND_URL) + } + +) +@Remote (MyStatelessRemote.class) +public class MyStatelessBeanWithMultipleRemoteBindings implements MyStatelessRemote +{ + + /** + * Remote jndi name + */ + public static final String REMOTE_JNDI_NAME = "SomeJndiName"; + + /** + * Another remote jndi name + */ + public static final String ANOTHER_REMOTE_JNDI_NAME = "AnotherJndiName"; + + /** + * Client bind url + */ + public static final String CUSTOM_CLIENT_BIND_URL = "0.0.0.0:3333"; + + public String sayHi(String name) + { + // TODO Auto-generated method stub + return null; + } + +} Index: proxy/src/test/resources/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase-beans.xml =================================================================== --- proxy/src/test/resources/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase-beans.xml (revision 0) +++ proxy/src/test/resources/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase-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 + + + + + + + + + + AOP + + org.jboss.aspects.remoting.AOPRemotingInvocationHandler + + + + + + + + + socket://0.0.0.0:3873 + + + + + + \ No newline at end of file Index: proxy/src/test/resources/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase-beans.xml =================================================================== --- proxy/src/test/resources/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase-beans.xml (revision 0) +++ proxy/src/test/resources/org/jboss/ejb3/test/proxy/binding/unit/JNDIBindingTestCase-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 + + + + + + + + + + AOP + + org.jboss.aspects.remoting.AOPRemotingInvocationHandler + + + + + + + + + socket://0.0.0.0:3873 + + + + + + \ No newline at end of file