[jboss-cvs] JBossAS SVN: r97221 - in projects/ejb3/trunk/nointerface: src/main/java/org/jboss/ejb3/nointerface and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Dec 1 07:09:14 EST 2009
Author: jaikiran
Date: 2009-12-01 07:09:13 -0500 (Tue, 01 Dec 2009)
New Revision: 97221
Added:
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/NoInterfaceEJBViewFactoryBase.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/NoInterfaceViewFactory.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/factory/
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/factory/unit/
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/factory/unit/NoInterfaceViewFactoryTestCase.java
Removed:
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewFactoryBase.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceViewFactory.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/connectionmanager/
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/javaee/
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MethodInvocationTrackingContainer.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/
projects/ejb3/trunk/nointerface/src/test/resources/conf/
projects/ejb3/trunk/nointerface/src/test/resources/deploy/
projects/ejb3/trunk/nointerface/src/test/resources/deployers/
projects/ejb3/trunk/nointerface/src/test/resources/jndi.properties
Modified:
projects/ejb3/trunk/nointerface/pom.xml
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/MCAwareStatefulNoInterfaceViewFactory.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java
projects/ejb3/trunk/nointerface/src/test/resources/log4j.xml
Log:
EJBTHREE-1727 Complete overhaul of the test cases. A new nointerface testsuite component will be added later
Modified: projects/ejb3/trunk/nointerface/pom.xml
===================================================================
--- projects/ejb3/trunk/nointerface/pom.xml 2009-12-01 11:52:28 UTC (rev 97220)
+++ projects/ejb3/trunk/nointerface/pom.xml 2009-12-01 12:09:13 UTC (rev 97221)
@@ -24,44 +24,14 @@
<properties>
<version.org.jboss.deployers>2.0.8.GA</version.org.jboss.deployers>
<version.org.jboss.microcontainer>2.0.8.GA</version.org.jboss.microcontainer>
- <version.org.jboss_jboss-vfs>2.1.2.GA</version.org.jboss_jboss-vfs>
<version.org.jboss_jbossxb>2.0.1.GA</version.org.jboss_jbossxb>
<version.javassist>3.7.1.GA</version.javassist>
<version.org.jboss.ejb3_jboss-ejb3-test>1.0.0</version.org.jboss.ejb3_jboss-ejb3-test>
- <version.org.jboss.ejb3_jboss-ejb3-deployers>1.0.1</version.org.jboss.ejb3_jboss-ejb3-deployers>
- <version.org.jboss.ejb3_jboss-ejb3-endpoint-deployer>0.1.4</version.org.jboss.ejb3_jboss-ejb3-endpoint-deployer>
- <version.org.jboss.bootstrap_jboss-bootstrap>1.0.0-Beta-1</version.org.jboss.bootstrap_jboss-bootstrap>
- <version.org.jboss.bootstrap_jboss-bootstrap-impl-mc>2.0.0-alpha-1</version.org.jboss.bootstrap_jboss-bootstrap-impl-mc>
</properties>
<build>
- <!-- we use the target/test-classes as our root of all the
- deployments for our test cases. We cannot have other resources in that
- folder which can cause deployment exceptions. So we create a new target/test-resources folder
- where all resources (except) jndi.properties will be copied to during mvn -->
- <testResources>
- <!-- Copy everything except jndi.properties to target/test-resources -->
- <testResource>
- <!-- Relative to tests-classes -->
- <targetPath>../test-resources</targetPath>
- <directory>${basedir}/src/test/resources</directory>
- <excludes>
- <exclude>jndi.properties</exclude>
- </excludes>
- </testResource>
- <!-- Copy jndi.properties to target/tests-classes, so that its available
- first in the list of classpath.
- -->
- <testResource>
- <!-- Relative to tests-classes -->
- <directory>${basedir}/src/test/resources</directory>
- <includes>
- <include>jndi.properties</include>
- </includes>
- </testResource>
+
- </testResources>
-
<plugins>
<!-- We have a dependency on @LocalBean which comes from ejb3-api (=JDK6) -->
<plugin>
@@ -88,10 +58,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <!-- Add our specific target/test-resources to the test classpath -->
- <additionalClasspathElements>
- <additionalClasspathElement>${basedir}/target/test-resources</additionalClasspathElement>
- </additionalClasspathElements>
+
<!-- Use Java6 -->
<forkMode>once</forkMode>
<jvm>${JDK6_HOME}/bin/java</jvm>
@@ -141,14 +108,7 @@
<scope>test</scope>
</dependency>
- <!-- Bootstrap -->
- <dependency>
- <groupId>org.jboss.bootstrap</groupId>
- <artifactId>jboss-bootstrap-impl-mc</artifactId>
- <version>${version.org.jboss.bootstrap_jboss-bootstrap-impl-mc}</version>
- <scope>test</scope>
- </dependency>
-
+
<!-- MC -->
<dependency>
<groupId>org.jboss.microcontainer</groupId>
@@ -222,36 +182,8 @@
<version>${version.org.jboss.deployers}</version>
</dependency>
+
<dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-vfs</artifactId>
- <version>${version.org.jboss_jboss-vfs}</version>
- <scope>test</scope>
- </dependency>
-
- <!-- EJB3 deployers only for test scope-->
- <dependency>
- <groupId>org.jboss.ejb3</groupId>
- <artifactId>jboss-ejb3-deployers</artifactId>
- <version>${version.org.jboss.ejb3_jboss-ejb3-deployers}</version>
- <scope>test</scope>
- </dependency>
-
- <!-- EJB3 Endpoint deployers for test scope -->
- <dependency>
- <groupId>org.jboss.ejb3</groupId>
- <artifactId>jboss-ejb3-endpoint-deployer</artifactId>
- <version>${version.org.jboss.ejb3_jboss-ejb3-endpoint-deployer}</version>
- <scope>test</scope>
- </dependency>
-<!--
- <dependency>
- <groupId>trove</groupId>
- <artifactId>trove</artifactId>
- <scope>runtime</scope>
- </dependency>
--->
- <dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-endpoint</artifactId>
<version>0.1.0</version>
@@ -262,18 +194,10 @@
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-api</artifactId>
- <version>3.1.0-SNAPSHOT</version>
+ <version>3.1.1-SNAPSHOT</version>
</dependency>
- <!-- Transaction support for tests -->
- <!-- This jboss-ejb3-jta-profile dependency provides a jboss-beans.xml through which the transaction manager gets deployed -->
- <dependency>
- <groupId>org.jboss.ejb3</groupId>
- <artifactId>jboss-ejb3-jta-profile</artifactId>
- <version>0.1.0-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
-
+
<dependency>
<groupId>org.jboss.naming</groupId>
<artifactId>jnp-client</artifactId>
@@ -281,43 +205,7 @@
</dependency>
- <!-- Support for deploying containers in test -->
- <!-- FIXME: this must be ejb3-deployers, because else we get a recursive dependency -->
- <!-- FIXME: this also implies the use of Java 6 -->
- <dependency>
- <groupId>org.jboss.ejb3</groupId>
- <artifactId>jboss-ejb3-embedded</artifactId>
- <version>1.0.0-Alpha-2</version>
- <scope>test</scope>
- <exclusions>
- <!-- comes in through org.jboss.aop:jboss-aop-asintegration-core -->
- <exclusion>
- <groupId>org.jboss.aop</groupId>
- <artifactId>jboss-aop-deployer-jdk50</artifactId>
- </exclusion>
- <!-- Embedded uses new bootstrap impls; leaking makes collisions between legacy and new -->
- <exclusion>
- <groupId>org.jboss.bootstrap</groupId>
- <artifactId>jboss-bootstrap-impl-mc</artifactId>
- </exclusion>
- <!-- core is brought in separately instead of from embedded -->
- <exclusion>
- <groupId>org.jboss.ejb3</groupId>
- <artifactId>jboss-ejb3-core</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jboss.deployers</groupId>
- <artifactId>jboss-deployers-impl</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.ejb3</groupId>
- <artifactId>jboss-ejb3-core</artifactId>
- <version>1.1.21</version>
- <scope>test</scope>
- </dependency>
+
</dependencies>
</project>
Deleted: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewFactoryBase.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewFactoryBase.java 2009-12-01 11:52:28 UTC (rev 97220)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewFactoryBase.java 2009-12-01 12:09:13 UTC (rev 97221)
@@ -1,284 +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;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.Set;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtField;
-import javassist.CtMethod;
-import javassist.CtNewMethod;
-import javassist.LoaderClassPath;
-import javassist.Modifier;
-
-import org.jboss.logging.Logger;
-
-/**
- * NoInterfaceEJBViewFactoryBase
- *
- * Creates a no-interface view for a EJB as per the EJB3.1 spec (section 3.4.4)
- *
- * @see NoInterfaceViewFactory
- * @author Jaikiran Pai
- * @version $Revision: $
- */
-public class NoInterfaceEJBViewFactoryBase implements NoInterfaceViewFactory
-{
-
- /**
- * The proxies (sub-classes) created for the bean class need to be
- * unique. This unique number is appended to the generated class name
- */
- private static long nextUniqueNumberForNoViewInterfaceClassName = 0;
-
- /**
- * Used while generating unique number for the proxy class
- */
- private static Object nextUniqueNumberLock = new Object();
-
- /**
- * Logger
- */
- private static Logger logger = Logger.getLogger(NoInterfaceEJBViewFactoryBase.class);
-
- /**
- * Inspects the bean class for all public methods and creates a proxy (sub-class)
- * out of it with overriden implementation of the public methods. The overriden
- * implementation will just give a call to <code>container</code>'s invoke(...) method
- * which handles the actual call.
- *
- * @param <T>
- * @param invocationHandler The container correpsonding to the bean class
- * @param beanClass The bean class (currently assumed)
- * @return Returns the no-interface view for the <code>beanClass</code>
- * @throws Exception
- */
- public <T> T createView(InvocationHandler invocationHandler, Class<T> beanClass) throws Exception
- {
- if (logger.isTraceEnabled())
- {
- logger.trace("Creating nointerface view for beanClass: " + beanClass + " with container " + invocationHandler);
- }
-
- // Create a ClassPool and add the classpath using the classloader of the beanClass, so
- // that it uses the correct jar while looking up the class
- ClassPool pool = new ClassPool();
- pool.appendClassPath(new LoaderClassPath(beanClass.getClassLoader()));
-
- CtClass beanCtClass = pool.get(beanClass.getName());
-
- // Create a sub-class (proxy) for the bean class. A unique name will be used for the subclass
- CtClass proxyCtClass = pool.makeClass(beanClass.getName() + "_NoInterfaceProxy$" + getNextUniqueNumber(),
- beanCtClass);
-
- // We need to maintain a reference of the invocationHandler in the proxy, so that we can
- // forward the method calls to invocationHandler.invoke. Create a new field in the sub-class (proxy)
- CtField invocationHandlerField = CtField.make("private java.lang.reflect.InvocationHandler invocationHandler;",
- proxyCtClass);
- proxyCtClass.addField(invocationHandlerField);
-
- // get all public methods from the bean class
- Set<CtMethod> beanPublicMethods = getAllPublicNonStaticNonFinalMethods(beanCtClass);
-
- // Override each of the public methods
- for (CtMethod beanPublicMethod : beanPublicMethods)
- {
- // Methods from java.lang.Object can be skipped, if they are
- // not implemented (overriden) in the bean class. TODO: Do we really need to do this?
- if (shouldMethodBeSkipped(pool, beanPublicMethod))
- {
- logger.debug("Skipping " + beanPublicMethod.getName() + " on bean " + beanCtClass.getName()
- + " from no-interface view");
- continue;
- }
- // We should not be changing the bean class methods. So we need to create a copy of the methods
- // for the sub-class (proxy)
- CtMethod proxyPublicMethod = CtNewMethod.copy(beanPublicMethod, proxyCtClass, null);
- // All the public methods of the bean should now be overriden (through the proxy)
- // to give a call to the container.invoke
- // Ex: If the bean's public method was:
- // public String sayHi(String name) { return "Hi " + name; }
- // then it will be changed in the proxy to
- // public String sayHi(String name) { java.lang.reflect.Method currentMethod = beanClass.getName() + ".class.getMethod(theMethodName,params);
- // return container.invoke(this,currentMethod,args); }
- proxyPublicMethod = overridePublicMethod(invocationHandler, beanClass, beanPublicMethod, proxyPublicMethod);
- // We have now created the overriden method. We need to add it to the proxy
- proxyCtClass.addMethod(proxyPublicMethod);
- if (logger.isTraceEnabled())
- {
- logger.trace("Added overriden implementation for method " + proxyPublicMethod.getName()
- + " in no-interface view " + proxyCtClass.getName() + " for bean " + beanClass.getName());
- }
- }
- // Add java.io.Serializable as the interface for the proxy (since it goes into JNDI)
- //proxyCtClass.addInterface(pool.get(Serializable.class.getName()));
- proxyCtClass.addMethod(createEqualsMethod(pool, proxyCtClass));
-
- // We are almost done (except for setting the container field in the proxy)
- // Let's first create a java.lang.Class (i.e. load) out of the javassist class
- // using the classloader of the bean
- Class<?> proxyClass = proxyCtClass.toClass(beanClass.getClassLoader(), beanClass.getProtectionDomain());
- // time to set the container field through normal java reflection
- Object proxyInstance = proxyClass.newInstance();
- Field containerInProxy = proxyClass.getDeclaredField("invocationHandler");
- containerInProxy.setAccessible(true);
- containerInProxy.set(proxyInstance, invocationHandler);
-
- // return the proxy instance
- return beanClass.cast(proxyInstance);
-
- }
-
- private <T> CtMethod overridePublicMethod(InvocationHandler container, Class<T> beanClass,
- CtMethod publicMethodOnBean, CtMethod publicMethodOnProxy) throws Exception
- {
- publicMethodOnProxy.setBody("{"
- +
- // The proxy needs to call the container.invoke
- // the InvocationHandler.invoke accepts (Object proxy,Method method,Object[] args)
- // This view needs to create a java.lang.reflect.Method object based on the "current method"
- // that is invoked on the view. Note that we need to get the Method from the beanclass.
- // Note: All the '$' parameters used are javassist specific syntax
- "java.lang.reflect.Method currentMethod = " + beanClass.getName() + ".class.getMethod(\""
- + publicMethodOnBean.getName() + "\",$sig);" +
- // At this point we have the container, the Method to be invoked and the parameters to be passed
- // All we have to do is invoke the container
- "return ($r) invocationHandler.invoke(this,currentMethod,$args);" + "}");
-
- return publicMethodOnProxy;
- }
-
- /**
- * Returns all public, non-static and non-final methods for the class
- *
- * @param ctClass The class whose non-final, non-static public methods are to be returned
- * @return
- * @throws Exception
- */
- private Set<CtMethod> getAllPublicNonStaticNonFinalMethods(CtClass ctClass) throws Exception
- {
- CtMethod[] allMethods = ctClass.getMethods();
- Set<CtMethod> publicMethods = new HashSet<CtMethod>();
-
- for (CtMethod ctMethod : allMethods)
- {
- int modifier = ctMethod.getModifiers();
- // Public non-static non-final methods
- if (((Modifier.PUBLIC & modifier) == Modifier.PUBLIC) && ((Modifier.STATIC & modifier) != Modifier.STATIC)
- && ((Modifier.FINAL & modifier) != Modifier.FINAL) && ((Modifier.NATIVE & modifier) != Modifier.NATIVE))
- {
- publicMethods.add(ctMethod);
- }
- }
- return publicMethods;
- }
-
- /**
- * Checks whether a method has to be skipped from being overriden in the proxy
- * that is returned for the no-interface view.
- *
- * TODO: Do we really need this. Need to think more. Let's keep it for the time-being
- *
- * @param beanCtClass
- * @param ctMethod
- * @return
- * @throws Exception
- */
- private boolean shouldMethodBeSkipped(CtClass beanCtClass, CtMethod ctMethod) throws Exception
- {
-
- // List<CtMethod> declaredMethods = Arrays.asList(beanCtClass.getDeclaredMethods());
- // if (declaredMethods.contains(ctMethod))
- // {
- // return false;
- // }
- // CtClass objectCtClass = ClassPool.getDefault().get(Object.class.getName());
- // CtMethod[] methodsInObjectClass = objectCtClass.getMethods();
- // List<CtMethod> methodsToBeSkipped = Arrays.asList(methodsInObjectClass);
- // return methodsToBeSkipped.contains(ctMethod);
- return false;
-
- }
-
- private static boolean shouldMethodBeSkipped(ClassPool pool, CtMethod ctMethod) throws Exception
- {
- CtClass paramsToEqualsMethodInObjectClass[] = new CtClass[]
- {pool.get(Object.class.getName())};
- if (!ctMethod.getName().equals("equals"))
- {
- return false;
- }
- if (ctMethod.getParameterTypes().length != paramsToEqualsMethodInObjectClass.length)
- {
- return false;
- }
- CtClass paramsToEqualsMethodInOtherClass[] = ctMethod.getParameterTypes();
- return paramsToEqualsMethodInObjectClass[0].equals(paramsToEqualsMethodInOtherClass[0]);
-
- }
-
- private static CtMethod createEqualsMethod(ClassPool pool, CtClass proxyCtClass) throws Exception
- {
- String body = "{" + "java.lang.reflect.Method currentMethod = " + Object.class.getName()
- + ".class.getMethod(\"equals\",$sig);" + "return ($r) invocationHandler.invoke(this,currentMethod,$args);"
- + "}";
-
- Method equals = Object.class.getMethod("equals", new Class<?>[]
- {Object.class});
- CtClass returnType = pool.get(equals.getReturnType().getName());
- CtClass paramTypes[] = new CtClass[equals.getParameterTypes().length];
- int i = 0;
- for (Class<?> paramType : equals.getParameterTypes())
- {
- paramTypes[i++] = pool.get(paramType.getName());
- }
-
- CtClass exceptionTypes[] = new CtClass[equals.getExceptionTypes().length];
- int j = 0;
- for (Class<?> exceptionType : equals.getExceptionTypes())
- {
- exceptionTypes[j++] = pool.get(exceptionType.getName());
- }
-
- return CtNewMethod.make(returnType, equals.getName(), paramTypes, exceptionTypes, body, proxyCtClass);
- }
-
- /**
- * Get the next unique number which will be used for the proxy class name
- *
- * @return
- */
- private long getNextUniqueNumber()
- {
- synchronized (nextUniqueNumberLock)
- {
- this.nextUniqueNumberForNoViewInterfaceClassName++;
- return this.nextUniqueNumberForNoViewInterfaceClassName;
- }
- }
-
-}
Deleted: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceViewFactory.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceViewFactory.java 2009-12-01 11:52:28 UTC (rev 97220)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceViewFactory.java 2009-12-01 12:09:13 UTC (rev 97221)
@@ -1,51 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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;
-
-import java.lang.reflect.InvocationHandler;
-
-/**
- * NoInterfaceViewFactory
- *
- * Factory for creating no-interface view for a bean
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
-public interface NoInterfaceViewFactory
-{
-
- /**
- * Creates a no-interface view for the EJB represented by the
- * <code>beanClass</code>
- *
- * @param <T>
- * @param invocationHandler The invocation handler responsible for handling
- * requests on the no-interface view returned by this
- * method
- * @param beanClass The bean class (no validation on the Class is done to check for EJB semantics)
- * @return Returns the no-interface view for the <code>beanClass</code>
- *
- * @throws Exception If any exceptions are encountered during the no-interface view creation
- */
- public <T> T createView(InvocationHandler invocationHandler, Class<T> beanClass) throws Exception;
-}
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/MCAwareStatefulNoInterfaceViewFactory.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/MCAwareStatefulNoInterfaceViewFactory.java 2009-12-01 11:52:28 UTC (rev 97220)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/MCAwareStatefulNoInterfaceViewFactory.java 2009-12-01 12:09:13 UTC (rev 97221)
@@ -26,7 +26,6 @@
import org.jboss.dependency.spi.ControllerState;
import org.jboss.ejb3.endpoint.Endpoint;
-import org.jboss.ejb3.nointerface.NoInterfaceEJBViewFactoryBase;
import org.jboss.ejb3.nointerface.invocationhandler.MCAwareNoInterfaceViewInvocationHandler;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.logging.Logger;
Added: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/NoInterfaceEJBViewFactoryBase.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/NoInterfaceEJBViewFactoryBase.java (rev 0)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/NoInterfaceEJBViewFactoryBase.java 2009-12-01 12:09:13 UTC (rev 97221)
@@ -0,0 +1,284 @@
+/*
+ * 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.factory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtField;
+import javassist.CtMethod;
+import javassist.CtNewMethod;
+import javassist.LoaderClassPath;
+import javassist.Modifier;
+
+import org.jboss.logging.Logger;
+
+/**
+ * NoInterfaceEJBViewFactoryBase
+ *
+ * Creates a no-interface view for a EJB as per the EJB3.1 spec (section 3.4.4)
+ *
+ * @see NoInterfaceViewFactory
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class NoInterfaceEJBViewFactoryBase implements NoInterfaceViewFactory
+{
+
+ /**
+ * The proxies (sub-classes) created for the bean class need to be
+ * unique. This unique number is appended to the generated class name
+ */
+ private static long nextUniqueNumberForNoViewInterfaceClassName = 0;
+
+ /**
+ * Used while generating unique number for the proxy class
+ */
+ private static Object nextUniqueNumberLock = new Object();
+
+ /**
+ * Logger
+ */
+ private static Logger logger = Logger.getLogger(NoInterfaceEJBViewFactoryBase.class);
+
+ /**
+ * Inspects the bean class for all public methods and creates a proxy (sub-class)
+ * out of it with overriden implementation of the public methods. The overriden
+ * implementation will just give a call to <code>container</code>'s invoke(...) method
+ * which handles the actual call.
+ *
+ * @param <T>
+ * @param invocationHandler The container correpsonding to the bean class
+ * @param beanClass The bean class (currently assumed)
+ * @return Returns the no-interface view for the <code>beanClass</code>
+ * @throws Exception
+ */
+ public <T> T createView(InvocationHandler invocationHandler, Class<T> beanClass) throws Exception
+ {
+ if (logger.isTraceEnabled())
+ {
+ logger.trace("Creating nointerface view for beanClass: " + beanClass + " with container " + invocationHandler);
+ }
+
+ // Create a ClassPool and add the classpath using the classloader of the beanClass, so
+ // that it uses the correct jar while looking up the class
+ ClassPool pool = new ClassPool();
+ pool.appendClassPath(new LoaderClassPath(beanClass.getClassLoader()));
+
+ CtClass beanCtClass = pool.get(beanClass.getName());
+
+ // Create a sub-class (proxy) for the bean class. A unique name will be used for the subclass
+ CtClass proxyCtClass = pool.makeClass(beanClass.getName() + "_NoInterfaceProxy$" + getNextUniqueNumber(),
+ beanCtClass);
+
+ // We need to maintain a reference of the invocationHandler in the proxy, so that we can
+ // forward the method calls to invocationHandler.invoke. Create a new field in the sub-class (proxy)
+ CtField invocationHandlerField = CtField.make("private java.lang.reflect.InvocationHandler invocationHandler;",
+ proxyCtClass);
+ proxyCtClass.addField(invocationHandlerField);
+
+ // get all public methods from the bean class
+ Set<CtMethod> beanPublicMethods = getAllPublicNonStaticNonFinalMethods(beanCtClass);
+
+ // Override each of the public methods
+ for (CtMethod beanPublicMethod : beanPublicMethods)
+ {
+ // Methods from java.lang.Object can be skipped, if they are
+ // not implemented (overriden) in the bean class. TODO: Do we really need to do this?
+ if (shouldMethodBeSkipped(pool, beanPublicMethod))
+ {
+ logger.debug("Skipping " + beanPublicMethod.getName() + " on bean " + beanCtClass.getName()
+ + " from no-interface view");
+ continue;
+ }
+ // We should not be changing the bean class methods. So we need to create a copy of the methods
+ // for the sub-class (proxy)
+ CtMethod proxyPublicMethod = CtNewMethod.copy(beanPublicMethod, proxyCtClass, null);
+ // All the public methods of the bean should now be overriden (through the proxy)
+ // to give a call to the container.invoke
+ // Ex: If the bean's public method was:
+ // public String sayHi(String name) { return "Hi " + name; }
+ // then it will be changed in the proxy to
+ // public String sayHi(String name) { java.lang.reflect.Method currentMethod = beanClass.getName() + ".class.getMethod(theMethodName,params);
+ // return container.invoke(this,currentMethod,args); }
+ proxyPublicMethod = overridePublicMethod(invocationHandler, beanClass, beanPublicMethod, proxyPublicMethod);
+ // We have now created the overriden method. We need to add it to the proxy
+ proxyCtClass.addMethod(proxyPublicMethod);
+ if (logger.isTraceEnabled())
+ {
+ logger.trace("Added overriden implementation for method " + proxyPublicMethod.getName()
+ + " in no-interface view " + proxyCtClass.getName() + " for bean " + beanClass.getName());
+ }
+ }
+ // Add java.io.Serializable as the interface for the proxy (since it goes into JNDI)
+ //proxyCtClass.addInterface(pool.get(Serializable.class.getName()));
+ proxyCtClass.addMethod(createEqualsMethod(pool, proxyCtClass));
+
+ // We are almost done (except for setting the container field in the proxy)
+ // Let's first create a java.lang.Class (i.e. load) out of the javassist class
+ // using the classloader of the bean
+ Class<?> proxyClass = proxyCtClass.toClass(beanClass.getClassLoader(), beanClass.getProtectionDomain());
+ // time to set the container field through normal java reflection
+ Object proxyInstance = proxyClass.newInstance();
+ Field containerInProxy = proxyClass.getDeclaredField("invocationHandler");
+ containerInProxy.setAccessible(true);
+ containerInProxy.set(proxyInstance, invocationHandler);
+
+ // return the proxy instance
+ return beanClass.cast(proxyInstance);
+
+ }
+
+ private <T> CtMethod overridePublicMethod(InvocationHandler container, Class<T> beanClass,
+ CtMethod publicMethodOnBean, CtMethod publicMethodOnProxy) throws Exception
+ {
+ publicMethodOnProxy.setBody("{"
+ +
+ // The proxy needs to call the container.invoke
+ // the InvocationHandler.invoke accepts (Object proxy,Method method,Object[] args)
+ // This view needs to create a java.lang.reflect.Method object based on the "current method"
+ // that is invoked on the view. Note that we need to get the Method from the beanclass.
+ // Note: All the '$' parameters used are javassist specific syntax
+ "java.lang.reflect.Method currentMethod = " + beanClass.getName() + ".class.getMethod(\""
+ + publicMethodOnBean.getName() + "\",$sig);" +
+ // At this point we have the container, the Method to be invoked and the parameters to be passed
+ // All we have to do is invoke the container
+ "return ($r) invocationHandler.invoke(this,currentMethod,$args);" + "}");
+
+ return publicMethodOnProxy;
+ }
+
+ /**
+ * Returns all public, non-static and non-final methods for the class
+ *
+ * @param ctClass The class whose non-final, non-static public methods are to be returned
+ * @return
+ * @throws Exception
+ */
+ private Set<CtMethod> getAllPublicNonStaticNonFinalMethods(CtClass ctClass) throws Exception
+ {
+ CtMethod[] allMethods = ctClass.getMethods();
+ Set<CtMethod> publicMethods = new HashSet<CtMethod>();
+
+ for (CtMethod ctMethod : allMethods)
+ {
+ int modifier = ctMethod.getModifiers();
+ // Public non-static non-final methods
+ if (((Modifier.PUBLIC & modifier) == Modifier.PUBLIC) && ((Modifier.STATIC & modifier) != Modifier.STATIC)
+ && ((Modifier.FINAL & modifier) != Modifier.FINAL) && ((Modifier.NATIVE & modifier) != Modifier.NATIVE))
+ {
+ publicMethods.add(ctMethod);
+ }
+ }
+ return publicMethods;
+ }
+
+ /**
+ * Checks whether a method has to be skipped from being overriden in the proxy
+ * that is returned for the no-interface view.
+ *
+ * TODO: Do we really need this. Need to think more. Let's keep it for the time-being
+ *
+ * @param beanCtClass
+ * @param ctMethod
+ * @return
+ * @throws Exception
+ */
+ private boolean shouldMethodBeSkipped(CtClass beanCtClass, CtMethod ctMethod) throws Exception
+ {
+
+ // List<CtMethod> declaredMethods = Arrays.asList(beanCtClass.getDeclaredMethods());
+ // if (declaredMethods.contains(ctMethod))
+ // {
+ // return false;
+ // }
+ // CtClass objectCtClass = ClassPool.getDefault().get(Object.class.getName());
+ // CtMethod[] methodsInObjectClass = objectCtClass.getMethods();
+ // List<CtMethod> methodsToBeSkipped = Arrays.asList(methodsInObjectClass);
+ // return methodsToBeSkipped.contains(ctMethod);
+ return false;
+
+ }
+
+ private static boolean shouldMethodBeSkipped(ClassPool pool, CtMethod ctMethod) throws Exception
+ {
+ CtClass paramsToEqualsMethodInObjectClass[] = new CtClass[]
+ {pool.get(Object.class.getName())};
+ if (!ctMethod.getName().equals("equals"))
+ {
+ return false;
+ }
+ if (ctMethod.getParameterTypes().length != paramsToEqualsMethodInObjectClass.length)
+ {
+ return false;
+ }
+ CtClass paramsToEqualsMethodInOtherClass[] = ctMethod.getParameterTypes();
+ return paramsToEqualsMethodInObjectClass[0].equals(paramsToEqualsMethodInOtherClass[0]);
+
+ }
+
+ private static CtMethod createEqualsMethod(ClassPool pool, CtClass proxyCtClass) throws Exception
+ {
+ String body = "{" + "java.lang.reflect.Method currentMethod = " + Object.class.getName()
+ + ".class.getMethod(\"equals\",$sig);" + "return ($r) invocationHandler.invoke(this,currentMethod,$args);"
+ + "}";
+
+ Method equals = Object.class.getMethod("equals", new Class<?>[]
+ {Object.class});
+ CtClass returnType = pool.get(equals.getReturnType().getName());
+ CtClass paramTypes[] = new CtClass[equals.getParameterTypes().length];
+ int i = 0;
+ for (Class<?> paramType : equals.getParameterTypes())
+ {
+ paramTypes[i++] = pool.get(paramType.getName());
+ }
+
+ CtClass exceptionTypes[] = new CtClass[equals.getExceptionTypes().length];
+ int j = 0;
+ for (Class<?> exceptionType : equals.getExceptionTypes())
+ {
+ exceptionTypes[j++] = pool.get(exceptionType.getName());
+ }
+
+ return CtNewMethod.make(returnType, equals.getName(), paramTypes, exceptionTypes, body, proxyCtClass);
+ }
+
+ /**
+ * Get the next unique number which will be used for the proxy class name
+ *
+ * @return
+ */
+ private long getNextUniqueNumber()
+ {
+ synchronized (nextUniqueNumberLock)
+ {
+ this.nextUniqueNumberForNoViewInterfaceClassName++;
+ return this.nextUniqueNumberForNoViewInterfaceClassName;
+ }
+ }
+
+}
Property changes on: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/NoInterfaceEJBViewFactoryBase.java
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/NoInterfaceViewFactory.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/NoInterfaceViewFactory.java (rev 0)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/NoInterfaceViewFactory.java 2009-12-01 12:09:13 UTC (rev 97221)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.factory;
+
+import java.lang.reflect.InvocationHandler;
+
+/**
+ * NoInterfaceViewFactory
+ *
+ * Factory for creating no-interface view for a bean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface NoInterfaceViewFactory
+{
+
+ /**
+ * Creates a no-interface view for the EJB represented by the
+ * <code>beanClass</code>
+ *
+ * @param <T>
+ * @param invocationHandler The invocation handler responsible for handling
+ * requests on the no-interface view returned by this
+ * method
+ * @param beanClass The bean class (no validation on the Class is done to check for EJB semantics)
+ * @return Returns the no-interface view for the <code>beanClass</code>
+ *
+ * @throws Exception If any exceptions are encountered during the no-interface view creation
+ */
+ public <T> T createView(InvocationHandler invocationHandler, Class<T> beanClass) throws Exception;
+}
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-12-01 11:52:28 UTC (rev 97220)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java 2009-12-01 12:09:13 UTC (rev 97221)
@@ -26,8 +26,8 @@
import javax.naming.Context;
import javax.naming.NamingException;
-import org.jboss.ejb3.nointerface.NoInterfaceEJBViewFactoryBase;
-import org.jboss.ejb3.nointerface.NoInterfaceViewFactory;
+import org.jboss.ejb3.nointerface.factory.NoInterfaceEJBViewFactoryBase;
+import org.jboss.ejb3.nointerface.factory.NoInterfaceViewFactory;
import org.jboss.ejb3.nointerface.invocationhandler.MCAwareNoInterfaceViewInvocationHandler;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/factory/unit/NoInterfaceViewFactoryTestCase.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/factory/unit/NoInterfaceViewFactoryTestCase.java (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/factory/unit/NoInterfaceViewFactoryTestCase.java 2009-12-01 12:09:13 UTC (rev 97221)
@@ -0,0 +1,256 @@
+/*
+ * 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.factory.unit;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.jboss.ejb3.nointerface.factory.NoInterfaceEJBViewFactoryBase;
+import org.jboss.ejb3.nointerface.factory.NoInterfaceViewFactory;
+import org.jboss.ejb3.nointerface.test.viewcreator.SimpleSFSBeanWithoutInterfaces;
+import org.jboss.ejb3.nointerface.test.viewcreator.SimpleSLSBWithoutInterface;
+import org.jboss.logging.Logger;
+import org.junit.Test;
+
+/**
+ * NoInterfaceBeansTestCase
+ *
+ * Tests the no-inteface view for beans.
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class NoInterfaceViewFactoryTestCase
+{
+
+ /**
+ * Logger
+ */
+ private static Logger logger = Logger.getLogger(NoInterfaceViewFactoryTestCase.class);
+
+ private class DummyInvocationHandler implements InvocationHandler
+ {
+
+ private Object target;
+
+ public DummyInvocationHandler(Object target)
+ {
+ if (target == null)
+ {
+ throw new IllegalArgumentException("Target object cannot be null, for invocation handler");
+ }
+ this.target = target;
+ }
+
+ /**
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ // just pass on the call to the target
+ return method.invoke(target, args);
+ }
+
+ }
+
+ /**
+ * 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
+ {
+ NoInterfaceViewFactory noInterfaceBeanFactory = new NoInterfaceEJBViewFactoryBase();
+ SimpleSLSBWithoutInterface beanInstance = new SimpleSLSBWithoutInterface();
+ Object proxy = noInterfaceBeanFactory.createView(new DummyInvocationHandler(beanInstance), beanInstance.getClass());
+ // ensure that the returned object is not null and is of expected type
+ assertNotNull("No-interface view factory returned a null view for " + beanInstance.getClass(), proxy);
+ assertTrue("No-interface view factory returend an unexpected object type: " + proxy.getClass(), (proxy instanceof SimpleSLSBWithoutInterface));
+
+ SimpleSLSBWithoutInterface noInterfaceView = (SimpleSLSBWithoutInterface) proxy;
+
+ // 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 = noInterfaceView.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
+ {
+ NoInterfaceViewFactory noInterfaceBeanFactory = new NoInterfaceEJBViewFactoryBase();
+ SimpleSFSBeanWithoutInterfaces beanInstance = new SimpleSFSBeanWithoutInterfaces();
+ Object proxy = noInterfaceBeanFactory.createView(new DummyInvocationHandler(beanInstance), beanInstance.getClass());
+ // ensure that the returned object is not null and is of expected type
+ assertNotNull("No-interface view factory returned a null view for " + beanInstance.getClass(), proxy);
+ assertTrue("No-interface view factory returend an unexpected object type: " + proxy.getClass(), (proxy instanceof SimpleSFSBeanWithoutInterfaces));
+
+ SimpleSFSBeanWithoutInterfaces noInterfaceView = (SimpleSFSBeanWithoutInterfaces) proxy;
+
+
+ // Nothing fancy to test - just ensure that the declared methods in the proxy does
+ // NOT contain a "static" method. Just check on method name, should be enough
+ Method[] declaredMethods = noInterfaceView.getClass().getDeclaredMethods();
+ for (Method declaredMethod : declaredMethods)
+ {
+ if (declaredMethod.getName().equals("someStaticMethod"))
+ {
+ fail("No-interface view has overriden a static method. It shouldn't have.");
+ }
+ }
+ }
+
+// /**
+// * Test to ensure that a no-interface view is NOT created for session beans
+// * which implement an interface (and do not explicitly mark themselves @LocalBean)
+// *
+// * @throws Exception
+// */
+// @Test
+// public void testBeanWithInterfacesIsNotEligibleForNoInterfaceView() throws Exception
+// {
+// JBossSessionBeanMetaData slsbMetadata = MetaDataHelper
+// .getMetadataFromBeanImplClass(StatelessBeanWithInterfaces.class);
+// String slsbNoInterfaceViewJNDIName = slsbMetadata.getEjbName() + "/no-interface";
+//
+// JBossSessionBeanMetaData sfsbMetadata = MetaDataHelper
+// .getMetadataFromBeanImplClass(StatefulBeanWithInterfaces.class);
+// String sfsbNoInterfaceViewJNDIName = sfsbMetadata.getEjbName() + "/no-interface";
+// String sfsbNoInterfaceViewFactoryJNDIName = sfsbMetadata.getEjbName() + "/no-interface-stateful-proxyfactory";
+//
+// Context ctx = new InitialContext();
+// // we have to ensure that there is NO no-interface view for these beans (because they are not eligible)
+// try
+// {
+// Object obj = ctx.lookup(slsbNoInterfaceViewJNDIName);
+// // this is a failure because there should not be a no-interface view for these beans
+// fail("A SLSB with interfaces was marked as eligible for no-interface view. Shouldn't have been. Found object of type "
+// + obj.getClass() + " in the jndi for jndiname " + slsbNoInterfaceViewJNDIName);
+// }
+// catch (NameNotFoundException nnfe)
+// {
+// // expected
+// }
+//
+// // now for sfsb, test that neither the factory nor the view are NOT bound
+//
+// // test factory binding
+// try
+// {
+// Object obj = ctx.lookup(sfsbNoInterfaceViewFactoryJNDIName);
+// // this is a failure because there should not be a no-interface view for these beans
+// fail("A SFSB factory for no-interface view was created for a bean implementing interfaces. Shouldn't have been. Found object of type "
+// + obj.getClass() + " in the jndi for jndiname " + sfsbNoInterfaceViewFactoryJNDIName);
+// }
+// catch (NameNotFoundException nnfe)
+// {
+// // expected
+// }
+// // sfsb no-interface view
+// try
+// {
+// Object obj = ctx.lookup(sfsbNoInterfaceViewJNDIName);
+// // this is a failure because there should not be a no-interface view for these beans
+// fail("A no-interface view for SFSB was created for a bean implementing interfaces. Shouldn't have been. Found object of type "
+// + obj.getClass() + " in the jndi for jndiname " + sfsbNoInterfaceViewJNDIName);
+// }
+// catch (NameNotFoundException nnfe)
+// {
+// // expected
+// }
+//
+// }
+//
+// /**
+// * Test that sessions are created as expected for stateful session beans
+// *
+// * @throws Exception
+// */
+// @Test
+// public void testSessionCreationForSFSBNoInterfaceViews() throws Exception
+// {
+// JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper
+// .getMetadataFromBeanImplClass(SimpleSFSBeanWithoutInterfaces.class);
+// String jndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
+//
+// Context ctx = new InitialContext();
+// // let's assume the lookup returns the correct type.
+// // there are other test cases to ensure it does return the correct type
+// SimpleSFSBeanWithoutInterfaces firstSFSB = (SimpleSFSBeanWithoutInterfaces) ctx.lookup(jndiName);
+// // ensure this is a clean bean
+// int initQty = firstSFSB.getQtyPurchased();
+// assertEquals("SFSB instance is not new", initQty, SimpleSFSBeanWithoutInterfaces.INITIAL_QTY);
+// // now change the state of the sfsb instance
+// firstSFSB.incrementPurchaseQty();
+// int incrementedValueForFirstSFSB = firstSFSB.getQtyPurchased();
+// assertEquals("SFSB instance's value not incremented", incrementedValueForFirstSFSB,
+// SimpleSFSBeanWithoutInterfaces.INITIAL_QTY + 1);
+//
+// // now lookup another bean
+// SimpleSFSBeanWithoutInterfaces secondSFSB = (SimpleSFSBeanWithoutInterfaces) ctx.lookup(jndiName);
+// // ensure this is a clean bean
+// int initQtyForSecondBeanInstance = secondSFSB.getQtyPurchased();
+// assertEquals("Second instance of SFSB is not new", initQtyForSecondBeanInstance,
+// SimpleSFSBeanWithoutInterfaces.INITIAL_QTY);
+// // now change the state of the sfsb instance by some x amount
+// int incrementBy = 10;
+// secondSFSB.incrementPurchaseQty(incrementBy);
+// int incrementedValueForSecondSFSB = secondSFSB.getQtyPurchased();
+// assertEquals("Second SFSB instance's value not incremented", incrementedValueForSecondSFSB,
+// SimpleSFSBeanWithoutInterfaces.INITIAL_QTY + incrementBy);
+//
+// // let's also (again) check that the first SFSB still has it's own values and hasn't been
+// // affected by changes made to second SFSB
+// assertEquals("Value in first SFSB was changed when second SFSB was being modified", incrementedValueForFirstSFSB,
+// SimpleSFSBeanWithoutInterfaces.INITIAL_QTY + 1);
+//
+// // also check equality of two sfsb instances - they should not be equal
+// assertFalse("Both the instances of the SFSB are the same", firstSFSB.equals(secondSFSB));
+//
+// // let's also check whether the bean is equal to itself
+// assertTrue("Incorrect equals implementation - returns false for the same sfsb instance", firstSFSB
+// .equals(firstSFSB));
+// assertTrue("equals returned false for the same sfsb instance", secondSFSB.equals(secondSFSB));
+//
+// }
+
+}
Property changes on: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/factory/unit/NoInterfaceViewFactoryTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Deleted: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MethodInvocationTrackingContainer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MethodInvocationTrackingContainer.java 2009-12-01 11:52:28 UTC (rev 97220)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MethodInvocationTrackingContainer.java 2009-12-01 12:09:13 UTC (rev 97221)
@@ -1,106 +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.viewcreator;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.jboss.ejb3.nointerface.test.viewcreator.unit.NoInterfaceEJBViewCreatorTestCase;
-import org.jboss.logging.Logger;
-
-/**
- * MethodInvocationTrackingContainer
- *
- * Mock container which just tracks/maintains the methods which were
- * invoked on the bean through this container. This MethodInvocationTrackingContainer will be
- * used by the {@link NoInterfaceEJBViewCreatorTestCase} to create a no-interface view out of a
- * bean and associate this container with the bean. Any invocations on the public methods of the
- * no-interface view of the bean in, the {@link NoInterfaceEJBViewCreatorTestCase} test case,
- * will be routed through this MethodInvocationTrackingContainer
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
-public class MethodInvocationTrackingContainer implements InvocationHandler
-{
-
- /**
- * Logger
- */
- private Logger logger = Logger.getLogger(MethodInvocationTrackingContainer.class);
-
- /**
- * The bean class to which this container corresponds to
- */
- private Class<?> beanClass;
-
-
- private List<String> invokedMethods;
-
- /**
- * Constructor
- * @param targetBean The bean class to which this container corresponds to
- */
- public MethodInvocationTrackingContainer(Class<?> targetBean)
- {
- this.beanClass = targetBean;
- invokedMethods = new ArrayList<String>();
- }
-
- /**
- * Maintains the method name invoked, in its internal list and then forwards
- * the method invocation to the instance of the bean class
- *
- *
- * @see InvocationHandler#invoke(Object, Method, Object[])
- */
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- logger.debug("Tracking method " + method.getName() + " for bean " + beanClass.getName());
- // add to internal map for tracking
- this.invokedMethods.add(method.getName());
-
- Object target = beanClass.newInstance();
- return method.invoke(target, args);
- }
-
- /**
- * Clears the methods that were tracked
- */
- public void resetTracking()
- {
- this.invokedMethods.clear();
- }
-
- /**
- * Return the tracked method names
- * @return
- */
- public List<String> getTrackedMethodNames()
- {
- return Collections.unmodifiableList(this.invokedMethods);
- }
-
-}
Deleted: projects/ejb3/trunk/nointerface/src/test/resources/jndi.properties
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/resources/jndi.properties 2009-12-01 11:52:28 UTC (rev 97220)
+++ projects/ejb3/trunk/nointerface/src/test/resources/jndi.properties 2009-12-01 12:09:13 UTC (rev 97221)
@@ -1,2 +0,0 @@
-java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
-java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Modified: projects/ejb3/trunk/nointerface/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/resources/log4j.xml 2009-12-01 11:52:28 UTC (rev 97220)
+++ projects/ejb3/trunk/nointerface/src/test/resources/log4j.xml 2009-12-01 12:09:13 UTC (rev 97221)
@@ -62,6 +62,10 @@
<!-- ================ -->
<category name="org.jboss">
+ <priority value="INFO"/>
+ </category>
+
+ <category name="org.jboss.embedded">
<priority value="DEBUG"/>
</category>
More information about the jboss-cvs-commits
mailing list