[jboss-cvs] JBossAS SVN: r86038 - 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
Wed Mar 18 05:50:12 EDT 2009


Author: jaikiran
Date: 2009-03-18 05:50:12 -0400 (Wed, 18 Mar 2009)
New Revision: 86038

Added:
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MyStateful.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MyStateless.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSFSBeanWithoutInterfaces.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatefulBeanWithInterfaces.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatelessBeanWithInterfaces.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatelessLocalBeanWithInterfaces.java
Removed:
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSFSBean.java
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/StatefulNoInterfaceJNDIBinder.java
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.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/common/MockStatefulContainer.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/ChildBean.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSLSBWithoutInterface.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java
Log:
EJBTHREE-1727 (1) Added dependency on Java6 (for @LocalBean) (2) Refactored the code to incorporate review comments including injection of StatefulSessionFactory (3) More unit tests added

Modified: projects/ejb3/trunk/nointerface/pom.xml
===================================================================
--- projects/ejb3/trunk/nointerface/pom.xml	2009-03-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/pom.xml	2009-03-18 09:50:12 UTC (rev 86038)
@@ -60,19 +60,65 @@
    </testResources>
 
    <plugins>
-      <plugin>
-        <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>
-        </configuration>
-      </plugin>
+        <!-- We have a dependency on @LocalBean which comes from ejb3-api (=JDK6) -->
+        <plugin>
+            <artifactId>maven-enforcer-plugin</artifactId>
+            <executions>
+              <execution>
+                <id>enforce-jdk6</id>
+                <goals>
+                  <goal>enforce</goal>
+                </goals>
+                <configuration>
+                  <rules>
+                    <requireProperty>
+                      <property>env.JDK6_HOME</property>
+                      <message>JDK6_HOME is not set</message>
+                    </requireProperty>
+                  </rules>
+                </configuration>
+              </execution>
+            </executions>
+        </plugin>
+   
+        <plugin>
+            <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>
+              
+            </configuration>
+        </plugin>
+      
+      
+        <plugin>
+            <artifactId>maven-compiler-plugin</artifactId>
+            <configuration>
+              <source>1.6</source>
+              <target>1.6</target>
+              <executable>${JDK6_HOME}/bin/javac</executable>
+            </configuration>
+        </plugin>
+        
+        <!-- Code coverage tool -->
+        <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>cobertura-maven-plugin</artifactId>
+            <!-- version 2.0 is intentional since other (later) version
+            seems to generate reports showing 0% coverage for all -->
+            <version>2.0</version>
+        </plugin>
+        
     </plugins>
 
   </build>
+  
 
  <!-- Dependencies -->
   <dependencies>

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-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewCreator.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -24,9 +24,8 @@
 import java.io.Serializable;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationHandler;
-import java.util.Arrays;
+import java.lang.reflect.Method;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
 
 import javassist.ClassPool;
@@ -37,7 +36,6 @@
 import javassist.Modifier;
 
 import org.jboss.logging.Logger;
-import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 
 /**
  * NoInterfaceEJBViewCreator
@@ -107,7 +105,8 @@
 
       // We need to maintain a reference of the container in the proxy, so that we can
       // forward the method calls to invocationHandler.invoke. Create a new field in the sub-class (proxy)
-      CtField containerField = CtField.make("private java.lang.reflect.InvocationHandler invocationHandler;", proxyCtClass);
+      CtField containerField = CtField.make("private java.lang.reflect.InvocationHandler invocationHandler;",
+            proxyCtClass);
       proxyCtClass.addField(containerField);
 
       // get all public methods from the bean class
@@ -118,7 +117,7 @@
       {
          // 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(beanCtClass, beanPublicMethod))
+         if (shouldMethodBeSkipped(pool, beanPublicMethod))
          {
             logger.debug("Skipping " + beanPublicMethod.getName() + " on bean " + beanCtClass.getName()
                   + " from no-interface view");
@@ -139,12 +138,13 @@
          proxyCtClass.addMethod(proxyPublicMethod);
          if (logger.isTraceEnabled())
          {
-            logger.trace("Added method " + proxyPublicMethod.getName() + " in no-interface view "
-                  + proxyCtClass.getName() + " for bean " + beanClass.getName());
+            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.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
@@ -219,18 +219,62 @@
    protected boolean shouldMethodBeSkipped(CtClass beanCtClass, CtMethod ctMethod) throws Exception
    {
 
-      List<CtMethod> declaredMethods = Arrays.asList(beanCtClass.getDeclaredMethods());
-      if (declaredMethods.contains(ctMethod))
+      //      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;
       }
-      CtClass objectCtClass = ClassPool.getDefault().get(Object.class.getName());
-      CtMethod[] methodsInObjectClass = objectCtClass.getMethods();
-      List<CtMethod> methodsToBeSkipped = Arrays.asList(methodsInObjectClass);
-      return methodsToBeSkipped.contains(ctMethod);
+      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
     *

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-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -23,10 +23,12 @@
 
 import java.io.Externalizable;
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
+import javax.ejb.LocalBean;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
@@ -126,12 +128,21 @@
          }
          Class<?> beanClass = Class.forName(sessionBeanMetaData.getEjbClass(), false, unit.getClassLoader());
 
-         // The container name is set in the metadata only after the creation of the container
-         // 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();
-         String containerMCBeanName = getContainerName(unit, sessionBeanMetaData);
+         String containerMCBeanName = sessionBeanMetaData.getContainerName();
+         if (logger.isTraceEnabled())
+         {
+            logger.trace("Container name for bean " + sessionBeanMetaData.getEjbName() + " in unit " + unit + " is " + containerMCBeanName);
+         }
+         if (containerMCBeanName == null)
+         {
+            // The container name is set in the metadata only after the creation of the container
+            // 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();
+            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
          NoInterfaceViewJNDIBinder bean = NoInterfaceViewJNDIBinder.getNoInterfaceViewJndiBinder(beanClass,
@@ -145,6 +156,14 @@
          // Too bad we have to know the field name. Need to do more research on MC to see if we can
          // add property metadata based on type instead of field name.
          builder.addPropertyMetaData("container", inject);
+         
+         // for SFSB we also need to inject the StatefulSessionFactory (which at the moment is 
+         // available at the same containerMCBeanName and is infact the container)
+         if (sessionBeanMetaData.isStateful())
+         {
+            // inject the container (=StatefulSessionFactory)
+            builder.addPropertyMetaData("statefulSessionFactory", inject);
+         }
 
          logger.info("Added injection on " + bean + " for container " + containerMCBeanName + " cl set to "
                + unit.getClassLoader());
@@ -187,10 +206,14 @@
       //TODO: The JBMETA does not yet support @LocalBean so let's HACK it for now
       String ejbClassName = sessionBeanMetadata.getEjbClass();
       Class<?> beanClass = Class.forName(ejbClassName, false, unit.getClassLoader());
-      //      if (beanClass.getAnnotation(LocalBean.class) != null) //sessionBeanMetadata.getLocalBean())
-      //      {
-      //         return true;
-      //      }
+      if (beanClass.getAnnotation(LocalBean.class) != null) //sessionBeanMetadata.getLocalBean())
+      {
+         if (logger.isTraceEnabled())
+         {
+            logger.trace("Bean class " + ejbClassName + " in unit " + unit + " is marked as @LocalBean");
+         }
+         return true;
+      }
 
       // If there are any local business interfaces then its not eligible
       if (sessionBeanMetadata.getBusinessLocals() != null && !sessionBeanMetadata.getBusinessLocals().isEmpty())
@@ -264,7 +287,10 @@
       // As per section 4.9.8 (bullet 1.3) of EJB3.1 spec
       // java.io.Serializable; java.io.Externalizable; any of the interfaces defined by the javax.ejb
       // are excluded from interface check
-      List<Class<?>> implementedInterfaces = Arrays.asList(interfaces);
+      
+      // Impl detail : We need an ArrayList because it supports removing of elements through iterator, while
+      // iterating. The List returned through Arrays.asList(...) does not allow this and throws UnsupportedException
+      List<Class<?>> implementedInterfaces = new ArrayList<Class<?>>(Arrays.asList(interfaces));
       Iterator<Class<?>> implementedInterfacesIterator = implementedInterfaces.iterator();
       while (implementedInterfacesIterator.hasNext())
       {

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-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/StatefulNoInterfaceViewFactory.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -22,6 +22,7 @@
 package org.jboss.ejb3.nointerface.factory;
 
 import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
 
 import org.jboss.ejb3.nointerface.NoInterfaceEJBViewCreator;
 import org.jboss.ejb3.nointerface.invocationhandler.NoInterfaceViewInvocationHandler;
@@ -59,14 +60,22 @@
    protected InvokableContext container;
 
    /**
+    * Responsible for creating sessions
+    */
+   protected StatefulSessionFactory statefulSessionFactory;
+
+   /**
     * Constructor
     * @param beanClass
     * @param container
+    * @param statefulSessionFactory
     */
-   public StatefulNoInterfaceViewFactory(Class<?> beanClass, InvokableContext container)
+   public StatefulNoInterfaceViewFactory(Class<?> beanClass, InvokableContext container,
+         StatefulSessionFactory statefulSessionFactory)
    {
       this.beanClass = beanClass;
       this.container = container;
+      this.statefulSessionFactory = statefulSessionFactory;
    }
 
    /**
@@ -80,15 +89,13 @@
    {
       logger.debug("Creating no-interface view for " + this.beanClass);
 
-      StatefulSessionFactory statefulSessionFactory = (StatefulSessionFactory) container;
-      Serializable session = statefulSessionFactory.createSession();
+      Serializable session = this.statefulSessionFactory.createSession();
       logger.debug("Created session " + session + " for " + this.beanClass);
 
-      NoInterfaceViewInvocationHandler invocationHandler = new NoInterfaceViewInvocationHandler(container);
-      invocationHandler.createSessionProxy(session);
+      InvocationHandler invocationHandler = new NoInterfaceViewInvocationHandler(container, session);
       // Now create the view for this bean class and the newly created invocation handler
       NoInterfaceEJBViewCreator noInterfaceViewCreator = new NoInterfaceEJBViewCreator();
-      Object noInterfaceView = noInterfaceViewCreator.createView(invocationHandler,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-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/NoInterfaceViewInvocationHandler.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -68,10 +68,11 @@
     * Constructor
     * @param container
     */
-   public NoInterfaceViewInvocationHandler(InvokableContext container)
+   public NoInterfaceViewInvocationHandler(InvokableContext container, Object target)
    {
       assert container != null : "Container is null for no-interface view invocation handler";
       this.container = container;
+      this.sessionProxy = new NoInterfaceViewSessionProxy(target);
    }
 
    /**
@@ -104,18 +105,6 @@
       return this.container;
    }
 
-   /**
-    * 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.sessionProxy = new NoInterfaceViewSessionProxy();
-      this.sessionProxy.setTarget(target);
-   }
 
 
    /**
@@ -136,8 +125,12 @@
        * The target of an invocation on the {@link NoInterfaceViewInvocationHandler} - used as a sessionId
        */
       private Object target;
+      
+      public NoInterfaceViewSessionProxy(Object target)
+      {
+         this.target = target;
+      }
 
-
       /**
        * @see SessionProxy#getTarget()
        */

Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java	2009-03-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -27,9 +27,12 @@
 import javax.naming.Reference;
 import javax.naming.StringRefAddr;
 
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.ejb3.nointerface.deployers.EJB3NoInterfaceDeployer;
 import org.jboss.ejb3.nointerface.factory.StatefulNoInterfaceViewFactory;
 import org.jboss.ejb3.nointerface.objectfactory.NoInterfaceViewProxyFactoryRefAddrTypes;
 import org.jboss.ejb3.nointerface.objectfactory.StatefulNoInterfaceViewObjectFactory;
+import org.jboss.ejb3.proxy.spi.container.StatefulSessionFactory;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 import org.jboss.util.naming.NonSerializableFactory;
@@ -52,6 +55,16 @@
     */
    private static Logger logger = Logger.getLogger(StatefulNoInterfaceJNDIBinder.class);
 
+   /**
+    * {@link StatefulSessionFactory} will be used to 
+    * create session(s) for a SFSB
+    * Note: The name of the correct MC bean to be injected will be 
+    * added programatically through BeanMetaData. 
+    * @see EJB3NoInterfaceDeployer#deploy(org.jboss.deployers.structure.spi.DeploymentUnit)
+    */
+   @Inject(dependentState = "Described")
+   private StatefulSessionFactory statefulSessionFactory;
+
    protected StatefulNoInterfaceJNDIBinder(Class<?> beanClass, JBossSessionBeanMetaData sessionBeanMetadata)
    {
       super(beanClass, sessionBeanMetadata);
@@ -79,7 +92,7 @@
       // This factory will be bound to JNDI and will be invoked (through an objectfactory) to create
       // the no-interface view for a SFSB
       StatefulNoInterfaceViewFactory statefulNoInterfaceViewFactory = new StatefulNoInterfaceViewFactory(
-            this.beanClass, this.container);
+            this.beanClass, this.container, this.statefulSessionFactory);
 
       // TODO - Needs to be a proper jndi name for the factory
       String statefulProxyFactoryJndiName = sessionBeanMetadata.getEjbName() + "/no-interface-stateful-proxyfactory";
@@ -111,4 +124,14 @@
 
    }
 
+   public void setStatefulSessionFactory(StatefulSessionFactory statefulSessFactory)
+   {
+      this.statefulSessionFactory = statefulSessFactory;
+   }
+
+   public StatefulSessionFactory getStatefulSessionFactory()
+   {
+      return this.statefulSessionFactory;
+   }
+
 }

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-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.nointerface.mc;
 
+import java.lang.reflect.InvocationHandler;
+
 import javax.naming.Name;
 
 import org.jboss.ejb3.nointerface.NoInterfaceEJBViewCreator;
@@ -65,8 +67,8 @@
 
       // Create the view and bind to jndi
       NoInterfaceEJBViewCreator noInterfaceViewCreator = new NoInterfaceEJBViewCreator();
-      NoInterfaceViewInvocationHandler invocationHandler = new NoInterfaceViewInvocationHandler(this.container);
-      invocationHandler.createSessionProxy(null);
+      InvocationHandler invocationHandler = new NoInterfaceViewInvocationHandler(this.container, 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

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-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/AbstractNoInterfaceTestCase.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -201,6 +201,8 @@
    {
       deploy(new File(SERVER_PROFILE_DEPLOY_DIR_PATH).toURL());
 
+      // We no longer use real containers in our unit tests. So no dependency on ejb3-core.
+      // We rely on mock containers.
 //      // 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");

Modified: 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	2009-03-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatefulContainer.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -54,7 +54,7 @@
    /**
     * Maintain the sessions
     */
-   private static Map<Serializable,Object> sessions = new HashMap<Serializable,Object>();
+   private static Map<Serializable, Object> sessions = new HashMap<Serializable, Object>();
 
    /**
     * Each session is represented by an id
@@ -103,7 +103,7 @@
    {
       synchronized (currentSessionId)
       {
-         currentSessionId ++;
+         currentSessionId++;
          try
          {
             sessions.put(currentSessionId, beanClass.newInstance());
@@ -116,7 +116,6 @@
          return currentSessionId;
       }
 
-
    }
 
    /**
@@ -129,7 +128,6 @@
          sessions.remove(target);
       }
 
-
    }
 
 }

Modified: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/ChildBean.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/ChildBean.java	2009-03-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/ChildBean.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -45,7 +45,7 @@
    }
 
 
-   public int somePublicMethod(int number)
+   public int echoNumberFromChild(int number)
    {
       return number;
    }

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MyStateful.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MyStateful.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MyStateful.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -0,0 +1,15 @@
+/**
+ * 
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+/**
+ * MyStateful
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStateful
+{
+   int getNextCounter();
+}

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MyStateless.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MyStateless.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/MyStateless.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -0,0 +1,16 @@
+/**
+ * 
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+/**
+ * MyStateless
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyStateless
+{
+   public String sayHello(String name);
+
+}

Deleted: 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-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSFSBean.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -1,54 +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 javax.ejb.Stateful;
-
-/**
- * SimpleSFSBean
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
- at Stateful
-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
-   }
-}

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSFSBeanWithoutInterfaces.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSFSBeanWithoutInterfaces.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSFSBeanWithoutInterfaces.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+
+import javax.ejb.Stateful;
+
+/**
+ * SimpleSFSBeanWithoutInterfaces
+ * 
+ * Used in testing of no-interface view. Although the name suggests
+ * this bean does not implement any interfaces, it does however implement
+ * {@link Serializable} and {@link Externalizable} which are allowed by 
+ * spec for no-interface view.
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateful
+public class SimpleSFSBeanWithoutInterfaces implements Serializable, Externalizable
+{
+
+   public static final int INITIAL_QTY = 2;
+
+   private int qtyPurchased = INITIAL_QTY;
+
+   public int getQtyPurchased()
+   {
+      return this.qtyPurchased;
+   }
+
+   public void incrementPurchaseQty()
+   {
+      this.qtyPurchased++;
+   }
+
+   public void incrementPurchaseQty(int qty)
+   {
+      this.qtyPurchased += qty;
+   }
+
+   public static void someStaticMethod()
+   {
+      // do nothing
+   }
+
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      // do nothing
+
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      // do nothing
+
+   }
+}

Modified: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSLSBWithoutInterface.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSLSBWithoutInterface.java	2009-03-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/SimpleSLSBWithoutInterface.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -32,7 +32,6 @@
  * @version $Revision: $
  */
 @Stateless
-//@LocalBean
 public class SimpleSLSBWithoutInterface
 {
 
@@ -64,11 +63,11 @@
       return "Hi " + name;
    }
 
-//   @Override
-//   public String toString()
-//   {
-//      return "Test - " + this.getClass().getName();
-//   }
+   //   @Override
+   //   public String toString()
+   //   {
+   //      return "Test - " + this.getClass().getName();
+   //   }
 
    public final String someFinalMethod()
    {

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatefulBeanWithInterfaces.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatefulBeanWithInterfaces.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatefulBeanWithInterfaces.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -0,0 +1,43 @@
+/**
+ * 
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+
+import javax.ejb.Stateful;
+
+/**
+ * StatefulBeanWithInterfaces
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateful
+public class StatefulBeanWithInterfaces implements MyStateful, Serializable, Externalizable
+{
+
+   private int counter = 1;
+
+   public int getNextCounter()
+   {
+      return ++counter;
+   }
+
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      // do nothing
+      
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      // do nothing
+      
+   }
+
+}

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatelessBeanWithInterfaces.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatelessBeanWithInterfaces.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatelessBeanWithInterfaces.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -0,0 +1,23 @@
+/**
+ * 
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+import javax.ejb.Stateless;
+
+/**
+ * StatelessBeanWithInterfaces
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+public class StatelessBeanWithInterfaces implements MyStateless
+{
+
+   public String sayHello(String name)
+   {
+      return "Hello " + name;
+   }
+
+}

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatelessLocalBeanWithInterfaces.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatelessLocalBeanWithInterfaces.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatelessLocalBeanWithInterfaces.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -0,0 +1,25 @@
+/**
+ * 
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+import javax.ejb.LocalBean;
+import javax.ejb.Stateless;
+
+/**
+ * StatelessLocalBeanWithInterfaces
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at LocalBean
+public class StatelessLocalBeanWithInterfaces implements MyStateless
+{
+
+   public String sayHello(String name)
+   {
+      return "Hello " + name;
+   }
+
+}

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-18 07:52:31 UTC (rev 86037)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java	2009-03-18 09:50:12 UTC (rev 86038)
@@ -21,6 +21,7 @@
  */
 package org.jboss.ejb3.nointerface.test.viewcreator.unit;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -29,11 +30,16 @@
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
 
+import org.jboss.ejb3.nointerface.factory.StatefulNoInterfaceViewFactory;
 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.SimpleSFSBeanWithoutInterfaces;
 import org.jboss.ejb3.nointerface.test.viewcreator.SimpleSLSBWithoutInterface;
+import org.jboss.ejb3.nointerface.test.viewcreator.StatefulBeanWithInterfaces;
+import org.jboss.ejb3.nointerface.test.viewcreator.StatelessBeanWithInterfaces;
+import org.jboss.ejb3.nointerface.test.viewcreator.StatelessLocalBeanWithInterfaces;
 import org.jboss.ejb3.test.common.MetaDataHelper;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
@@ -96,16 +102,9 @@
 
       // Right now, the no-interface view is bound to the ejb-name/no-interface
       String noInterfaceJndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
-      logger.debug("Looking up " + noInterfaceJndiName);
-      Context ctx = new InitialContext();
 
-      // check the view
-      Object noInterfaceView = ctx.lookup(noInterfaceJndiName);
-      assertNotNull("No-interface view for SLSB returned null from JNDI", noInterfaceView);
+      assertBoundAndOfExpectedType(new InitialContext(), noInterfaceJndiName, SimpleSLSBWithoutInterface.class);
 
-      assertTrue("No-interface view for SLSB is not an instance of  " + SimpleSLSBWithoutInterface.class.getName(),
-            (noInterfaceView instanceof SimpleSLSBWithoutInterface));
-
    }
 
    /**
@@ -116,24 +115,19 @@
    @Test
    public void testSFSBNoInterfaceBindings() throws Exception
    {
-      JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper.getMetadataFromBeanImplClass(SimpleSFSBean.class);
+      JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(SimpleSFSBeanWithoutInterfaces.class);
+      Context ctx = new InitialContext();
 
       // Right now, the no-interface view is bound to the ejb-name/no-interface
       String noInterfaceJndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
       String statefulProxyFactoryJndiName = sessionBeanMetadata.getEjbName() + "/no-interface-stateful-proxyfactory";
-      logger.debug("Looking up no-interface view for sfsb at " + noInterfaceJndiName);
 
-      Context ctx = new InitialContext();
       // check the proxy factory
-      Object proxyFactory = ctx.lookup(statefulProxyFactoryJndiName);
-      assertNotNull("Stateful proxy factory for SFSB returned null from JNDI", proxyFactory);
+      assertBoundAndOfExpectedType(ctx, statefulProxyFactoryJndiName, StatefulNoInterfaceViewFactory.class);
 
       // check the view
-      Object noInterfaceView = ctx.lookup(noInterfaceJndiName);
-      assertNotNull("No-interface view for SFSB returned null from JNDI", noInterfaceView);
-
-      assertTrue("No-interface view for SFSB is not an instance of  " + SimpleSFSBean.class.getName(),
-            (noInterfaceView instanceof SimpleSFSBean));
+      assertBoundAndOfExpectedType(ctx, noInterfaceJndiName, SimpleSFSBeanWithoutInterfaces.class);
    }
 
    /**
@@ -150,21 +144,16 @@
 
       // ensure that the bean is bound
       Context ctx = new InitialContext();
-      Object bean = ctx.lookup(jndiName);
+      assertBoundAndOfExpectedType(ctx, jndiName, ChildBean.class);
 
-      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));
-
    }
 
-  /**
-   * 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 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
    {
@@ -199,13 +188,14 @@
    @Test
    public void testStaticMethodsAreNotConsideredInView() throws Exception
    {
-      JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper.getMetadataFromBeanImplClass(SimpleSFSBean.class);
+      JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(SimpleSFSBeanWithoutInterfaces.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);
+      SimpleSFSBeanWithoutInterfaces bean = (SimpleSFSBeanWithoutInterfaces) 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
@@ -218,31 +208,220 @@
          }
       }
    }
-   //
-   //   /**
-   //    * Test that multiple invocations to the {@link NoInterfaceEJBViewCreator#createView(java.lang.reflect.InvocationHandler, Class)}
-   //    * returns different instances of the view with unique view-classnames
-   //    *
-   //    * @throws Exception
-   //    */
-   //   @Test
-   //   public void testViewCreatorCreatesUniqueViewInstanceNames() throws Exception
-   //   {
-   //      MethodInvocationTrackingContainer mockContainer = new MethodInvocationTrackingContainer(
-   //            SimpleSLSBWithoutInterface.class);
-   //
-   //      SimpleSLSBWithoutInterface noInterfaceView = noInterfaceViewCreator.createView(mockContainer,
-   //            SimpleSLSBWithoutInterface.class);
-   //      logger.debug("No-interface view for first invocation is " + noInterfaceView);
-   //
-   //      SimpleSLSBWithoutInterface anotherNoInterfaceViewOnSameBean = noInterfaceViewCreator.createView(mockContainer,
-   //            SimpleSLSBWithoutInterface.class);
-   //      logger.debug("No-interface view for second invocation is " + anotherNoInterfaceViewOnSameBean);
-   //
-   //      assertNotSame("No-interface view returned same instance for two createView invocations", noInterfaceView,
-   //            anotherNoInterfaceViewOnSameBean);
-   //      assertTrue("No-interfave view class name is the same for two createView invocations", !noInterfaceView
-   //            .equals(anotherNoInterfaceViewOnSameBean));
-   //   }
-   //
+
+   /**
+    * The spec says that if the bean has been marked as local bean using 
+    * @LocalBean, then even if it implements any other interfaces, a no-interface view must
+    * be created. This test case ensures that this requirement is handled correctly
+    *  
+    * @throws Exception
+    */
+   @Test
+   public void testLocalBeanWithInterfaces() throws Exception
+   {
+      JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(StatelessLocalBeanWithInterfaces.class);
+      String jndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
+
+      Context ctx = new InitialContext();
+      assertBoundAndOfExpectedType(ctx, jndiName, StatelessLocalBeanWithInterfaces.class);
+
+   }
+
+   /**
+    * 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 invocations on no-interface view of a SLSB work as expected
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testInvocationOnSLSBNoInterfaceView() throws Exception
+   {
+      JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(SimpleSLSBWithoutInterface.class);
+      String jndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
+
+      Context ctx = new InitialContext();
+      assertBoundAndOfExpectedType(ctx, jndiName, SimpleSLSBWithoutInterface.class);
+      // at this point we are sure we will get the no-interface view
+      SimpleSLSBWithoutInterface bean = (SimpleSLSBWithoutInterface) ctx.lookup(jndiName);
+
+      // invoke a method
+      String name = "jai";
+      String returnedMessage = bean.sayHi(name);
+      assertNotNull("Invocation on no-interface view for SLSB returned a null message", returnedMessage);
+      assertEquals("Invocation on no-interface view method of SLSB returned an unexpected return message",
+            returnedMessage, "Hi " + name);
+
+      JBossSessionBeanMetaData childBeanMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(ChildBean.class);
+      String childBeanJndiName = childBeanMetadata.getEjbName() + "/no-interface";
+      assertBoundAndOfExpectedType(ctx, childBeanJndiName, ChildBean.class);
+      // at this point we are sure we will get the no-interface view
+      ChildBean childBean = (ChildBean) ctx.lookup(childBeanJndiName);
+      
+      // invoke method
+      int returnedNumber = childBean.echoNumberFromChild(10);
+      assertEquals("Method invocation on child bean returned incorrect value", returnedNumber, 10);
+      
+
+   }
+
+   /**
+    * Test that invocations on no-interface view of SFSB work as expected
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testInvocationOnSFSBNoInterfaceView() throws Exception
+   {
+      JBossSessionBeanMetaData sessionBeanMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(SimpleSFSBeanWithoutInterfaces.class);
+      String jndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
+
+      Context ctx = new InitialContext();
+      assertBoundAndOfExpectedType(ctx, jndiName, SimpleSFSBeanWithoutInterfaces.class);
+      // at this point we are sure we will get the no-interface view
+      SimpleSFSBeanWithoutInterfaces bean = (SimpleSFSBeanWithoutInterfaces) ctx.lookup(jndiName);
+
+      // invoke a method
+      int qty = bean.getQtyPurchased();
+      assertEquals("Invocation on no-interface view method of SFSB returned an unexpected return value", qty,
+            SimpleSFSBeanWithoutInterfaces.INITIAL_QTY);
+
+   }
+
+   /**
+    * 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));
+
+   }
+
+   /**
+    * Utility method for testing that the bean is bound at the <code>jndiName</code>
+    * and is of the <code>expectedType</code>
+    * 
+    * @param ctx JNDI Context 
+    * @param jndiName The jndiname to lookup
+    * @param expectedType The object returned from the jndi will be expected to be of this type
+    * 
+    * @throws Exception
+    */
+   private void assertBoundAndOfExpectedType(Context ctx, String jndiName, Class<?> expectedType) throws Exception
+   {
+      logger.debug("Looking up " + jndiName + " expectedType " + expectedType.getName());
+      Object bean = ctx.lookup(jndiName);
+
+      assertNotNull("No-interface view for " + expectedType + " returned null from JNDI name " + jndiName, bean);
+
+      assertTrue("No-interface view at jndiname " + jndiName + " for " + expectedType + " is not an instance of  " + expectedType.getName(),
+            expectedType.isAssignableFrom(bean.getClass()));
+
+   }
 }




More information about the jboss-cvs-commits mailing list