[jboss-cvs] JBossAS SVN: r85890 - in projects/ejb3/trunk/nointerface: src/main/java/org/jboss/ejb3/nointerface and 12 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 16 06:32:11 EDT 2009
Author: jaikiran
Date: 2009-03-16 06:32:09 -0400 (Mon, 16 Mar 2009)
New Revision: 85890
Added:
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatefulContainer.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatelessContainer.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java
Removed:
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/connectionmanager/MockCachedConnectionManager.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EJB3DeploymentUnit.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbComponentDeployer.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbDeployment.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbModuleDeployer.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/javaee/SimpleJavaEEModuleInformer.java
projects/ejb3/trunk/nointerface/src/test/resources/deployers/jpa-deployers-jboss-beans.xml
Modified:
projects/ejb3/trunk/nointerface/pom.xml
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewCreator.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/StatefulNoInterfaceViewFactory.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/NoInterfaceViewInvocationHandler.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/objectfactory/StatefulNoInterfaceViewObjectFactory.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/AbstractNoInterfaceTestCase.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSFSBean.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java
projects/ejb3/trunk/nointerface/src/test/resources/deployers/ejb3-deployers-jboss-beans.xml
Log:
EJBTHREE-1727 1) Removed dependency on ejb3-core 2) Added more tests for the component 3) Container name is now created within the Ejb3NoInterfaceDeployer 4)Depends on the new proxy-spi
Modified: projects/ejb3/trunk/nointerface/pom.xml
===================================================================
--- projects/ejb3/trunk/nointerface/pom.xml 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/pom.xml 2009-03-16 10:32:09 UTC (rev 85890)
@@ -154,28 +154,25 @@
<scope>test</scope>
</dependency>
- <!-- Note: Finally this dependency on core needs to go -->
+ <dependency>
+ <groupId>trove</groupId>
+ <artifactId>trove</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
<dependency>
<groupId>org.jboss.ejb3</groupId>
- <artifactId>jboss-ejb3-core</artifactId>
- <version>1.0.0</version>
-
- <exclusions>
- <exclusion>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-transaction-spi</artifactId>
- </exclusion>
- </exclusions>
+ <artifactId>jboss-ejb3-proxy-spi</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.jboss.ejb3</groupId>
- <artifactId>jboss-ejb3-proxy</artifactId>
- <version>1.0.0</version>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-common</artifactId>
+ <version>1.0.0</version>
</dependency>
-
<!-- The EJB3.1 API support (ex: @LocalBean) -->
<dependency>
<groupId>org.jboss.ejb3</groupId>
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewCreator.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewCreator.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewCreator.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -59,12 +59,12 @@
* The proxies (sub-classes) created for the bean class need to be
* unique. This unique number is appended to the generated class name
*/
- private long nextUniqueNumberForNoViewInterfaceClassName = 0;
+ private static long nextUniqueNumberForNoViewInterfaceClassName = 0;
/**
* Used while generating unique number for the proxy class
*/
- private Object nextUniqueNumberLock = new Object();
+ private static Object nextUniqueNumberLock = new Object();
/**
* Logger
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -27,6 +27,9 @@
import java.util.Iterator;
import java.util.List;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.ValueMetaData;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
@@ -35,9 +38,6 @@
import org.jboss.deployers.spi.deployer.DeploymentStages;
import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.ejb3.javaee.JavaEEComponentHelper;
-import org.jboss.ejb3.javaee.JavaEEModule;
-import org.jboss.ejb3.javaee.SimpleJavaEEModule;
import org.jboss.ejb3.nointerface.mc.NoInterfaceViewJNDIBinder;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
@@ -64,8 +64,9 @@
*/
public EJB3NoInterfaceDeployer()
{
- setStage(DeploymentStages.POST_CLASSLOADER);
- setInput(JBossMetaData.class);
+ setStage(DeploymentStages.REAL);
+ addInput(JBossMetaData.class);
+
addOutput(BeanMetaData.class);
}
@@ -129,9 +130,7 @@
// However, this deployer does not have an dependency on the creation of a container,
// so getting the container name from the bean metadata won't work. Need to do a different/better way
//String containerMCBeanName = sessionBeanMetaData.getContainerName();
- JavaEEModule module = new SimpleJavaEEModule(unit.getSimpleName());
- String ejbName = sessionBeanMetaData.getEjbName();
- String containerMCBeanName = JavaEEComponentHelper.createObjectName(module, ejbName);
+ String containerMCBeanName = getContainerName(unit, sessionBeanMetaData);
// The no-interface view needs to be a MC bean so that it can "depend" on the container, so let's
// make the no-interface view a MC bean
@@ -281,4 +280,74 @@
// if the implementedInterfaces collection is empty then this bean can be considered for no-interface view
return !implementedInterfaces.isEmpty();
}
+
+ /**
+ * Ultimately, the container name should come from the <code>sessionBeanMetadata</code>.
+ * However because of the current behaviour where the container on its start sets the containername
+ * in the metadata, its not possible to get this information even before the container is started.
+ *
+ * Hence let's for the time being create the container name from all the information that we have
+ * in the <code>unit</code>
+ *
+ * @param unit The deployment unit
+ * @param sessionBeanMetadata Session bean metadata
+ * @return Returns the container name for the bean corresponding to the <code>sessionBeanMetadata</code> in the <code>unit</code>
+ *
+ * @throws MalformedObjectNameException
+ */
+ private String getContainerName(DeploymentUnit unit, JBossSessionBeanMetaData sessionBeanMetadata)
+ throws MalformedObjectNameException
+ {
+ // TODO the base ejb3 jmx object name comes from Ejb3Module.BASE_EJB3_JMX_NAME, but
+ // we don't need any reference to ejb3-core. Right now just hard code here, we need
+ // a better way/place for this later
+ StringBuilder containerName = new StringBuilder("jboss.j2ee:service=EJB3" + ",");
+
+ // Get the top level unit for this unit (ex: the top level might be an ear and this unit might be the jar
+ // in that ear
+ DeploymentUnit toplevelUnit = unit.getTopLevel();
+ if (toplevelUnit != null)
+ {
+ // if top level is an ear, then create the name with the ear reference
+ if (isEar(toplevelUnit))
+ {
+ containerName.append("ear=");
+ containerName.append(toplevelUnit.getSimpleName());
+ containerName.append(",");
+
+ }
+ }
+ // now work on the passed unit, to get the jar name
+ if (unit.getSimpleName() == null)
+ {
+ containerName.append("*");
+ }
+ else
+ {
+ containerName.append("jar=");
+ containerName.append(unit.getSimpleName());
+ }
+ // now the ejbname
+ containerName.append(",name=");
+ containerName.append(sessionBeanMetadata.getEjbName());
+
+ if (logger.isTraceEnabled())
+ {
+ logger.trace("Container name generated for ejb = " + sessionBeanMetadata.getEjbName() + " in unit " + unit
+ + " is " + containerName);
+ }
+ ObjectName containerJMXName = new ObjectName(containerName.toString());
+ return containerJMXName.getCanonicalName();
+ }
+
+ /**
+ * Returns true if this <code>unit</code> represents an .ear deployment
+ *
+ * @param unit
+ * @return
+ */
+ private boolean isEar(DeploymentUnit unit)
+ {
+ return unit.getSimpleName().endsWith(".ear");
+ }
}
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/StatefulNoInterfaceViewFactory.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/StatefulNoInterfaceViewFactory.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/StatefulNoInterfaceViewFactory.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -25,8 +25,8 @@
import org.jboss.ejb3.nointerface.NoInterfaceEJBViewCreator;
import org.jboss.ejb3.nointerface.invocationhandler.NoInterfaceViewInvocationHandler;
-import org.jboss.ejb3.proxy.container.InvokableContext;
-import org.jboss.ejb3.proxy.container.StatefulSessionInvokableContext;
+import org.jboss.ejb3.proxy.spi.container.InvokableContext;
+import org.jboss.ejb3.proxy.spi.container.StatefulSessionFactory;
import org.jboss.logging.Logger;
/**
@@ -80,16 +80,15 @@
{
logger.debug("Creating no-interface view for " + this.beanClass);
- StatefulSessionInvokableContext statefulContainer = (StatefulSessionInvokableContext) container;
- Serializable session = statefulContainer.createSession();
+ StatefulSessionFactory statefulSessionFactory = (StatefulSessionFactory) container;
+ Serializable session = statefulSessionFactory.createSession();
logger.debug("Created session " + session + " for " + this.beanClass);
NoInterfaceViewInvocationHandler invocationHandler = new NoInterfaceViewInvocationHandler(container);
- invocationHandler.setProxy(session);
+ invocationHandler.createSessionProxy(session);
// Now create the view for this bean class and the newly created invocation handler
NoInterfaceEJBViewCreator noInterfaceViewCreator = new NoInterfaceEJBViewCreator();
- Object noInterfaceView = noInterfaceViewCreator.createView(new NoInterfaceViewInvocationHandler(container),
- beanClass);
+ Object noInterfaceView = noInterfaceViewCreator.createView(invocationHandler,beanClass);
if (logger.isTraceEnabled())
{
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/NoInterfaceViewInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/NoInterfaceViewInvocationHandler.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/NoInterfaceViewInvocationHandler.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -24,9 +24,11 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
-import org.jboss.ejb3.EJBContainer;
+
import org.jboss.ejb3.common.lang.SerializableMethod;
-import org.jboss.ejb3.proxy.container.InvokableContext;
+import org.jboss.ejb3.proxy.spi.container.InvokableContext;
+import org.jboss.ejb3.proxy.spi.intf.SessionProxy;
+import org.jboss.logging.Logger;
/**
* NoInterfaceViewInvocationHandler
@@ -43,6 +45,11 @@
{
/**
+ * Logger
+ */
+ private static Logger logger = Logger.getLogger(NoInterfaceViewInvocationHandler.class);
+
+ /**
* The container to which this invocation handler corresponds to.
* All calls to this invocation handler will be forwarded to this
* container.
@@ -50,9 +57,14 @@
*/
private InvokableContext container;
- private Object proxy;
/**
+ * The {@link NoInterfaceViewInvocationHandler} and the {@link InvokableContext} interact
+ * with each other through a {@link SessionProxy}
+ */
+ private SessionProxy sessionProxy;
+
+ /**
* Constructor
* @param container
*/
@@ -69,16 +81,17 @@
* This method will do the common steps (common for SLSB and SFSB) before passing on the
* call to {@link #doInvoke(Object, Method, Object[])}
*
- * @param obj
+ * @param proxy
* @param method The invoked method
* @param args The arguments to the method
*/
- public Object invoke(Object obj, Method method, Object[] args) throws Throwable
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
+ assert this.sessionProxy != null : "Cannot invoke the container without the " + SessionProxy.class.getName();
// TODO: Some methods like toString() can be handled locally.
// But as of now let's just pass it on to the container.
SerializableMethod serializableMethod = new SerializableMethod(method);
- return getContainer().invoke(this.proxy, serializableMethod, args);
+ return getContainer().invoke(this.sessionProxy, serializableMethod, args);
}
/**
@@ -91,14 +104,63 @@
return this.container;
}
- public void setProxy(Object proxy)
+ /**
+ * Creates a {@link SessionProxy}, for the <code>target</code>, which will
+ * be used by this {@link NoInterfaceViewInvocationHandler} to interact with
+ * the {@link InvokableContext}
+ *
+ * @param target The target of an invocation (used as a sessionid)
+ */
+ public void createSessionProxy(Object target)
{
- this.proxy = proxy;
+ this.sessionProxy = new NoInterfaceViewSessionProxy();
+ this.sessionProxy.setTarget(target);
}
- public Object getProxy()
+
+ /**
+ *
+ * NoInterfaceViewSessionProxy
+ *
+ * A {@link SessionProxy} implementation for the no-interface view.
+ * Used by the {@link NoInterfaceViewInvocationHandler} to interact
+ * with the {@link InvokableContext}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ private class NoInterfaceViewSessionProxy implements SessionProxy
{
- return this.proxy;
+
+ /**
+ * The target of an invocation on the {@link NoInterfaceViewInvocationHandler} - used as a sessionId
+ */
+ private Object target;
+
+
+ /**
+ * @see SessionProxy#getTarget()
+ */
+ public Object getTarget()
+ {
+ return this.target;
+ }
+
+ /**
+ * @see SessionProxy#setTarget(Object)
+ */
+ public void setTarget(Object target)
+ {
+ this.target = target;
+ }
+
+ public void removeTarget() throws UnsupportedOperationException
+ {
+ // Is this enough?
+ this.target = null;
+
+ }
+
}
}
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -24,7 +24,7 @@
import org.jboss.beans.metadata.api.annotations.Inject;
import org.jboss.beans.metadata.api.annotations.Start;
import org.jboss.beans.metadata.api.annotations.Stop;
-import org.jboss.ejb3.proxy.container.InvokableContext;
+import org.jboss.ejb3.proxy.spi.container.InvokableContext;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -65,8 +65,9 @@
// Create the view and bind to jndi
NoInterfaceEJBViewCreator noInterfaceViewCreator = new NoInterfaceEJBViewCreator();
- Object noInterfaceView = noInterfaceViewCreator.createView(new NoInterfaceViewInvocationHandler(this.container),
- beanClass);
+ NoInterfaceViewInvocationHandler invocationHandler = new NoInterfaceViewInvocationHandler(this.container);
+ invocationHandler.createSessionProxy(null);
+ Object noInterfaceView = noInterfaceViewCreator.createView(invocationHandler, beanClass);
// bind
// TODO: Again, the jndi-names for the no-interface view are a mess now. They need to come from
// the metadata. Let's just go ahead temporarily
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/objectfactory/StatefulNoInterfaceViewObjectFactory.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/objectfactory/StatefulNoInterfaceViewObjectFactory.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/objectfactory/StatefulNoInterfaceViewObjectFactory.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -29,8 +29,8 @@
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
-import org.apache.log4j.Logger;
import org.jboss.ejb3.nointerface.factory.StatefulNoInterfaceViewFactory;
+import org.jboss.logging.Logger;
/**
* StatefulNoInterfaceViewObjectFactory
Modified: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/AbstractNoInterfaceTestCase.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/AbstractNoInterfaceTestCase.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/AbstractNoInterfaceTestCase.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -201,11 +201,11 @@
{
deploy(new File(SERVER_PROFILE_DEPLOY_DIR_PATH).toURL());
- // additionally we need the ejb3-interceptors-aop.xml which we pull in from our
- // ejb3-core dependency jar (instead of duplicating that file in our test setup)
- URL ejb3InterceptorsConfigFile = Thread.currentThread().getContextClassLoader().getResource("ejb3-interceptors-aop.xml");
- logger.debug("ejb3-interceptors-aop.xml being picked up from " + ejb3InterceptorsConfigFile);
- deploy(ejb3InterceptorsConfigFile);
+// // additionally we need the ejb3-interceptors-aop.xml which we pull in from our
+// // ejb3-core dependency jar (instead of duplicating that file in our test setup)
+// URL ejb3InterceptorsConfigFile = Thread.currentThread().getContextClassLoader().getResource("ejb3-interceptors-aop.xml");
+// logger.debug("ejb3-interceptors-aop.xml being picked up from " + ejb3InterceptorsConfigFile);
+// deploy(ejb3InterceptorsConfigFile);
}
/**
Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatefulContainer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatefulContainer.java (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatefulContainer.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -0,0 +1,135 @@
+/*
+ * 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.nointerface.test.common;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.InvocationResponse;
+import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.proxy.spi.container.InvokableContext;
+import org.jboss.ejb3.proxy.spi.container.StatefulSessionFactory;
+import org.jboss.ejb3.proxy.spi.intf.SessionProxy;
+
+/**
+ * MockStatefulContainer
+ *
+ * A mock stateful container, used for testing. The functionality is very
+ * minimal. It just creates bean instances for a session and uses those instances
+ * to pass on the method invocation.
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class MockStatefulContainer implements InvokableContext, StatefulSessionFactory
+
+{
+ /**
+ * The bean class represented by this container
+ */
+ private Class<?> beanClass;
+
+ /**
+ * Maintain the sessions
+ */
+ private static Map<Serializable,Object> sessions = new HashMap<Serializable,Object>();
+
+ /**
+ * Each session is represented by an id
+ */
+ private static Long currentSessionId = new Long(0);
+
+ /**
+ * Constructor
+ * @param beanClass
+ */
+ public MockStatefulContainer(Class<?> beanClass)
+ {
+ this.beanClass = beanClass;
+ }
+
+ /**
+ * @see InvokableContext#dynamicInvoke(Invocation)
+ */
+ public InvocationResponse dynamicInvoke(Invocation invocation) throws Throwable
+ {
+ // TODO : We don't do anything related to remoting right now in these tests.
+ // Let's ignore this for now
+ return null;
+ }
+
+ /**
+ * @see InvokableContext#invoke(SessionProxy, SerializableMethod, Object[])
+ */
+ public Object invoke(SessionProxy proxy, SerializableMethod method, Object[] args) throws Throwable
+ {
+ // get the bean instance using the target (=sessionId) from the SessionProxy
+ Object target = proxy.getTarget();
+ assert target instanceof Long : "Unexcepted target in SessionProxy. Expected a session id of type Long";
+ Long sessionid = (Long) target;
+ Object beanInstance = sessions.get(sessionid);
+ Method invokedMethod = method.toMethod();
+ return invokedMethod.invoke(beanInstance, args);
+
+ }
+
+ /**
+ * Creates a session
+ * @see StatefulSessionFactory#createSession()
+ */
+ public Serializable createSession()
+ {
+ synchronized (currentSessionId)
+ {
+ currentSessionId ++;
+ try
+ {
+ sessions.put(currentSessionId, beanClass.newInstance());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not create a session for bean " + beanClass, e);
+
+ }
+ return currentSessionId;
+ }
+
+
+ }
+
+ /**
+ * @see InvokableContext#removeTarget(Object)
+ */
+ public void removeTarget(Object target) throws UnsupportedOperationException
+ {
+ synchronized (sessions)
+ {
+ sessions.remove(target);
+ }
+
+
+ }
+
+}
Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatelessContainer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatelessContainer.java (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatelessContainer.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -0,0 +1,91 @@
+/*
+ * 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.nointerface.test.common;
+
+import java.lang.reflect.Method;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.InvocationResponse;
+import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.proxy.spi.container.InvokableContext;
+import org.jboss.ejb3.proxy.spi.intf.SessionProxy;
+
+/**
+ * MockStatelessContainer
+ *
+ * A mock stateless container, used for testing. The functionality is very
+ * minimal. It just creates bean instances of the beans and uses those instances
+ * to pass on the method invocation.
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class MockStatelessContainer implements InvokableContext
+{
+
+ /**
+ * The bean class represented by this container
+ */
+ private Class<?> beanClass;
+
+ /**
+ * Constructor
+ * @param beanClass
+ */
+ public MockStatelessContainer(Class<?> beanClass)
+ {
+ this.beanClass = beanClass;
+ }
+
+ /**
+ * @see InvokableContext#dynamicInvoke(Invocation)
+ */
+ public InvocationResponse dynamicInvoke(Invocation invocation) throws Throwable
+ {
+ // TODO : We don't do anything related to remoting right now in these tests.
+ // Let's ignore this for now
+ return null;
+ }
+
+ /**
+ * @see InvokableContext#invoke(SessionProxy, SerializableMethod, Object[])
+ */
+ public Object invoke(SessionProxy proxy, SerializableMethod method, Object[] args) throws Throwable
+ {
+ // nothing fancy, just pass on the invocation to the bean class instance
+ Method invokedMethod = method.toMethod();
+ // since this is for testing, creation of new bean instance on each invocation
+ // should be manageable
+ Object beanInstance = beanClass.newInstance();
+ return invokedMethod.invoke(beanInstance, args);
+ }
+
+ /**
+ * @see InvokableContext#removeTarget(Object)
+ */
+ public void removeTarget(Object arg0) throws UnsupportedOperationException
+ {
+ // no-op for stateless container
+
+ }
+
+}
Deleted: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/connectionmanager/MockCachedConnectionManager.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/connectionmanager/MockCachedConnectionManager.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/connectionmanager/MockCachedConnectionManager.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -1,56 +0,0 @@
-/*
- * 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.nointerface.test.connectionmanager;
-
-import java.util.Set;
-
-import javax.resource.ResourceException;
-
-import org.jboss.ejb3.EJBContainer;
-import org.jboss.jca.spi.ComponentStack;
-
-/**
- * MockCachedConnectionManager
- *
- * The {@link EJBContainer} requires a cached connection manager of type
- * {@link ComponentStack} to be injected. This {@link MockCachedConnectionManager}
- * is just for use in the no-interface tests, and does not provide any real
- * functionality
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
-public class MockCachedConnectionManager implements ComponentStack
-{
-
- public void popMetaAwareObject(Set unsharableResources) throws ResourceException
- {
- // this is a mock - do nothing
- }
-
- public void pushMetaAwareObject(Object rawKey, Set unsharableResources) throws ResourceException
- {
- // this is a mock - do nothing
-
- }
-
-}
Deleted: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EJB3DeploymentUnit.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EJB3DeploymentUnit.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EJB3DeploymentUnit.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -1,154 +0,0 @@
-/*
- * 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.nointerface.test.deployers;
-
-import java.net.URL;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.ejb3.DeploymentUnit;
-import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VirtualFileFilter;
-
-/**
- * EJB3DeploymentUnit
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
-public class EJB3DeploymentUnit implements DeploymentUnit
-{
-
- private org.jboss.deployers.structure.spi.DeploymentUnit unit;
-
- public EJB3DeploymentUnit(org.jboss.deployers.structure.spi.DeploymentUnit unit)
- {
- this.unit = unit;
- }
-
- public Object addAttachment(String name, Object attachment)
- {
- return unit.addAttachment(name, attachment);
- }
-
- public Object getAttachment(String name)
- {
- return unit.getAttachment(name);
- }
-
- public ClassLoader getClassLoader()
- {
- return unit.getClassLoader();
- }
-
- public List<Class> getClasses()
- {
- throw new RuntimeException("Not yet implemented");
- }
-
- public String getDefaultEntityManagerName()
- {
- throw new RuntimeException("Not yet implemented");
- }
-
- public Map getDefaultPersistenceProperties()
- {
- throw new RuntimeException("Not yet implemented");
- }
-
- public URL getEjbJarXml()
- {
- // TODO Is there a better way to do this? Maybe traverse through the deployment unit
- return unit.getClassLoader().getResource("ejb-jar.xml");
-
- }
-
- public InterceptorInfoRepository getInterceptorInfoRepository()
- {
- throw new RuntimeException("Not yet implemented");
- }
-
- public URL getJbossXml()
- {
- // TODO Is there a better way to do this? Maybe traverse through the deployment unit
- return unit.getClassLoader().getResource("jboss.xml");
- }
-
- public Hashtable getJndiProperties()
- {
- return null;
- }
-
- public VirtualFile getMetaDataFile(String string)
- {
- throw new RuntimeException("Not yet implemented");
- }
-
- public URL getPersistenceXml()
- {
- // TODO Is there a better way to do this? Maybe traverse through the deployment unit
- return unit.getClassLoader().getResource("persistence.xml");
- }
-
- public String getRelativePath()
- {
- return unit.getRelativePath();
- }
-
- public URL getRelativeURL(String path)
- {
- throw new RuntimeException("Not yet implemented");
- }
-
- public ClassLoader getResourceLoader()
- {
- throw new RuntimeException("Not yet implemented");
- }
-
- public List<VirtualFile> getResources(VirtualFileFilter filter)
- {
- throw new RuntimeException("Not yet implemented");
- }
-
- public VirtualFile getRootFile()
- {
- throw new RuntimeException("Not yet implemented");
- }
-
- public String getShortName()
- {
- return unit.getSimpleName();
- }
-
- public URL getUrl()
- {
- throw new RuntimeException("Not yet implemented");
- }
-
- public Object removeAttachment(String name)
- {
- return unit.removeAttachment(name);
- }
-
-}
Deleted: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbComponentDeployer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbComponentDeployer.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbComponentDeployer.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -1,122 +0,0 @@
-/*
- * 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.nointerface.test.deployers;
-
-import java.util.List;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.beans.metadata.spi.DemandMetaData;
-import org.jboss.beans.metadata.spi.DependencyMetaData;
-import org.jboss.beans.metadata.spi.SupplyMetaData;
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.Ejb3Deployment;
-import org.jboss.ejb3.Ejb3DescriptorHandler;
-import org.jboss.ejb3.MCDependencyPolicy;
-import org.jboss.ejb3.javaee.JavaEEComponentHelper;
-import org.jboss.ejb3.javaee.JavaEEModule;
-import org.jboss.ejb3.javaee.SimpleJavaEEModule;
-import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
-
-/**
- * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public class EjbComponentDeployer extends AbstractSimpleRealDeployer<JBossEnterpriseBeanMetaData>
-{
- public EjbComponentDeployer()
- {
- super(JBossEnterpriseBeanMetaData.class);
-
- setComponentsOnly(true);
-
- addOutput(BeanMetaData.class);
- }
-
- protected void addDependencies(BeanMetaDataBuilder builder, DeploymentUnit unit, EJBContainer component)
- {
- // TODO: ask something else for that name
- builder.addDependency("org.jboss.ejb3.deployment:" + unit.getSimpleName());
-
- // Hmm, should not cast, EjbDeployment knows the type
- MCDependencyPolicy dependencyPolicy = (MCDependencyPolicy) component.getDependencyPolicy();
-
- // Translating back and forth, could be done in 1 step.
- for (DemandMetaData demand : dependencyPolicy.getDemands())
- builder.addDemand(demand.getDemand());
- for (DependencyMetaData dependency : dependencyPolicy.getDependencies())
- builder.addDependency(dependency.getDependency());
- for (SupplyMetaData supply : dependencyPolicy.getSupplies())
- builder.addSupply(supply.getSupply());
- }
-
- @Override
- public void deploy(DeploymentUnit unit, JBossEnterpriseBeanMetaData metaData) throws DeploymentException
- {
- log.info("Found " + metaData + " in " + unit);
-
- JavaEEModule module = new SimpleJavaEEModule(unit.getParent().getSimpleName());
- //unit.getAttachment(JavaEEModule.class);
-
- String ejbName = metaData.getEjbName();
- String componentName = JavaEEComponentHelper.createObjectName(module, ejbName);
-
- Ejb3Deployment deployment = unit.getAttachment(Ejb3Deployment.class);
-
- EJBContainer component;
- try
- {
- // We need javassist support to pass the class to the ejb3descriptor handler?
- // The class name would have been better so that the descriptor handler could hide the (javassist) impl detail
- ClassPool pool = ClassPool.getDefault();
- CtClass beanCtClass = pool.get(metaData.getEjbClass());
-
- Ejb3DescriptorHandler ejb3DescriptorHandler = new Ejb3DescriptorHandler(deployment,
- beanCtClass.getClassFile(), metaData.getJBossMetaData());
- List<EJBContainer> ejbContainers = ejb3DescriptorHandler.getContainers(beanCtClass.getClassFile(),deployment);
- // Ideally only one container should be created
- assert ejbContainers.size() == 1: "More than one container created for bean " + metaData.getEjbClass();
- component = ejbContainers.get(0);
- }
- catch (Exception e)
- {
- throw new DeploymentException(e);
- }
-
- BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(componentName, component.getClass().getName());
- builder.setConstructorValue(component);
- addDependencies(builder, unit, component);
-
- DeploymentUnit parent = unit.getParent();
- assert parent != null : "parent should not be null of component " + unit;
-
- // add the bean meta data to the parent, because else scope merging won't occur (whatever that is)
- // (e.g. the bean won't get injected)
- parent.addAttachment(BeanMetaData.class + ":" + componentName, builder.getBeanMetaData());
- }
-}
Deleted: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbDeployment.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbDeployment.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbDeployment.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -1,117 +0,0 @@
-/*
- * 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.nointerface.test.deployers;
-
-import javax.security.jacc.PolicyConfiguration;
-
-import org.jboss.beans.metadata.api.annotations.Inject;
-import org.jboss.ejb3.DependencyPolicy;
-import org.jboss.ejb3.DeploymentScope;
-import org.jboss.ejb3.DeploymentUnit;
-import org.jboss.ejb3.Ejb3Deployment;
-import org.jboss.ejb3.cache.CacheFactoryRegistry;
-import org.jboss.ejb3.cache.persistence.PersistenceManagerFactoryRegistry;
-import org.jboss.ejb3.deployers.JBoss5DependencyPolicy;
-import org.jboss.ejb3.javaee.JavaEEComponent;
-import org.jboss.ejb3.pool.PoolFactoryRegistry;
-import org.jboss.metadata.ejb.jboss.JBossMetaData;
-
-/**
- * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public class EjbDeployment extends Ejb3Deployment
-{
- /**
- * @param deploymentUnit
- * @param unit
- * @param deploymentScope
- * @param metaData
- */
- public EjbDeployment(org.jboss.deployers.structure.spi.DeploymentUnit deploymentUnit, DeploymentUnit unit,
- DeploymentScope deploymentScope, JBossMetaData metaData)
- {
- super(deploymentUnit, unit, deploymentScope, metaData);
- }
-
- @Override
- public void create() throws Exception
- {
- // make sure we don't invoke legacy stuff
- System.err.println("******************");
- }
-
- public DependencyPolicy createDependencyPolicy(JavaEEComponent component)
- {
- return new JBoss5DependencyPolicy(component);
- }
-
- protected PolicyConfiguration createPolicyConfiguration() throws Exception
- {
- throw new RuntimeException("NYI");
- }
-
- @Override
- public void destroy()
- {
- // make sure we don't invoke legacy stuff
- }
-
- protected void putJaccInService(PolicyConfiguration pc, DeploymentUnit unit)
- {
- throw new RuntimeException("NYI");
- }
-
- @Inject
- @Override
- public void setCacheFactoryRegistry(CacheFactoryRegistry registry)
- {
- super.setCacheFactoryRegistry(registry);
- }
-
- @Inject
- @Override
- public void setPoolFactoryRegistry(PoolFactoryRegistry poolFactoryRegistry)
- {
- super.setPoolFactoryRegistry(poolFactoryRegistry);
- System.out.println("Set pool factory");
- }
-
- @Inject
- @Override
- public void setPersistenceManagerFactoryRegistry(PersistenceManagerFactoryRegistry registry)
- {
- super.setPersistenceManagerFactoryRegistry(registry);
- }
-
- @Override
- public void start() throws Exception
- {
- // make sure we don't invoke legacy stuff
- }
-
- @Override
- public void stop()
- {
- // make sure we don't invoke legacy stuff
- }
-}
Deleted: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbModuleDeployer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbModuleDeployer.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/EjbModuleDeployer.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -1,154 +0,0 @@
-/*
- * 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.nointerface.test.deployers;
-
-import org.jboss.beans.metadata.api.annotations.Inject;
-import org.jboss.beans.metadata.api.annotations.Start;
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployerWithInput;
-import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.ejb3.DeploymentScope;
-import org.jboss.ejb3.Ejb3Deployment;
-import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar;
-import org.jboss.ejb3.common.registrar.spi.Ejb3Registrar;
-import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
-import org.jboss.kernel.Kernel;
-import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
-import org.jboss.metadata.ejb.jboss.JBossMetaData;
-
-/**
- * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public class EjbModuleDeployer extends AbstractRealDeployerWithInput<JBossMetaData>
-{
- @Deprecated
- private Kernel kernel;
-
- public EjbModuleDeployer()
- {
- //addInput(EjbMetadataJndiPolicyDecoratorDeployer.EJB_DECORATED_FLAG);
-
- setDeploymentVisitor(new EjbDeploymentVisitor());
-
- addOutput(JBossEnterpriseBeanMetaData.class);
- addOutput(BeanMetaData.class);
- }
-
- private static Ejb3Deployment createModule(DeploymentUnit unit, JBossMetaData metaData)
- {
- org.jboss.ejb3.DeploymentUnit ejb3Unit = new EJB3DeploymentUnit(unit);
- DeploymentScope scope = null;
- return new EjbDeployment(unit, ejb3Unit, scope, metaData);
- }
-
- private class EjbDeploymentVisitor implements DeploymentVisitor<JBossMetaData>
- {
- public void deploy(DeploymentUnit unit, JBossMetaData metaData) throws DeploymentException
- {
- log.info("Found " + metaData + " in " + unit);
-
- // FIXME
- if(metaData.getEnterpriseBeans() == null)
- {
- log.warn(unit + " contains no beans");
- return;
- }
-
- Ejb3Deployment module = createModule(unit, metaData);
- unit.addAttachment(Ejb3Deployment.class, module);
-
- String name = "org.jboss.ejb3.deployment:" + unit.getSimpleName();
- BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(name, module.getClass().getName());
- builder.setConstructorValue(module);
- unit.addAttachment(BeanMetaData.class + ":" + name, builder.getBeanMetaData());
-
- for(JBossEnterpriseBeanMetaData bean : metaData.getEnterpriseBeans())
- {
- DeploymentUnit component = unit.addComponent(bean.getEjbName());
- component.addAttachment(JBossEnterpriseBeanMetaData.class, bean);
- }
- }
-
- public Class<JBossMetaData> getVisitorType()
- {
- return JBossMetaData.class;
- }
-
- public void undeploy(DeploymentUnit unit, JBossMetaData metaData)
- {
- // FIXME
- if(metaData.getEnterpriseBeans() == null)
- {
- return;
- }
-
- for(JBossEnterpriseBeanMetaData bean : metaData.getEnterpriseBeans())
- {
- unit.removeComponent(bean.getEjbName());
- }
- unit.removeAttachment(Ejb3Deployment.class);
- }
- }
-
- @Inject(bean="jboss.kernel:service=Kernel")
- public void setKernel(Kernel kernel)
- {
- this.kernel = kernel;
- }
-
- /**
- * LifeCycle Start
- *
- * Responsible for Binding an MC-based EJB3 Registrar Object Store
- *
- * @author ALR
- * @throws Throwable
- */
- @Start
- public void start() throws Throwable
- {
- // FIXME: do all this stuff in beans.xml
-
- // Bind an EJB3 Registrar Implementation if not already bound
- if (!Ejb3RegistrarLocator.isRegistrarBound())
- {
- // Obtain the Kernel
- Kernel sanders = this.kernel;
- assert sanders != null : Kernel.class.getSimpleName() + " must be provided in order to bind "
- + Ejb3Registrar.class.getSimpleName();
-
- // Create an EJB3 Registrar
- Ejb3Registrar registrar = new Ejb3McRegistrar(sanders);
-
- // Bind Registrar to the Locator
- Ejb3RegistrarLocator.bindRegistrar(registrar);
-
- // Log
- log.debug("Bound " + Ejb3Registrar.class.getSimpleName() + " to static "
- + Ejb3RegistrarLocator.class.getSimpleName());
- }
- }
-}
Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -0,0 +1,208 @@
+/*
+ * 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.nointerface.test.deployers;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.nointerface.test.common.MockStatefulContainer;
+import org.jboss.ejb3.nointerface.test.common.MockStatelessContainer;
+import org.jboss.ejb3.proxy.spi.container.InvokableContext;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+
+/**
+ * MockContainerDeployer
+ *
+ * A deployer (to be used ONLY for testing) which creates mock containers
+ * for session beans. The mock containers are installed into MC.
+ *
+ *
+ * @see MockStatefulContainer
+ * @see MockStatelessContainer
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class MockContainerDeployer extends AbstractDeployer
+{
+
+ private static Logger logger = Logger.getLogger(MockContainerDeployer.class);
+
+ public MockContainerDeployer()
+ {
+ setInput(JBossMetaData.class);
+ // the InvokableContext (container) will be installed as output
+ addOutput(BeanMetaData.class);
+
+ }
+
+ /**
+ * Deploy the deployment unit
+ */
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ if (logger.isTraceEnabled())
+ {
+ logger.trace("Deploying unit " + unit.getName());
+ }
+ JBossMetaData metaData = unit.getAttachment(JBossMetaData.class);
+ if (metaData == null)
+ {
+ if (logger.isTraceEnabled())
+ logger.trace("No JBossMetadata for unit : " + unit.getName());
+ return;
+ }
+ // work on the ejbs
+ JBossEnterpriseBeansMetaData beans = metaData.getEnterpriseBeans();
+ for (JBossEnterpriseBeanMetaData bean : beans)
+ {
+ if (bean.isSession())
+ {
+ if (logger.isTraceEnabled())
+ {
+ logger.trace("Found bean of type session: " + bean.getEjbClass() + " in unit " + unit.getName());
+ }
+ // Create a container for each bean
+ deploy(unit, (JBossSessionBeanMetaData) bean);
+ }
+ }
+
+ }
+
+
+ private void deploy(DeploymentUnit unit, JBossSessionBeanMetaData sessionBeanMetadata) throws DeploymentException
+ {
+ try
+ {
+ String beanClassName = sessionBeanMetadata.getEjbClass();
+ InvokableContext container = null;
+ if (sessionBeanMetadata.isStateless())
+ {
+ container = new MockStatelessContainer(Class.forName(beanClassName, false, unit.getClassLoader()));
+ }
+ else if (sessionBeanMetadata.isStateful())
+ {
+ container = new MockStatefulContainer(Class.forName(beanClassName, false, unit.getClassLoader()));
+ }
+ else
+ {
+ logger
+ .warn("Support for only stateful/stateless beans available, right now in the tests. Ignoring bean class "
+ + beanClassName);
+ return;
+ }
+ // install the container in MC. Getting the container name is currently duplicated (copied from)
+ // Ejb3NoInterfaceDeployer.
+ String containerName = getContainerName(unit, sessionBeanMetadata);
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(containerName, InvokableContext.class.getName());
+ builder.setConstructorValue(container);
+
+ unit.addAttachment(BeanMetaData.class + ":" + containerName, builder.getBeanMetaData());
+
+ }
+ catch (Exception e)
+ {
+ logger.error("Error in " + MockContainerDeployer.class + " while creating a container for unit " + unit, e);
+ DeploymentException.rethrowAsDeploymentException("Could not create container for unit " + unit, e);
+ }
+ }
+ /**
+ *
+ * Ultimately, the container name should come from the <code>sessionBeanMetadata</code>.
+ * However because of the current behaviour where the container on its start sets the containername
+ * in the metadata, its not possible to get this information even before the container is started.
+ *
+ * Hence let's for the time being create the container name from all the information that we have
+ * in the <code>unit</code>
+ *
+ * @param unit The deployment unit
+ * @param sessionBeanMetadata Session bean metadata
+ * @return Returns the container name for the bean corresponding to the <code>sessionBeanMetadata</code> in the <code>unit</code>
+ *
+ * @throws MalformedObjectNameException
+ */
+ private String getContainerName(DeploymentUnit unit, JBossSessionBeanMetaData sessionBeanMetadata)
+ throws MalformedObjectNameException
+ {
+ // TODO the base ejb3 jmx object name comes from Ejb3Module.BASE_EJB3_JMX_NAME, but
+ // we don't need any reference to ejb3-core. Right now just hard code here, we need
+ // a better way/place for this later
+ StringBuilder containerName = new StringBuilder("jboss.j2ee:service=EJB3" + ",");
+
+ // Get the top level unit for this unit (ex: the top level might be an ear and this unit might be the jar
+ // in that ear
+ DeploymentUnit toplevelUnit = unit.getTopLevel();
+ if (toplevelUnit != null)
+ {
+ // if top level is an ear, then create the name with the ear reference
+ if (isEar(toplevelUnit))
+ {
+ containerName.append("ear=");
+ containerName.append(toplevelUnit.getSimpleName());
+ containerName.append(",");
+
+ }
+ }
+ // now work on the passed unit, to get the jar name
+ if (unit.getSimpleName() == null)
+ {
+ containerName.append("*");
+ }
+ else
+ {
+ containerName.append("jar=");
+ containerName.append(unit.getSimpleName());
+ }
+ // now the ejbname
+ containerName.append(",name=");
+ containerName.append(sessionBeanMetadata.getEjbName());
+
+ if (logger.isTraceEnabled())
+ {
+ logger.trace("Container name generated for ejb = " + sessionBeanMetadata.getEjbName() + " in unit " + unit
+ + " is " + containerName);
+ }
+ ObjectName containerJMXName = new ObjectName(containerName.toString());
+ return containerJMXName.getCanonicalName();
+ }
+
+ /**
+ * Returns true if this <code>unit</code> represents an .ear deployment
+ *
+ * @param unit
+ * @return
+ */
+ private boolean isEar(DeploymentUnit unit)
+ {
+ return unit.getSimpleName().endsWith(".ear");
+ }
+
+}
Deleted: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/javaee/SimpleJavaEEModuleInformer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/javaee/SimpleJavaEEModuleInformer.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/javaee/SimpleJavaEEModuleInformer.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -1,82 +0,0 @@
-/*
- * 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.nointerface.test.javaee;
-
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.jpa.javaee.JavaEEModuleInformer;
-import org.jboss.metadata.client.jboss.JBossClientMetaData;
-import org.jboss.metadata.ear.jboss.JBossAppMetaData;
-import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
-import org.jboss.metadata.ejb.jboss.JBossEntityBeanMetaData;
-import org.jboss.metadata.ejb.jboss.JBossMetaData;
-import org.jboss.metadata.web.jboss.JBossWebMetaData;
-
-/**
- * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public class SimpleJavaEEModuleInformer implements JavaEEModuleInformer
-{
- public String getApplicationName(DeploymentUnit unit)
- {
- DeploymentUnit topLevel = unit.getTopLevel();
- if(topLevel.isAttachmentPresent(JBossAppMetaData.class))
- return topLevel.getSimpleName();
- return null;
- }
-
- public String getModulePath(DeploymentUnit unit)
- {
- return unit.getRelativePath();
- }
-
- public ModuleType getModuleType(DeploymentUnit unit)
- {
- if(unit.isAttachmentPresent(JBossClientMetaData.class))
- return ModuleType.APP_CLIENT;
- if(unit.isAttachmentPresent(JBossMetaData.class) && isReallyAnEjbDeployment(unit))
- return ModuleType.EJB;
- if(unit.isAttachmentPresent(JBossWebMetaData.class))
- return ModuleType.WEB;
- return ModuleType.JAVA;
- }
-
- /*
- * Some hacks to counter problems.
- */
- private boolean isReallyAnEjbDeployment(DeploymentUnit unit)
- {
- JBossMetaData metaData = unit.getAttachment(JBossMetaData.class);
- // JBMETA-69
- if(metaData.getEnterpriseBeans() == null || metaData.getEnterpriseBeans().size() == 0)
- return false;
- // JBMETA-70
- // The chance of a persistence unit being defined with couple of EJB entity beans is
- // pretty slim.
- for(JBossEnterpriseBeanMetaData bean : metaData.getEnterpriseBeans())
- {
- if(!(bean instanceof JBossEntityBeanMetaData))
- return true;
- }
- return false;
- }
-}
Modified: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSFSBean.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSFSBean.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSFSBean.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -33,4 +33,22 @@
public class SimpleSFSBean
{
+ public static final int INITIAL_QTY = 2;
+
+ private int qtyPurchased = INITIAL_QTY;
+
+ public int getQtyPurchased()
+ {
+ return this.qtyPurchased;
+ }
+
+ public void incrementPurchaseQty()
+ {
+ this.qtyPurchased ++;
+ }
+
+ public static void someStaticMethod()
+ {
+ // do nothing
+ }
}
Modified: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java 2009-03-16 10:32:09 UTC (rev 85890)
@@ -23,12 +23,15 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import java.lang.reflect.Method;
+
import javax.naming.Context;
import javax.naming.InitialContext;
-import org.jboss.ejb3.nointerface.NoInterfaceEJBViewCreator;
import org.jboss.ejb3.nointerface.test.common.AbstractNoInterfaceTestCase;
+import org.jboss.ejb3.nointerface.test.viewcreator.ChildBean;
import org.jboss.ejb3.nointerface.test.viewcreator.SimpleSFSBean;
import org.jboss.ejb3.nointerface.test.viewcreator.SimpleSLSBWithoutInterface;
import org.jboss.ejb3.test.common.MetaDataHelper;
@@ -41,7 +44,9 @@
/**
* NoInterfaceEJBViewCreatorTestCase
*
- * Tests the {@link NoInterfaceEJBViewCreator}
+ * Tests the no-inteface view for beans. The test cases here mainly
+ * ensure that the no-interface view is created and bound. More rigorous
+ * testing of the no-interface view will be done in the "profile3_1" environment.
*
* @author Jaikiran Pai
* @version $Revision: $
@@ -129,58 +134,92 @@
assertTrue("No-interface view for SFSB is not an instance of " + SimpleSFSBean.class.getName(),
(noInterfaceView instanceof SimpleSFSBean));
+ }
+ /**
+ * Test that the no-interface view works as expected when the bean extends from some other class
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testNoInterfaceViewForInheritedBean() throws Exception
+ {
+
+ JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper.getMetadataFromBeanImplClass(ChildBean.class);
+ String jndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
+
+ // ensure that the bean is bound
+ Context ctx = new InitialContext();
+ Object bean = ctx.lookup(jndiName);
+
+ assertNotNull("No-interface view for ChildBean returned null from JNDI", bean);
+
+ assertTrue("No-interface view for ChildBean is not an instance of " + ChildBean.class.getName(),
+ (bean instanceof ChildBean));
+
}
- // Other tests will be enabled once the component is more testable
+ /**
+ * Test to ensure that the no-interface view instance does NOT consider
+ * a final method on the bean while creating the view
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testFinalMethodsAreNotConsideredInView() throws Exception
+ {
+ JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper
+ .getMetadataFromBeanImplClass(SimpleSLSBWithoutInterface.class);
+ String jndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
- // /**
- // * Test to ensure that the no-interface view instance does NOT consider
- // * a final method on the bean while creating the view
- // *
- // * @throws Exception
- // */
- // @Test
- // public void testFinalMethodsAreNotConsideredInView() throws Exception
- // {
- // MethodInvocationTrackingContainer mockContainer = new MethodInvocationTrackingContainer(
- // SimpleSLSBWithoutInterface.class);
- // SimpleSLSBWithoutInterface noInterfaceView = noInterfaceViewCreator.createView(mockContainer,
- // SimpleSLSBWithoutInterface.class);
+ // let's just assume the bean is bound and is of the expected type.
+ // there are other tests which test the correctness of the bindings.
+ Context ctx = new InitialContext();
+ SimpleSLSBWithoutInterface bean = (SimpleSLSBWithoutInterface) ctx.lookup(jndiName);
+
+ // Nothing fancy to test - just ensure that the declared methods in the proxy does
+ // NOT contain a "final" method. Just check on method name, should be enough
+ Method[] declaredMethods = bean.getClass().getDeclaredMethods();
+ for (Method declaredMethod : declaredMethods)
+ {
+ if (declaredMethod.getName().equals("someFinalMethod"))
+ {
+ fail("No-interface view has overriden a final method. It shouldn't have.");
+ }
+ }
+
+ }
+
+ /**
+ * Test to ensure that the no-interface view instance does NOT consider
+ * a static method on the bean while creating the view
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testStaticMethodsAreNotConsideredInView() throws Exception
+ {
+ JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper.getMetadataFromBeanImplClass(SimpleSFSBean.class);
+ String jndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
+
+ // let's just assume the bean is bound and is of the expected type.
+ // there are other tests which test the correctness of the bindings.
+ Context ctx = new InitialContext();
+ SimpleSFSBean bean = (SimpleSFSBean) ctx.lookup(jndiName);
+
+ // Nothing fancy to test - just ensure that the declared methods in the proxy does
+ // NOT contain a "final" method. Just check on method name, should be enough
+ Method[] declaredMethods = bean.getClass().getDeclaredMethods();
+ for (Method declaredMethod : declaredMethods)
+ {
+ if (declaredMethod.getName().equals("someStaticMethod"))
+ {
+ fail("No-interface view has overriden a static method. It shouldn't have.");
+ }
+ }
+ }
//
- // noInterfaceView.someFinalMethod();
- //
- // assertEquals("Final method of bean " + SimpleSLSBWithoutInterface.class.getName()
- // + " was included in no-inteface view", 0, mockContainer.getTrackedMethodNames().size());
- //
- // }
- //
// /**
- // * Test to ensure that the no-interface view instance does NOT consider
- // * a static method on the bean while creating the view
- // *
- // * @throws Exception
- // */
- // @Test
- // public void testStaticMethodsAreNotConsideredInView() throws Exception
- // {
- // MethodInvocationTrackingContainer mockContainer = new MethodInvocationTrackingContainer(
- // SimpleSLSBWithoutInterface.class);
- // SimpleSLSBWithoutInterface noInterfaceView = noInterfaceViewCreator.createView(mockContainer,
- // SimpleSLSBWithoutInterface.class);
- //
- // noInterfaceView.someStaticMethod();
- //
- // assertEquals("Static method of bean " + SimpleSLSBWithoutInterface.class.getName()
- // + " was included in no-inteface view", 0, mockContainer.getTrackedMethodNames().size());
- //
- // noInterfaceView.someStaticFinalMethod(3);
- // assertEquals("Static final method of bean " + SimpleSLSBWithoutInterface.class.getName()
- // + " was included in no-inteface view", 0, mockContainer.getTrackedMethodNames().size());
- //
- // }
- //
- // /**
// * Test that multiple invocations to the {@link NoInterfaceEJBViewCreator#createView(java.lang.reflect.InvocationHandler, Class)}
// * returns different instances of the view with unique view-classnames
// *
@@ -206,39 +245,4 @@
// .equals(anotherNoInterfaceViewOnSameBean));
// }
//
- // /**
- // * Test that the no-interface view works as expected when the bean extends from some other class
- // *
- // * @throws Exception
- // */
- // @Test
- // public void testNoInterfaceViewCreatorWithInheritedClasses() throws Exception
- // {
- // MethodInvocationTrackingContainer mockContainer = new MethodInvocationTrackingContainer(ChildBean.class);
- //
- // ChildBean noInterfaceView = noInterfaceViewCreator.createView(mockContainer, ChildBean.class);
- //
- // int numberOfInvokedMethods = 0;
- // noInterfaceView.sayHiFromBase("jaikiran");
- // numberOfInvokedMethods++;
- //
- // noInterfaceView.sayHiFromChild("jaikiran");
- // numberOfInvokedMethods++;
- //
- // noInterfaceView.somePublicMethod(4);
- // numberOfInvokedMethods++;
- //
- // // Do NOT increment the counter, since we are calling the final method
- // // which will NOT be covered by the no-interface view
- // noInterfaceView.someFinalMethod();
- //
- // logger.debug("Number of methods invoked on bean = " + numberOfInvokedMethods);
- //
- // assertNotNull("Methods on no-interface view on inherited bean were not tracked by container", mockContainer.getTrackedMethodNames());
- // assertEquals("The container did not handle the expected number of calls on the inherited bean",
- // numberOfInvokedMethods, mockContainer.getTrackedMethodNames().size());
- //
- //
- //
- // }
}
Modified: projects/ejb3/trunk/nointerface/src/test/resources/deployers/ejb3-deployers-jboss-beans.xml
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/resources/deployers/ejb3-deployers-jboss-beans.xml 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/resources/deployers/ejb3-deployers-jboss-beans.xml 2009-03-16 10:32:09 UTC (rev 85890)
@@ -5,75 +5,8 @@
<bean name="EjbAnnotationMetaDataDeployer" class="org.jboss.ejb3.deployers.EjbAnnotationMetaDataDeployer"/>
<bean name="MergedJBossMetaDataDeployer" class="org.jboss.ejb3.deployers.MergedJBossMetaDataDeployer"/>
+ <!-- A deployer which creates mocked containers for tests -->
+ <bean name="MockContainerDeployer" class="org.jboss.ejb3.nointerface.test.deployers.MockContainerDeployer"/>
-<!-- To create the containers -->
- <bean name="EjbModuleDeployer" class="org.jboss.ejb3.nointerface.test.deployers.EjbModuleDeployer"/>
- <bean name="EjbComponentDeployer" class="org.jboss.ejb3.nointerface.test.deployers.EjbComponentDeployer"/>
- <bean name="MessageDestinationReferenceResolver" class="org.jboss.ejb3.resolvers.DefaultMessageDestinationReferenceResolver"/>
-
- <!-- EJB containers need this cached connection manager -->
- <bean name="EmbeddedCachedConnectionManagerBridge" class="org.jboss.ejb3.nointerface.test.connectionmanager.MockCachedConnectionManager"/>
-
- <!-- EJB3 Cache Factory Registry -->
- <bean name="EJB3CacheFactoryRegistry" class="org.jboss.ejb3.cache.CacheFactoryRegistry">
- <property name="factories">
- <!-- Define each of the registered factories -->
- <map class="java.util.HashMap" keyClass="java.lang.String"
- valueClass="java.lang.Class">
- <!-- NoPassivationCache -->
- <entry>
- <key>NoPassivationCache</key>
- <value>org.jboss.ejb3.cache.NoPassivationCacheFactory</value>
- </entry>
- <!-- SimpleStatefulCache -->
- <entry>
- <key>SimpleStatefulCache</key>
- <value>org.jboss.ejb3.cache.simple.SimpleStatefulCacheFactory</value>
- </entry>
- <!-- StatefulTreeCache -->
- <entry>
- <key>StatefulTreeCache</key>
- <value>org.jboss.ejb3.cache.tree.StatefulTreeCacheFactory</value>
- </entry>
- </map>
- </property>
- </bean>
-
- <!-- EJB3 Persistence Manager Factory Registry -->
- <bean name="EJB3PersistenceManagerFactoryRegistry" class="org.jboss.ejb3.cache.persistence.PersistenceManagerFactoryRegistry">
- <property name="factories">
- <!-- Define each of the registered factories -->
- <map class="java.util.HashMap" keyClass="java.lang.String"
- valueClass="java.lang.Class">
- <!-- StatefulSessionFilePersistenceManager -->
- <entry>
- <key>StatefulSessionFilePersistenceManager</key>
- <value>org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManagerFactory</value>
- </entry>
- </map>
- </property>
- </bean>
-
- <!-- EJB3 Pool Factory Registry -->
- <bean name="EJB3PoolFactoryRegistry" class="org.jboss.ejb3.pool.PoolFactoryRegistry">
- <property name="factories">
- <!-- Define each of the registered factories -->
- <map class="java.util.HashMap" keyClass="java.lang.String"
- valueClass="java.lang.Class">
- <!-- ThreadlocalPool -->
- <entry>
- <key>ThreadlocalPool</key>
- <value>org.jboss.ejb3.pool.ThreadlocalPoolFactory</value>
- </entry>
- <!-- StrictMaxPool -->
- <entry>
- <key>StrictMaxPool</key>
- <value>org.jboss.ejb3.pool.StrictMaxPoolFactory</value>
- </entry>
- </map>
- </property>
- </bean>
-
-
</deployment>
\ No newline at end of file
Deleted: projects/ejb3/trunk/nointerface/src/test/resources/deployers/jpa-deployers-jboss-beans.xml
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/resources/deployers/jpa-deployers-jboss-beans.xml 2009-03-16 10:15:23 UTC (rev 85889)
+++ projects/ejb3/trunk/nointerface/src/test/resources/deployers/jpa-deployers-jboss-beans.xml 2009-03-16 10:32:09 UTC (rev 85890)
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<deployment xmlns="urn:jboss:bean-deployer:2.0">
-
-<!-- Probably needs to come from a jpa-profile -->
- <bean name="PersistenceUnitDependencyResolver" class="org.jboss.jpa.resolvers.DefaultPersistenceUnitDependencyResolver"/>
- <bean name="SpecCompliantSearchStrategy" class="org.jboss.jpa.resolvers.strategy.SpecCompliantSearchStrategy"/>
- <bean name="JavaEEModuleInformer" class="org.jboss.ejb3.nointerface.test.javaee.SimpleJavaEEModuleInformer"/>
-</deployment>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list