[jboss-cvs] JBossAS SVN: r80728 - in projects/ejb3/trunk/proxy/src/test: java/org/jboss/ejb3/test/proxy/common and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Nov 9 19:11:31 EST 2008
Author: ALRubinger
Date: 2008-11-09 19:11:30 -0500 (Sun, 09 Nov 2008)
New Revision: 80728
Added:
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/ServiceContainer.java
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyService.java
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBean.java
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBeanBase.java
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBeanWithExplicitJndiBindings.java
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceLocalBusiness.java
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceRemoteBusiness.java
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/service/
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/service/unit/
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/service/unit/ProxyServiceTestCase.java
Modified:
projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/Utils.java
projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/SessionTestCaseBase-jboss-beans.xml
Log:
[EJBTHREE-1573] Added Unit Tests for @Service support in jboss-ejb3-proxy
Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/Utils.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/Utils.java 2008-11-09 23:37:01 UTC (rev 80727)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/Utils.java 2008-11-10 00:11:30 UTC (rev 80728)
@@ -22,9 +22,11 @@
package org.jboss.ejb3.test.proxy.common;
import org.jboss.ejb3.test.common.MetaDataHelper;
+import org.jboss.ejb3.test.proxy.common.container.ServiceContainer;
import org.jboss.ejb3.test.proxy.common.container.StatefulContainer;
import org.jboss.ejb3.test.proxy.common.container.StatelessContainer;
import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossServiceBeanMetaData;
import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
import org.jboss.metadata.ejb.jboss.jndipolicy.plugins.BasicJndiBindingPolicy;
import org.jboss.metadata.ejb.jboss.jndipolicy.plugins.JBossSessionPolicyDecorator;
@@ -94,4 +96,36 @@
return container;
}
+ /**
+ * Creates and returns a @Service Container for the Service Implementation Class specified
+ *
+ * @param sfsbImplementationClass
+ * @return
+ * @throws Throwable
+ */
+ public static ServiceContainer createService(Class<?> serviceImplementationClass) throws Throwable
+ {
+ // Get Metadata
+ JBossSessionBeanMetaData beanMetaData = MetaDataHelper.getMetadataFromBeanImplClass(serviceImplementationClass);
+
+ // Ensure @Service
+ if (!beanMetaData.isService())
+ {
+ throw new RuntimeException("Specified implementation class for @Service was not a Service Bean: "
+ + serviceImplementationClass.getName());
+ }
+
+ // Cast
+ JBossServiceBeanMetaData smd = (JBossServiceBeanMetaData) beanMetaData;
+
+ // Decorate Metadata
+ beanMetaData = new JBossSessionPolicyDecorator(smd, new BasicJndiBindingPolicy());
+
+ // Make a Container
+ ServiceContainer container = new ServiceContainer(smd, Thread.currentThread().getContextClassLoader());
+
+ // Return
+ return container;
+ }
+
}
Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/ServiceContainer.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/ServiceContainer.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/ServiceContainer.java 2008-11-10 00:11:30 UTC (rev 80728)
@@ -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.container;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+import org.jboss.ejb3.proxy.container.InvokableContext;
+import org.jboss.ejb3.proxy.objectstore.ObjectStoreBindings;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+
+/**
+ * A simple @Service container that binds proxies and can be invoked.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ServiceContainer extends SessionSpecContainer implements InvokableContext
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ServiceContainer.class);
+
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Singleton instance
+ */
+ private Object beanInstance;
+
+ // --------------------------------------------------------------------------------||
+ // Constructors -------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public ServiceContainer(JBossSessionBeanMetaData metaData, ClassLoader classLoader) throws ClassNotFoundException
+ {
+ super(metaData, classLoader);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Required Implementations -------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Creates a unique name for this container
+ *
+ * @return
+ */
+ @Override
+ protected final String createContainerName()
+ {
+ return ObjectStoreBindings.OBJECTSTORE_NAMESPACE_EJBCONTAINER_SERVICE + this.getMetaData().getEjbName() + "/"
+ + UUID.randomUUID();
+ }
+
+ /**
+ * Returns the name under which the JNDI Registrar for this container is bound
+ *
+ * @return
+ */
+ @Override
+ protected String getJndiRegistrarBindName()
+ {
+ return ObjectStoreBindings.OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR_SERVICE;
+ }
+
+ /**
+ * Obtains the appropriate bean instance for invocation.
+ * Specified Session ID will be ignored
+ *
+ * @param sessionId
+ * @return
+ */
+ @Override
+ //FIXME: @Service has no Session ID
+ protected synchronized Object getBeanInstance(Serializable sessionId)
+ {
+ // Check if bean instance is not yet created
+ if (this.getBeanInstance() == null)
+ {
+ try
+ {
+ // Create and set the instance
+ Object beanInstance = this.createInstance();
+ this.setBeanInstance(beanInstance);
+ log.info("Set bean (Singleton) instance: " + beanInstance);
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("Error in creating new @Service Bean Instance", t);
+ }
+ }
+
+ // Return
+ return this.getBeanInstance();
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Accessors / Mutators -----------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ protected Object getBeanInstance()
+ {
+ return beanInstance;
+ }
+
+ protected void setBeanInstance(Object beanInstance)
+ {
+ this.beanInstance = beanInstance;
+ }
+
+}
Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyService.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyService.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyService.java 2008-11-10 00:11:30 UTC (rev 80728)
@@ -0,0 +1,45 @@
+/*
+ * 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.service;
+
+import java.util.UUID;
+
+/**
+ * MyService
+ *
+ * Defines contract for a test @Service bean
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface MyService
+{
+ // --------------------------------------------------------------------------------||
+ // Contracts ----------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Returns a globally-unique ID for this
+ * Service bean
+ */
+ UUID getUuid();
+}
Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBean.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBean.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBean.java 2008-11-10 00:11:30 UTC (rev 80728)
@@ -0,0 +1,43 @@
+/*
+ * 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.service;
+
+import javax.ejb.Local;
+import javax.ejb.Remote;
+
+import org.jboss.ejb3.annotation.Service;
+
+/**
+ * MyServiceBean
+ *
+ * An @Service bean used in testing
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Service
+ at Local(MyServiceLocalBusiness.class)
+ at Remote(MyServiceRemoteBusiness.class)
+public class MyServiceBean extends MyServiceBeanBase implements MyServiceLocalBusiness, MyServiceRemoteBusiness
+{
+
+}
Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBeanBase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBeanBase.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBeanBase.java 2008-11-10 00:11:30 UTC (rev 80728)
@@ -0,0 +1,68 @@
+/*
+ * 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.service;
+
+import java.util.UUID;
+
+/**
+ * MyServiceBeanBase
+ *
+ * Base implementation class (business logic)
+ * for an @Service bean used in testing
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class MyServiceBeanBase implements MyServiceLocalBusiness, MyServiceRemoteBusiness
+{
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * UUID for this instance
+ */
+ private UUID uuid;
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public MyServiceBeanBase()
+ {
+ this.uuid = UUID.randomUUID();
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Required Implementations -------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Returns a globally-unique ID for this
+ * Service bean
+ */
+ public UUID getUuid()
+ {
+ return this.uuid;
+ }
+
+}
Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBeanWithExplicitJndiBindings.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBeanWithExplicitJndiBindings.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceBeanWithExplicitJndiBindings.java 2008-11-10 00:11:30 UTC (rev 80728)
@@ -0,0 +1,60 @@
+/*
+ * 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.service;
+
+import javax.ejb.Local;
+import javax.ejb.Remote;
+
+import org.jboss.ejb3.annotation.LocalBinding;
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.ejb3.annotation.Service;
+
+/**
+ * MyServiceBean
+ *
+ * An @Service bean used in testing
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Service
+ at Local(MyServiceLocalBusiness.class)
+ at Remote(MyServiceRemoteBusiness.class)
+ at LocalBinding(jndiBinding = MyServiceBeanWithExplicitJndiBindings.JNDI_NAME_LOCAL)
+ at RemoteBinding(jndiBinding = MyServiceBeanWithExplicitJndiBindings.JNDI_NAME_REMOTE)
+public class MyServiceBeanWithExplicitJndiBindings extends MyServiceBeanBase
+ implements
+ MyServiceLocalBusiness,
+ MyServiceRemoteBusiness
+{
+ // --------------------------------------------------------------------------------||
+ // Constants ----------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /*
+ * Define explicit JNDI Bindings
+ */
+
+ public static final String JNDI_NAME_REMOTE = "MyServiceBeanRemoteBinding";
+
+ public static final String JNDI_NAME_LOCAL = "MyServiceBeanLocalBinding";
+}
Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceLocalBusiness.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceLocalBusiness.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceLocalBusiness.java 2008-11-10 00:11:30 UTC (rev 80728)
@@ -0,0 +1,33 @@
+/*
+ * 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.service;
+
+/**
+ * MyServiceLocalBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface MyServiceLocalBusiness extends MyService
+{
+
+}
Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceRemoteBusiness.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceRemoteBusiness.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/service/MyServiceRemoteBusiness.java 2008-11-10 00:11:30 UTC (rev 80728)
@@ -0,0 +1,33 @@
+/*
+ * 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.service;
+
+/**
+ * MyServiceRemoteBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface MyServiceRemoteBusiness extends MyService
+{
+
+}
Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/service/unit/ProxyServiceTestCase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/service/unit/ProxyServiceTestCase.java (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/service/unit/ProxyServiceTestCase.java 2008-11-10 00:11:30 UTC (rev 80728)
@@ -0,0 +1,237 @@
+/*
+ * 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.service.unit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.test.proxy.common.SessionTestCaseBase;
+import org.jboss.ejb3.test.proxy.common.Utils;
+import org.jboss.ejb3.test.proxy.common.container.ServiceContainer;
+import org.jboss.ejb3.test.proxy.common.ejb.service.MyServiceBean;
+import org.jboss.ejb3.test.proxy.common.ejb.service.MyServiceBeanWithExplicitJndiBindings;
+import org.jboss.ejb3.test.proxy.common.ejb.service.MyServiceLocalBusiness;
+import org.jboss.ejb3.test.proxy.common.ejb.service.MyServiceRemoteBusiness;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * ProxyServiceTestCase
+ *
+ * General tests for @Service beans:
+ *
+ * - Bound as expected
+ * - May be invoked
+ * - .equals() implementation of Proxies is correct
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ProxyServiceTestCase extends SessionTestCaseBase
+{
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ProxyServiceTestCase.class);
+
+ private static InitialContext context;
+
+ // --------------------------------------------------------------------------------||
+ // Tests --------------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Tests binding and invocation upon the local business
+ * interface
+ */
+ @Test
+ public void testLocalDefaultBindings() throws Exception
+ {
+ // Define the JNDI name to use
+ String jndiName = "MyServiceBean/local";
+
+ // Run test
+ this.runLocalTest(jndiName);
+ }
+
+ /**
+ * Tests binding and invocation upon the remote business
+ * interface
+ */
+ @Test
+ public void testRemoteDefaultBindings() throws Exception
+ {
+ // Define the JNDI name to use
+ String jndiName = "MyServiceBean/remote";
+
+ // Run test
+ this.runRemoteTest(jndiName);
+ }
+
+ /**
+ * Tests binding and invocation upon the local business
+ * interface using @LocalBinding.jnidBinding value
+ */
+ @Test
+ public void testLocalExplicitBindings() throws Exception
+ {
+ // Define the JNDI name to use
+ String jndiName = MyServiceBeanWithExplicitJndiBindings.JNDI_NAME_LOCAL;
+
+ // Run test
+ this.runLocalTest(jndiName);
+ }
+
+ /**
+ * Tests binding and invocation upon the remote business
+ * interface using @RemoteBinding.jnidBinding value
+ */
+ @Test
+ public void testRemoteExplicitBindings() throws Exception
+ {
+ // Define the JNDI name to use
+ String jndiName = MyServiceBeanWithExplicitJndiBindings.JNDI_NAME_REMOTE;
+
+ // Run test
+ this.runRemoteTest(jndiName);
+ }
+
+ /**
+ * Tests that proxies with the same target container are
+ * equal
+ */
+ @Test
+ public void testProxiesSameTargetContainerEqual() throws Exception
+ {
+ // Lookup
+ Object bean1 = context.lookup("MyServiceBean/local");
+ Object bean2 = context.lookup("MyServiceBean/remote");
+
+ // Ensure equal
+ assertEquals("@Service proxies with the same target container must be equal", bean1, bean2);
+ }
+
+ /**
+ * Tests that proxies with the different target containers are
+ * not equal
+ */
+ @Test
+ public void testProxiesDifferentTargetContainersNotEqual() throws Exception
+ {
+ // Lookup
+ Object bean1 = context.lookup("MyServiceBean/local");
+ Object bean2 = context.lookup(MyServiceBeanWithExplicitJndiBindings.JNDI_NAME_LOCAL);
+
+ // Ensure equal
+ assertNotSame("@Service proxies with the different target containers must not be equal", bean1, bean2);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Internal Helper Methods --------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Run the local test using the specified lookup name
+ *
+ * @param jndiName
+ */
+ protected void runLocalTest(String jndiName) throws Exception
+ {
+ // Lookup
+ Object bean = context.lookup(jndiName);
+
+ // Ensure expected type
+ assertTrue(bean instanceof MyServiceLocalBusiness);
+
+ // Cast
+ MyServiceLocalBusiness ejb = (MyServiceLocalBusiness) bean;
+
+ // Invoke and log
+ log.info("Invoked upon @Service local business view: " + ejb.getUuid());
+ }
+
+ /**
+ * Run the remote test using the specified lookup name
+ *
+ * @param jndiName
+ */
+ protected void runRemoteTest(String jndiName) throws Exception
+ {
+ // Lookup
+ Object bean = context.lookup(jndiName);
+
+ // Ensure expected type
+ assertTrue(bean instanceof MyServiceRemoteBusiness);
+
+ // Cast
+ MyServiceRemoteBusiness ejb = (MyServiceRemoteBusiness) bean;
+
+ // Invoke and log
+ log.info("Invoked upon @Service remote business view: " + ejb.getUuid());
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Lifecycle Methods --------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Perform setup before any tests
+ *
+ * @throws Throwable
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Throwable
+ {
+ // Create Bootstrap and Deploy
+ SessionTestCaseBase.setUpBeforeClass();
+
+ // Deploy MC Beans
+ ProxyServiceTestCase.bootstrap.deploy(SessionTestCaseBase.class);
+
+ // Create @Service containers
+ ServiceContainer defaultBindingsContainer = Utils.createService(MyServiceBean.class);
+ ServiceContainer explicitBindingsContainer = Utils.createService(MyServiceBeanWithExplicitJndiBindings.class);
+
+ // Install
+ Ejb3RegistrarLocator.locateRegistrar().bind(defaultBindingsContainer.getName(), defaultBindingsContainer);
+ Ejb3RegistrarLocator.locateRegistrar().bind(explicitBindingsContainer.getName(), explicitBindingsContainer);
+
+ // Set Naming COntext
+ ProxyServiceTestCase.context = new InitialContext(); // Props from jndi.properties
+
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception
+ {
+ if (bootstrap != null)
+ bootstrap.shutdown();
+ bootstrap = null;
+ }
+}
Modified: projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/SessionTestCaseBase-jboss-beans.xml
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/SessionTestCaseBase-jboss-beans.xml 2008-11-09 23:37:01 UTC (rev 80727)
+++ projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/SessionTestCaseBase-jboss-beans.xml 2008-11-10 00:11:30 UTC (rev 80728)
@@ -37,6 +37,17 @@
</parameter>
</constructor>
<depends>NameServer</depends>
+ </bean>
+
+ <!-- @Service JNDI Registrar -->
+ <bean name="org.jboss.ejb3.JndiRegistrar.ServiceJndiRegistrar"
+ class="org.jboss.ejb3.proxy.jndiregistrar.JndiServiceRegistrar">
+ <constructor>
+ <parameter>
+ org.jboss.ejb3.proxy.objectfactory.service.ServiceProxyObjectFactory
+ </parameter>
+ </constructor>
+ <depends>NameServer</depends>
</bean>
<!--
More information about the jboss-cvs-commits
mailing list