[jboss-cvs] JBossAS SVN: r86205 - in projects/ejb3/trunk/nointerface: src/main/java/org/jboss/ejb3/nointerface/factory and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 23 10:09:55 EDT 2009


Author: jaikiran
Date: 2009-03-23 10:09:55 -0400 (Mon, 23 Mar 2009)
New Revision: 86205

Added:
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatefulLocalBeanWithInterfaces.java
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/invocationhandler/MCAwareNoInterfaceViewInvocationHandler.java
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.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/common/MockStatelessContainer.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java
   projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java
Log:
EJBTHREE-1781 Move to ejb3-endpoint. 

Modified: projects/ejb3/trunk/nointerface/pom.xml
===================================================================
--- projects/ejb3/trunk/nointerface/pom.xml	2009-03-23 13:47:33 UTC (rev 86204)
+++ projects/ejb3/trunk/nointerface/pom.xml	2009-03-23 14:09:55 UTC (rev 86205)
@@ -208,8 +208,8 @@
 
     <dependency>
       <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-proxy-spi</artifactId>
-      <version>1.0.0-SNAPSHOT</version>
+      <artifactId>jboss-ejb3-endpoint</artifactId>
+      <version>0.1.0-SNAPSHOT</version>
     </dependency>
 
     <dependency>

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-03-23 13:47:33 UTC (rev 86204)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/MCAwareStatefulNoInterfaceViewFactory.java	2009-03-23 14:09:55 UTC (rev 86205)
@@ -25,9 +25,9 @@
 import java.lang.reflect.InvocationHandler;
 
 import org.jboss.dependency.spi.ControllerState;
+import org.jboss.ejb3.endpoint.SessionFactory;
 import org.jboss.ejb3.nointerface.NoInterfaceEJBViewCreator;
 import org.jboss.ejb3.nointerface.invocationhandler.MCAwareNoInterfaceViewInvocationHandler;
-import org.jboss.ejb3.proxy.spi.container.StatefulSessionFactory;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.logging.Logger;
 
@@ -116,11 +116,11 @@
 
       // now get hold of the StatefulSessionFactory from the context
       Object statefulSessionFactory = this.statefulSessionFactoryContext.getTarget();
-      assert statefulSessionFactory instanceof StatefulSessionFactory : "Unexpected object type found "
-            + statefulSessionFactory + " - expected a " + StatefulSessionFactory.class;
+      assert statefulSessionFactory instanceof SessionFactory : "Unexpected object type found "
+            + statefulSessionFactory + " - expected a " + SessionFactory.class;
 
       // create the session
-      Serializable session = ((StatefulSessionFactory) statefulSessionFactory).createSession();
+      Serializable session = ((SessionFactory) statefulSessionFactory).createSession(null, null);
       logger.debug("Created session " + session + " for " + this.beanClass);
 
       // create an invocation handler

Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/MCAwareNoInterfaceViewInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/MCAwareNoInterfaceViewInvocationHandler.java	2009-03-23 13:47:33 UTC (rev 86204)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/MCAwareNoInterfaceViewInvocationHandler.java	2009-03-23 14:09:55 UTC (rev 86205)
@@ -21,14 +21,14 @@
  */
 package org.jboss.ejb3.nointerface.invocationhandler;
 
+import java.io.Serializable;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 
 import javax.ejb.EJBContainer;
 
 import org.jboss.dependency.spi.ControllerState;
-import org.jboss.ejb3.common.lang.SerializableMethod;
-import org.jboss.ejb3.proxy.spi.container.InvokableContext;
+import org.jboss.ejb3.endpoint.Endpoint;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.logging.Logger;
 
@@ -47,6 +47,34 @@
 {
 
    /**
+    * Equals and hashCode methods are handled within this invocation handler
+    */
+   private static final Method METHOD_EQUALS;
+
+   private static final Method METHOD_HASH_CODE;
+
+   private static final Method METHOD_TO_STRING;
+
+   static
+   {
+      try
+      {
+         METHOD_EQUALS = Object.class.getDeclaredMethod("equals", Object.class);
+         METHOD_HASH_CODE = Object.class.getDeclaredMethod("hashCode");
+         METHOD_TO_STRING = Object.class.getDeclaredMethod("toString");
+      }
+      catch (SecurityException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (NoSuchMethodException e)
+      {
+         throw new RuntimeException(e);
+      }
+
+   }
+
+   /**
     * Logger
     */
    private static Logger logger = Logger.getLogger(MCAwareNoInterfaceViewInvocationHandler.class);
@@ -65,19 +93,19 @@
    private KernelControllerContext containerContext;
 
    /**
-    * The target (=sessionId) used to interact with the {@link InvokableContext}
+    * The session used to interact with the {@link Endpoint}
     */
-   private Object target;
+   private Serializable session;
 
    /**
     * Constructor
     * @param container
     */
-   public MCAwareNoInterfaceViewInvocationHandler(KernelControllerContext containerContext, Object target)
+   public MCAwareNoInterfaceViewInvocationHandler(KernelControllerContext containerContext, Serializable session)
    {
       assert containerContext != null : "Container context is null for no-interface view invocation handler";
       this.containerContext = containerContext;
-      this.target = target;
+      this.session = session;
    }
 
    /**
@@ -91,21 +119,26 @@
     */
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
    {
-      // TODO: Some methods like toString() can be handled locally.
-      // But as of now let's just pass it on to the container.
-
-      if (logger.isTraceEnabled())
+      // handle equals() and hashCode() in this InvocationHandler
+      try
       {
-         logger.trace("Pushing the container context to INSTALLED state from its current state = "
-               + this.containerContext.getState().getStateString());
+         return handleDirectly(proxy, method, args);
       }
-      // first push the context corresponding to the container to INSTALLED
-      this.containerContext.getController().change(this.containerContext, ControllerState.INSTALLED);
-      // get hold of the container from its context
-      InvokableContext container = (InvokableContext) this.containerContext.getTarget();
-      // finally pass on the control to the container
-      SerializableMethod serializableMethod = new SerializableMethod(method);
-      return container.invoke(this.target, serializableMethod, args);
+      catch (CannotHandleDirectlyException chde)
+      {
+         //ignore
+         if (logger.isTraceEnabled())
+         {
+            logger.trace("Cannot handle method: " + method.getName() + " in " + this.getClass().getName());
+         }
+      }
+      // get the container (which will involve pushing it to INSTALLED state)
+      Endpoint container = getInstalledContainer();
+      assert container != null : "No container associated with context " + this.containerContext
+            + " - cannot invoke the method on bean";
+
+      // finally pass-on the control to the container
+      return container.invoke(this.session, null, method, args);
    }
 
    /**
@@ -118,4 +151,198 @@
       return this.containerContext;
    }
 
+   /**
+    * Returns the {@link Endpoint} container corresponding to this 
+    * {@link MCAwareNoInterfaceViewInvocationHandler}. Internally, the {@link Endpoint} 
+    * will be first pushed to the INSTALLED state 
+    * 
+    * @return
+    */
+   public Endpoint getInstalledContainer()
+   {
+      if (logger.isTraceEnabled())
+      {
+         logger.trace("Pushing the container context to INSTALLED state from its current state = "
+               + this.containerContext.getState().getStateString());
+      }
+      try
+      {
+         // first push the context corresponding to the container to INSTALLED
+         this.containerContext.getController().change(this.containerContext, ControllerState.INSTALLED);
+         // get hold of the container from its context
+         Endpoint container = (Endpoint) this.containerContext.getTarget();
+         return container;
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException("Error getting container out of container KernelControllerContext "
+               + this.containerContext, t);
+      }
+
+   }
+
+   /**
+    * Returns the {@link Endpoint} container corresponding to this 
+    * {@link MCAwareNoInterfaceViewInvocationHandler}. Note that this method does NOT
+    * change the state of the KernelControllerContext of this Endpoint. As such,
+    * the Endpoint returned by this method is NOT guaranteed to be in INSTALLED state.
+    * If the Endpoint with INSTALLED state is required, then use the {@link #getInstalledContainer()}
+    * method. 
+    *  
+    * @return
+    * @see #getInstalledContainer()
+    */
+   private Endpoint getContainer()
+   {
+      Object container = this.containerContext.getTarget();
+      assert container instanceof Endpoint : "Unexpected type " + container.getClass().getName() + " found in context "
+            + this.containerContext + " Expected " + Endpoint.class.getName();
+      return (Endpoint) container;
+   }
+
+   /**
+    * @see Object#equals(Object)
+    */
+   @Override
+   public boolean equals(Object other)
+   {
+      // simple object comparison
+      if (this == other)
+      {
+         return true;
+      }
+
+      // equals() method contract specifies that if the other object is null
+      // then equals() should return false
+      if (other == null)
+      {
+         return false;
+      }
+
+      // If the other object is not an instance of MCAwareNoInterfaceViewInvocationHandler
+      // then they are not equal
+      if (!(other instanceof MCAwareNoInterfaceViewInvocationHandler))
+      {
+         return false;
+      }
+
+      MCAwareNoInterfaceViewInvocationHandler otherNoInterfaceViewInvocationHandler = (MCAwareNoInterfaceViewInvocationHandler) other;
+
+      // First check whether the Endpoints of both these InvocationHandlers are equal. If 
+      // not, then no need for any further comparison, just return false
+      if (!(this.getInstalledContainer().equals(otherNoInterfaceViewInvocationHandler.getInstalledContainer())))
+      {
+         return false;
+      }
+
+      // If the endpoints are equal, then let's next check whether the sessions for
+      // these invocation handlers are equal. If not, return false.
+      if (!(this.session.equals(otherNoInterfaceViewInvocationHandler.session)))
+      {
+         return false;
+      }
+      // All possible, inequality conditions have been tested, so return true.
+      return true;
+   }
+
+   /**
+    * @see Object#hashCode()
+    */
+   @Override
+   public int hashCode()
+   {
+      int hashCode = this.getInstalledContainer().hashCode();
+      if (this.session != null)
+      {
+         hashCode += this.session.hashCode();
+      }
+      return hashCode;
+   }
+
+   /**
+    * @see Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      StringBuilder sb = new StringBuilder("No-Interface view for endpoint [ " + this.getContainer() + " ]");
+      if (this.session != null)
+      {
+         sb.append(" and session " + this.session);
+      }
+      return sb.toString();
+   }
+
+   /**
+    * Handles {@link Object#equals(Object)} and {@link Object#hashCode()} method invocations on the 
+    * proxy.
+    * 
+    * @param proxy
+    * @param method The method that was invoked on the no-interface view
+    * @param args The arguments to the method
+    * @return  
+    * @throws CannotHandleDirectlyException If the <code>method</code> is neither {@link Object#equals(Object) nor Object#hashCode()
+    */
+   private Object handleDirectly(Object proxy, Method method, Object[] args) throws CannotHandleDirectlyException
+   {
+
+      // if equals()
+      if (method.equals(METHOD_EQUALS))
+      {
+         Object other = args[0];
+         // if the other object is null, then it's a false straight-away as per the
+         // contract of equals method
+         if (other == null)
+         {
+            return false;
+         }
+         // simple instance comparison
+         if (this == other)
+         {
+            return true;
+         }
+
+         // This is the important one (and a good one) - thanks to Carlo
+         // When the equals is called on the no-interface view - view1.equals(view2)
+         // we somehow have to get the invocation handler (which hold the session information) for view2.
+         // So the trick here is to first check whether the other is an instance of 
+         // MCAwareNoInterfaceViewInvocationHandler. If not, then invoke the equals on that object.
+         //  - If the "other" happens to be an no-interface view, the call will be redirected
+         // to the invocation handler of view2 and thus we have the session information that we needed
+         // from view2.
+         //  - If the "other" happens to be an instance of some other class, then that class' equals
+         // would return false since its not an instance of MCAwareNoInterfaceViewInvocationHandler.
+         if (!(other instanceof MCAwareNoInterfaceViewInvocationHandler))
+         {
+            return other.equals(this);
+         }
+
+         return this.equals(other);
+      }
+      // handle hashCode
+      else if (method.equals(METHOD_HASH_CODE))
+      {
+         return this.hashCode();
+      }
+      else if (method.equals(METHOD_TO_STRING))
+      {
+         return this.toString();
+      }
+      throw new CannotHandleDirectlyException();
+   }
+
+   /**
+    * 
+    * CannotHandleDirectlyException
+    * 
+    * Will be used to indicate that this {@link MCAwareNoInterfaceViewInvocationHandler} cannot 
+    * handle the method invocation in the invocation handler. 
+    *
+    * @author Jaikiran Pai
+    * @version $Revision: $
+    */
+   private class CannotHandleDirectlyException extends Exception
+   {
+   }
+
 }

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-23 13:47:33 UTC (rev 86204)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java	2009-03-23 14:09:55 UTC (rev 86205)
@@ -32,7 +32,6 @@
 import org.jboss.ejb3.nointerface.factory.MCAwareStatefulNoInterfaceViewFactory;
 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.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;

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-23 13:47:33 UTC (rev 86204)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatefulContainer.java	2009-03-23 14:09:55 UTC (rev 86205)
@@ -26,11 +26,9 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.InvocationResponse;
-import org.jboss.ejb3.common.lang.SerializableMethod;
-import org.jboss.ejb3.proxy.spi.container.InvokableContext;
-import org.jboss.ejb3.proxy.spi.container.StatefulSessionFactory;
+import org.jboss.ejb3.endpoint.Endpoint;
+import org.jboss.ejb3.endpoint.SessionFactory;
+import org.jboss.logging.Logger;
 
 /**
  * MockStatefulContainer
@@ -42,10 +40,15 @@
  * @author Jaikiran Pai
  * @version $Revision: $
  */
-public class MockStatefulContainer implements InvokableContext, StatefulSessionFactory
+public class MockStatefulContainer implements Endpoint, SessionFactory
 
 {
    /**
+    * Logger
+    */
+   private Logger logger = Logger.getLogger(MockStatefulContainer.class);
+
+   /**
     * The bean class represented by this container
     */
    private Class<?> beanClass;
@@ -69,36 +72,23 @@
       this.beanClass = beanClass;
    }
 
-   /**
-    * @see InvokableContext#dynamicInvoke(Invocation)
-    */
-   public InvocationResponse dynamicInvoke(Invocation invocation) throws Throwable
+   @Override
+   public Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
+         throws Throwable
    {
-      // TODO : We don't do anything related to remoting right now in these tests.
-      // Let's ignore this for now
-      return null;
-   }
+      // get the bean instance using the session 
 
-   /**
-    * @see InvokableContext#invoke(Object, SerializableMethod, Object[])
-    */
-   public Object invoke(Object proxy, SerializableMethod method, Object[] args) throws Throwable
-   {
-      // get the bean instance using the target (=sessionId) 
-      Object target = proxy;
-      assert target instanceof Long : "Unexcepted session. Expected a session id of type Long";
-      Long sessionid = (Long) target;
-      Object beanInstance = sessions.get(sessionid);
-      Method invokedMethod = method.toMethod();
-      return invokedMethod.invoke(beanInstance, args);
-
+      Object beanInstance = sessions.get(session);
+      if (beanInstance == null)
+      {
+         logger.error("No bean instance found for session " + session + " for bean class " + beanClass.getName());
+         throw new RuntimeException("No bean instance found for session " + session);
+      }
+      return method.invoke(beanInstance, args);
    }
 
-   /**
-    * Creates a session
-    * @see StatefulSessionFactory#createSession()
-    */
-   public Serializable createSession()
+   @Override
+   public Serializable createSession(Class<?>[] initTypes, Object[] initValues)
    {
       synchronized (currentSessionId)
       {
@@ -114,17 +104,14 @@
          }
          return currentSessionId;
       }
-
    }
 
-   /**
-    * @see InvokableContext#removeTarget(Object)
-    */
-   public void removeTarget(Object target) throws UnsupportedOperationException
+   @Override
+   public void destroySession(Serializable session)
    {
       synchronized (sessions)
       {
-         sessions.remove(target);
+         sessions.remove(session);
       }
 
    }

Modified: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatelessContainer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatelessContainer.java	2009-03-23 13:47:33 UTC (rev 86204)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/common/MockStatelessContainer.java	2009-03-23 14:09:55 UTC (rev 86205)
@@ -21,12 +21,10 @@
  */
 package org.jboss.ejb3.nointerface.test.common;
 
+import java.io.Serializable;
 import java.lang.reflect.Method;
 
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.InvocationResponse;
-import org.jboss.ejb3.common.lang.SerializableMethod;
-import org.jboss.ejb3.proxy.spi.container.InvokableContext;
+import org.jboss.ejb3.endpoint.Endpoint;
 
 /**
  * MockStatelessContainer
@@ -38,7 +36,7 @@
  * @author Jaikiran Pai
  * @version $Revision: $
  */
-public class MockStatelessContainer implements InvokableContext
+public class MockStatelessContainer implements Endpoint
 {
 
    /**
@@ -55,36 +53,15 @@
       this.beanClass = beanClass;
    }
 
-   /**
-    * @see InvokableContext#dynamicInvoke(Invocation)
-    */
-   public InvocationResponse dynamicInvoke(Invocation invocation) throws Throwable
+   @Override
+   public Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
+         throws Throwable
    {
-      // TODO : We don't do anything related to remoting right now in these tests.
-      // Let's ignore this for now
-      return null;
-   }
 
-   /**
-    * @see InvokableContext#invoke(Object, SerializableMethod, Object[])
-    */
-   public Object invoke(Object proxy, SerializableMethod method, Object[] args) throws Throwable
-   {
-      // nothing fancy, just pass on the invocation to the bean class instance
-      Method invokedMethod = method.toMethod();
       // since this is for testing, creation of new bean instance on each invocation
       // should be manageable
       Object beanInstance = beanClass.newInstance();
-      return invokedMethod.invoke(beanInstance, args);
+      return method.invoke(beanInstance, args);
    }
 
-   /**
-    * @see InvokableContext#removeTarget(Object)
-    */
-   public void removeTarget(Object arg0) throws UnsupportedOperationException
-   {
-      // no-op for stateless container
-
-   }
-
 }

Modified: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java	2009-03-23 13:47:33 UTC (rev 86204)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java	2009-03-23 14:09:55 UTC (rev 86205)
@@ -29,9 +29,9 @@
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.endpoint.Endpoint;
 import org.jboss.ejb3.nointerface.test.common.MockStatefulContainer;
 import org.jboss.ejb3.nointerface.test.common.MockStatelessContainer;
-import org.jboss.ejb3.proxy.spi.container.InvokableContext;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
@@ -46,7 +46,7 @@
  *
  *
  * @see MockStatefulContainer
- * @see MockStatelessContainer
+ * @see MockContainer
  *
  * @author Jaikiran Pai
  * @version $Revision: $
@@ -59,7 +59,7 @@
    public MockContainerDeployer()
    {
       setInput(JBossMetaData.class);
-      // the InvokableContext (container) will be installed as output
+      // the Endpoint (container) will be installed as output
       addOutput(BeanMetaData.class);
 
    }
@@ -97,28 +97,26 @@
 
    }
 
-
    private void deploy(DeploymentUnit unit, JBossSessionBeanMetaData sessionBeanMetadata) throws DeploymentException
    {
       try
       {
          String beanClassName = sessionBeanMetadata.getEjbClass();
-         InvokableContext container = null;
-         if (sessionBeanMetadata.isStateless())
+         Endpoint container = null;
+         if (sessionBeanMetadata.isStateful())
          {
-            container = new MockStatelessContainer(Class.forName(beanClassName, false, unit.getClassLoader()));
+            container = new MockStatefulContainer(Class.forName(beanClassName, false, unit.getClassLoader()));
          }
-         else if (sessionBeanMetadata.isStateful())
+         else if (sessionBeanMetadata.isStateless())
          {
-            container = new MockStatefulContainer(Class.forName(beanClassName, false, unit.getClassLoader()));
+            container = new MockStatelessContainer(Class.forName(beanClassName, false, unit.getClassLoader()));
          }
          else
          {
-            logger
-                  .warn("Support for only stateful/stateless beans available, right now in the tests. Ignoring bean class "
-                        + beanClassName);
-            return;
+            logger.error("Bean " + beanClassName + " is neither stateful nor stateless, cannot create a container");
+            throw new DeploymentException("Bean " + beanClassName + " is of unrecognized type");
          }
+
          // install the container in MC. Getting the container name is currently duplicated (copied from)
          // Ejb3NoInterfaceDeployer.
          String containerName = getContainerName(unit, sessionBeanMetadata);
@@ -134,6 +132,7 @@
          DeploymentException.rethrowAsDeploymentException("Could not create container for unit " + unit, e);
       }
    }
+
    /**
     *
     * Ultimately, the container name should come from the <code>sessionBeanMetadata</code>.

Added: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatefulLocalBeanWithInterfaces.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatefulLocalBeanWithInterfaces.java	                        (rev 0)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/StatefulLocalBeanWithInterfaces.java	2009-03-23 14:09:55 UTC (rev 86205)
@@ -0,0 +1,20 @@
+/**
+ * 
+ */
+package org.jboss.ejb3.nointerface.test.viewcreator;
+
+import javax.ejb.LocalBean;
+import javax.ejb.Stateful;
+
+/**
+ * StatefulLocalBeanWithInterfaces
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateful
+ at LocalBean
+public class StatefulLocalBeanWithInterfaces extends StatefulBeanWithInterfaces
+{
+
+}

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-23 13:47:33 UTC (rev 86204)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java	2009-03-23 14:09:55 UTC (rev 86205)
@@ -22,6 +22,7 @@
 package org.jboss.ejb3.nointerface.test.viewcreator.unit;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -38,6 +39,7 @@
 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.StatefulLocalBeanWithInterfaces;
 import org.jboss.ejb3.nointerface.test.viewcreator.StatelessBeanWithInterfaces;
 import org.jboss.ejb3.nointerface.test.viewcreator.StatelessLocalBeanWithInterfaces;
 import org.jboss.ejb3.test.common.MetaDataHelper;
@@ -313,17 +315,15 @@
       assertEquals("Invocation on no-interface view method of SLSB returned an unexpected return message",
             returnedMessage, "Hi " + name);
 
-      JBossSessionBeanMetaData childBeanMetadata = MetaDataHelper
-            .getMetadataFromBeanImplClass(ChildBean.class);
+      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);
-      
 
    }
 
@@ -395,15 +395,129 @@
             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));
+      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));
+
    }
 
    /**
+    * Tests that the {@link Object#equals(Object)} method on a no-interface view of a SLSB, behaves
+    * as per the contract
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testEqualsOnSLSBNoInterfaceView() throws Exception
+   {
+      JBossSessionBeanMetaData slsbMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(SimpleSLSBWithoutInterface.class);
+      String jndiName = slsbMetadata.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 slsbOne = (SimpleSLSBWithoutInterface) ctx.lookup(jndiName);
+
+      SimpleSLSBWithoutInterface slsbTwo = (SimpleSLSBWithoutInterface) ctx.lookup(jndiName);
+
+      // compare two instances of no-interface view of the same bean
+      assertEquals("Two no-interface views for the same SLSB are not equal", slsbOne, slsbTwo);
+
+      // compare against null
+      assertFalse("NULL and a no-interface view should not be \"equal\"", slsbOne.equals(null));
+
+      // compare with itself
+      assertTrue("equals() on the same instance of no-interface view for SLSB should always be true", slsbTwo
+            .equals(slsbTwo));
+
+      // another different SLSB
+      JBossSessionBeanMetaData anotherSLSBMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(StatelessLocalBeanWithInterfaces.class);
+      String oneMoreSLSBJndiName = anotherSLSBMetadata.getEjbName() + "/no-interface";
+
+      assertBoundAndOfExpectedType(ctx, oneMoreSLSBJndiName, StatelessLocalBeanWithInterfaces.class);
+      // at this point we are sure we will get the no-interface view
+      StatelessLocalBeanWithInterfaces differentSLSB = (StatelessLocalBeanWithInterfaces) ctx
+            .lookup(oneMoreSLSBJndiName);
+
+      // compare no-interface views of 2 different SLS beans 
+      assertFalse("no-interfaces views of different SLSB classes should not be equal", slsbOne.equals(differentSLSB));
+
+      // SFSB
+      JBossSessionBeanMetaData sfsbMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(SimpleSFSBeanWithoutInterfaces.class);
+      String sfsbJndiName = sfsbMetadata.getEjbName() + "/no-interface";
+
+      assertBoundAndOfExpectedType(ctx, sfsbJndiName, SimpleSFSBeanWithoutInterfaces.class);
+      // at this point we are sure we will get the no-interface view
+      SimpleSFSBeanWithoutInterfaces sfsb = (SimpleSFSBeanWithoutInterfaces) ctx.lookup(sfsbJndiName);
+
+      // compare a no-interface view of SLSB against no-interface view of SFSB
+      assertFalse("no-interface view of SLSB should not be equal to no-interface view of SFSB", slsbTwo.equals(sfsb));
+
+   }
+
+   /**
+    * Tests that the {@link Object#equals(Object)} method on a no-interface view of a SFSB, behaves
+    * as per the contract
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testEqualsOnSFSBNoInterfaceView() throws Exception
+   {
+      JBossSessionBeanMetaData sfsbMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(SimpleSFSBeanWithoutInterfaces.class);
+      String jndiName = sfsbMetadata.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 sfsbOne = (SimpleSFSBeanWithoutInterfaces) ctx.lookup(jndiName);
+
+      SimpleSFSBeanWithoutInterfaces sfsbTwo = (SimpleSFSBeanWithoutInterfaces) ctx.lookup(jndiName);
+
+      // compare two instances of no-interface view of the same bean
+      assertFalse("Two no-interface views/sessions for the same SFSB are equal", sfsbOne.equals(sfsbTwo));
+
+      // compare against null
+      assertFalse("NULL and a no-interface view should not be \"equal\"", sfsbOne.equals(null));
+
+      // compare with itself
+      assertTrue("equals() on the same instance of no-interface view for SFSB should always be true", sfsbTwo
+            .equals(sfsbTwo));
+
+      // another different SFSB
+      JBossSessionBeanMetaData anotherSFSBMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(StatefulLocalBeanWithInterfaces.class);
+      String oneMoreSFSBJndiName = anotherSFSBMetadata.getEjbName() + "/no-interface";
+
+      assertBoundAndOfExpectedType(ctx, oneMoreSFSBJndiName, StatefulLocalBeanWithInterfaces.class);
+      // at this point we are sure we will get the no-interface view
+      StatefulLocalBeanWithInterfaces differentSFSB = (StatefulLocalBeanWithInterfaces) ctx.lookup(oneMoreSFSBJndiName);
+
+      // compare no-interface views of 2 different SFS beans 
+      assertFalse("no-interfaces views of different SFSB classes should not be equal", sfsbOne.equals(differentSFSB));
+
+      // SLSB
+      JBossSessionBeanMetaData slsbMetadata = MetaDataHelper
+            .getMetadataFromBeanImplClass(SimpleSLSBWithoutInterface.class);
+      String slsbJndiName = slsbMetadata.getEjbName() + "/no-interface";
+
+      assertBoundAndOfExpectedType(ctx, slsbJndiName, SimpleSLSBWithoutInterface.class);
+      // at this point we are sure we will get the no-interface view
+      SimpleSLSBWithoutInterface slsb = (SimpleSLSBWithoutInterface) ctx.lookup(slsbJndiName);
+
+      // compare a no-interface view of SFSB against no-interface view of SLSB
+      assertFalse("no-interface view of SFSB should not be equal to no-interface view of SLSB", sfsbOne.equals(slsb));
+
+   }
+
+   /**
     * Utility method for testing that the bean is bound at the <code>jndiName</code>
     * and is of the <code>expectedType</code>
     * 
@@ -420,8 +534,8 @@
 
       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()));
+      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