[webbeans-commits] Webbeans SVN: r1094 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/bean/proxy and 4 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Mon Jan 19 16:19:40 EST 2009


Author: nickarls
Date: 2009-01-19 16:19:40 -0500 (Mon, 19 Jan 2009)
New Revision: 1094

Added:
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/Bad.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/BadLocal.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/RemoveMethodTests.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/InternalEjbDescriptor.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointProvider.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
Log:
EJB remove method changes + broken tests for Pete to check.

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java	2009-01-19 21:14:14 UTC (rev 1093)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java	2009-01-19 21:19:40 UTC (rev 1094)
@@ -50,6 +50,7 @@
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.util.Proxies;
+import org.jboss.webbeans.util.Reflections;
 
 /**
  * An enterprise bean representation
@@ -64,12 +65,9 @@
 
    // The EJB descriptor
    private InternalEjbDescriptor<T> ejbDescriptor;
-   
+
    private Class<T> proxyClass;
 
-   // The remove method on the bean class (do not call!)
-   private AnnotatedMethod<?> removeMethod;
-
    /**
     * Creates a simple, annotation defined Enterprise Web Bean
     * 
@@ -125,13 +123,11 @@
       }
       super.init();
       initProxyClass();
-      initRemoveMethod();
       initInjectionPoints();
       checkEnterpriseBeanTypeAllowed();
       checkEnterpriseScopeAllowed();
       checkConflictingRoles();
       checkSpecialization();
-      checkRemoveMethod();
    }
 
    /**
@@ -141,15 +137,8 @@
    protected void initInjectionPoints()
    {
       super.initInjectionPoints();
-      if (removeMethod != null)
-      {
-         for (AnnotatedParameter<?> injectable : removeMethod.getParameters())
-         {
-            annotatedInjectionPoints.add(injectable);
-         }
-      }
    }
-   
+
    protected void initTypes()
    {
       types = new HashSet<Type>();
@@ -159,14 +148,14 @@
       }
       types.add(Object.class);
    }
-   
+
    protected void initProxyClass()
    {
       ProxyFactory proxyFactory = Proxies.getProxyFactory(getTypes());
-      
+
       @SuppressWarnings("unchecked")
       Class<T> proxyClass = proxyFactory.createClass();
-      
+
       this.proxyClass = proxyClass;
    }
 
@@ -218,83 +207,6 @@
    }
 
    /**
-    * Initializes the remvoe method
-    */
-   protected void initRemoveMethod()
-   {
-
-      // >1 @Destructor
-      if (getAnnotatedItem().getAnnotatedMethods(Destructor.class).size() > 1)
-      {
-         throw new DefinitionException("Multiple @Destructor methods not allowed on " + getAnnotatedItem());
-      }
-
-      if (getAnnotatedItem().getAnnotatedMethods(Destructor.class).size() == 1)
-      {
-         AnnotatedMethod<?> destructorMethod = getAnnotatedItem().getAnnotatedMethods(Destructor.class).iterator().next();
-         for (Method removeMethod : ejbDescriptor.getRemoveMethods())
-         {
-            if (removeMethod != null && destructorMethod.isEquivalent(removeMethod))
-            {
-               this.removeMethod = destructorMethod;
-               return;
-            }
-         }
-         throw new DefinitionException("Method annotated @Destructor is not an EJB remove method on " + toString());
-      }
-      Set<Method> noArgsRemoveMethods = new HashSet<Method>();
-      for (Method removeMethod : ejbDescriptor.getRemoveMethods())
-      {
-         if (removeMethod.getParameterTypes().length == 0)
-         {
-            noArgsRemoveMethods.add(removeMethod);
-         }
-      }
-      if (noArgsRemoveMethods.size() == 1)
-      {
-         this.removeMethod = annotatedItem.getMethod(noArgsRemoveMethods.iterator().next());
-         return;
-      }
-
-      if (!getScopeType().equals(Dependent.class))
-      {
-         throw new DefinitionException("Only @Dependent scoped enterprise beans can be without remove methods " + toString());
-      }
-
-   }
-
-   /**
-    * Validates the remove method
-    */
-   private void checkRemoveMethod()
-   {
-      if (removeMethod == null)
-      {
-         return;
-      }
-      else if (ejbDescriptor.isStateless())
-      {
-         throw new DefinitionException("Can't define a remove method on SLSBs");
-      }
-      if (removeMethod.isAnnotationPresent(Initializer.class))
-      {
-         throw new DefinitionException("Remove methods cannot be initializers on " + removeMethod.getName());
-      }
-      else if (removeMethod.isAnnotationPresent(Produces.class))
-      {
-         throw new DefinitionException("Remove methods cannot be producers on " + removeMethod.getName());
-      }
-      else if (removeMethod.getAnnotatedParameters(Disposes.class).size() > 0)
-      {
-         throw new DefinitionException("Remove method can't have @Disposes annotated parameters on " + removeMethod.getName());
-      }
-      else if (removeMethod.getAnnotatedParameters(Observes.class).size() > 0)
-      {
-         throw new DefinitionException("Remove method can't have @Observes annotated parameters on " + removeMethod.getName());
-      }
-   }
-
-   /**
     * Creates an instance of the bean
     * 
     * @return The instance
@@ -306,7 +218,7 @@
       {
          DependentContext.INSTANCE.setActive(true);
          T instance = proxyClass.newInstance();
-         ((ProxyObject) instance).setHandler(new EnterpriseBeanProxyMethodHandler(this)); 
+         ((ProxyObject) instance).setHandler(new EnterpriseBeanProxyMethodHandler(this, ejbDescriptor.getRemoveMethods()));
          return instance;
       }
       catch (InstantiationException e)
@@ -335,19 +247,11 @@
    @Override
    public void destroy(T instance)
    {
-      try
+      Boolean isDestroyed = (Boolean) Reflections.invokeAndWrap("isDestroyed", null, instance, null);
+      if (isDestroyed.booleanValue())
       {
-         DependentContext.INSTANCE.setActive(true);
-         removeMethod.invokeOnInstance(instance, manager);
+         return;
       }
-      catch (Exception e)
-      {
-         log.error("Error destroying " + toString(), e);
-      }
-      finally
-      {
-         DependentContext.INSTANCE.setActive(false);
-      }
    }
 
    /**
@@ -394,11 +298,6 @@
 
    }
 
-   public AnnotatedMethod<?> getRemoveMethod()
-   {
-      return removeMethod;
-   }
-
    /**
     * Validates the bean type
     */
@@ -454,9 +353,8 @@
 
    }
 
-   public void preDestroy(T target)
+   public void preDestroy(T instance)
    {
-
    }
 
    @Override
@@ -470,4 +368,9 @@
       return ejbDescriptor;
    }
 
+   public boolean canCallRemoveMethods()
+   {
+      return getEjbDescriptor().isStateful() && Dependent.class.equals(getScopeType());
+   }
+
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java	2009-01-19 21:14:14 UTC (rev 1093)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java	2009-01-19 21:19:40 UTC (rev 1094)
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.jboss.webbeans.bean;
 
 import java.lang.annotation.Annotation;
@@ -31,47 +30,87 @@
 import org.jboss.webbeans.literal.NewLiteral;
 
 /**
+ * Represents a @New enterprise bean
  * 
  * @author Nicklas Karlsson
- *
  */
 public class NewEnterpriseBean<T> extends EnterpriseBean<T>
 {
    private static Set<Annotation> NEW_BINDING_SET = new HashSet<Annotation>(Arrays.asList(new NewLiteral()));
 
+   /**
+    * Creates an instance of a NewEnterpriseBean from an annotated class
+    * 
+    * @param clazz The annotated class
+    * @param manager The Web Beans manager
+    * @return a new NewEnterpriseBean instance
+    */
    public static <T> NewEnterpriseBean<T> of(AnnotatedClass<T> clazz, ManagerImpl manager)
    {
       return new NewEnterpriseBean<T>(clazz, manager);
    }
 
+   /**
+    * Creates an instance of a NewEnterpriseBean from a class
+    * 
+    * @param clazz The class
+    * @param manager The Web Beans manager
+    * @return a new NewEnterpriseBean instance
+    */
    public static <T> NewEnterpriseBean<T> of(Class<T> clazz, ManagerImpl manager)
    {
       return of(AnnotatedClassImpl.of(clazz), manager);
    }
 
+   /**
+    * Protected constructor
+    * 
+    * @param type An annotated class
+    * @param manager The Web Beans manager
+    */
    protected NewEnterpriseBean(AnnotatedClass<T> type, ManagerImpl manager)
    {
       super(type, manager);
    }
 
+   /**
+    * Gets the scope type
+    * 
+    * @return @Dependent
+    */
    @Override
    public Class<? extends Annotation> getScopeType()
    {
       return Dependent.class;
    }
 
+   /**
+    * Gets the deployment type
+    * 
+    * @return The standard deployment type
+    */
    @Override
    public Class<? extends Annotation> getDeploymentType()
    {
       return Standard.class;
    }
 
+   /**
+    * Gets the name of the bean
+    * 
+    * @return null
+    */
    @Override
    public String getName()
    {
       return null;
    }
 
+   /**
+    * Gets the bindings
+    * 
+    * @returns @New
+    */
    @Override
    public Set<Annotation> getBindings()
    {

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java	2009-01-19 21:14:14 UTC (rev 1093)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java	2009-01-19 21:19:40 UTC (rev 1094)
@@ -32,29 +32,52 @@
 import org.jboss.webbeans.literal.NewLiteral;
 
 /**
+ * Represents a @New simple bean
  * 
- * @author Nicklas Karlsson
- *
+ * @author Nicklas Karlsson 
  */
 public class NewSimpleBean<T> extends SimpleBean<T>
 {
    private static Set<Annotation> NEW_BINDING_SET = new HashSet<Annotation>(Arrays.asList(new NewLiteral()));
 
+   /**
+    * Creates an instance of a NewSimpleBean from an annotated class
+    * 
+    * @param clazz The annotated class
+    * @param manager The Web Beans manager
+    * @return a new NewSimpleBean instance
+    */
    public static <T> NewSimpleBean<T> of(AnnotatedClass<T> clazz, ManagerImpl manager)
    {
       return new NewSimpleBean<T>(clazz, manager);
    }
-   
+
+   /**
+    * Creates an instance of a NewSimpleBean from a class
+    * 
+    * @param clazz The class
+    * @param manager The Web Beans manager
+    * @return a new NewSimpleBean instance
+    */
    public static <T> NewSimpleBean<T> of(Class<T> clazz, ManagerImpl manager)
    {
       return of(AnnotatedClassImpl.of(clazz), manager);
    }
-   
+
+   /**
+    * Protected constructor
+    * 
+    * @param type An annotated class
+    * @param manager The Web Beans manager
+    */
    protected NewSimpleBean(AnnotatedClass<T> type, ManagerImpl manager)
    {
       super(type, manager);
    }
 
+   /**
+    * Creates a new instance
+    */
    @Override
    public T create()
    {
@@ -76,24 +99,44 @@
       }
    }
 
+   /**
+    * Gets the scope type
+    * 
+    * @return @Dependent
+    */
    @Override
    public Class<? extends Annotation> getScopeType()
    {
       return Dependent.class;
    }
 
+   /**
+    * Gets the deployment type
+    * 
+    * @return The standard deployment type
+    */
    @Override
    public Class<? extends Annotation> getDeploymentType()
    {
       return Standard.class;
    }
 
+   /**
+    * Gets the name of the bean
+    * 
+    * @return null
+    */
    @Override
    public String getName()
    {
       return null;
    }
 
+   /**
+    * Gets the bindings
+    * 
+    * @returns @New
+    */
    @Override
    public Set<Annotation> getBindings()
    {

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java	2009-01-19 21:14:14 UTC (rev 1093)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java	2009-01-19 21:19:40 UTC (rev 1094)
@@ -18,11 +18,15 @@
 package org.jboss.webbeans.bean.proxy;
 
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javassist.util.proxy.MethodHandler;
 
+import javax.webbeans.Dependent;
+
 import org.jboss.webbeans.CurrentManager;
 import org.jboss.webbeans.bean.EnterpriseBean;
 import org.jboss.webbeans.log.LogProvider;
@@ -34,7 +38,7 @@
  * 
  * @author Nicklas Karlsson
  * @author Pete Muir
- *
+ * 
  */
 public class EnterpriseBeanProxyMethodHandler implements MethodHandler
 {
@@ -44,39 +48,50 @@
    // The container provided proxy that implements all interfaces
    private final Map<Class<?>, Object> proxiedInstances;
    private final Map<Class<?>, String> jndiNames;
+   private boolean destroyed;
+   private boolean canCallRemoveMethods;
+   private final List<Method> removeMethods;
 
    /**
     * Constructor
     * 
+    * @param removeMethods
+    * 
     * @param proxy The generic proxy
     */
-   public EnterpriseBeanProxyMethodHandler(EnterpriseBean<?> bean)
+   public EnterpriseBeanProxyMethodHandler(EnterpriseBean<?> bean, Iterable<Method> removeMethods)
    {
       this.proxiedInstances = new HashMap<Class<?>, Object>();
       this.jndiNames = bean.getEjbDescriptor().getLocalBusinessInterfacesJndiNames();
+      this.canCallRemoveMethods = bean.canCallRemoveMethods();
+      this.removeMethods = bean.getEjbDescriptor().getRemoveMethods();
+      this.destroyed = false;
       log.trace("Created enterprise bean proxy method handler for " + bean);
    }
 
    /**
     * Lookups the EJB in the container and executes the method on it
     * 
-    * @param self          the proxy instance.
-    * @param method        the overridden method declared in the super
-    *                      class or interface.
-    * @param proceed       the forwarder method for invoking the overridden 
-    *                      method.  It is null if the overridden method is
-    *                      abstract or declared in the interface.
-    * @param args          an array of objects containing the values of
-    *                      the arguments passed in the method invocation
-    *                      on the proxy instance.  If a parameter type is
-    *                      a primitive type, the type of the array element
-    *                      is a wrapper class.
-    * @return              the resulting value of the method invocation.
-    *
-    * @throws Throwable    if the method invocation fails.
+    * @param self the proxy instance.
+    * @param method the overridden method declared in the super class or
+    *           interface.
+    * @param proceed the forwarder method for invoking the overridden method. It
+    *           is null if the overridden method is abstract or declared in the
+    *           interface.
+    * @param args an array of objects containing the values of the arguments
+    *           passed in the method invocation on the proxy instance. If a
+    *           parameter type is a primitive type, the type of the array
+    *           element is a wrapper class.
+    * @return the resulting value of the method invocation.
+    * 
+    * @throws Throwable if the method invocation fails.
     */
    public Object invoke(Object self, Method method, Method proceed, Object[] args) throws Throwable
    {
+      if ("isDestroyed".equals(method.getName()))
+      {
+         return destroyed;
+      }
       Class<?> businessInterface = method.getDeclaringClass();
       Object proxiedInstance = proxiedInstances.get(businessInterface);
       if (proxiedInstance == null)
@@ -90,9 +105,19 @@
          proxiedInstances.put(businessInterface, proxiedInstance);
       }
       Method proxiedMethod = Reflections.lookupMethod(method, proxiedInstance);
+      if (removeMethods.contains(proxiedMethod))
+      {
+         if (canCallRemoveMethods)
+         {
+            destroyed = true;
+         }
+         else
+         {
+            throw new UnsupportedOperationException("Remove method can't be called directly on non-dependent scoped Enterprise Beans");
+         }
+      }
       Object returnValue = Reflections.invokeAndWrap(proxiedMethod, proxiedInstance, args);
       log.trace("Executed " + method + " on " + proxiedInstance + " with parameters " + args + " and got return value " + returnValue);
       return returnValue;
    }
-
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/InternalEjbDescriptor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/InternalEjbDescriptor.java	2009-01-19 21:14:14 UTC (rev 1093)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/InternalEjbDescriptor.java	2009-01-19 21:19:40 UTC (rev 1094)
@@ -17,8 +17,11 @@
 
 package org.jboss.webbeans.ejb;
 
+import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.jboss.webbeans.ejb.spi.BusinessInterfaceDescriptor;
@@ -34,10 +37,11 @@
  */
 public class InternalEjbDescriptor<T> extends ForwardingEjbDescriptor<T> implements EjbDescriptor<T>
 {
- 
+
    private final Map<Class<?>, String> localBusinessInterfacesJndiNames;
    private final EjbDescriptor<T> delegate;
-   
+   public List<Method> removeMethods;
+
    public InternalEjbDescriptor(EjbDescriptor<T> ejbDescriptor)
    {
       this.delegate = ejbDescriptor;
@@ -46,21 +50,31 @@
       {
          localBusinessInterfacesJndiNames.put(businessInterfaceDescriptor.getInterface(), businessInterfaceDescriptor.getJndiName());
       }
-      // Internally, Object.class is added to the type hierachy of an 
+      // Internally, Object.class is added to the type hierachy of an
       // EnterpriseBean, so we need to represent that here. We can just use any
       // of the local business interfaces
       localBusinessInterfacesJndiNames.put(Object.class, ejbDescriptor.getLocalBusinessInterfaces().iterator().next().getJndiName());
+      removeMethods = new ArrayList<Method>();
+      for (Method removeMethod : ejbDescriptor.getRemoveMethods())
+      {
+         removeMethods.add(removeMethod);
+      }
    }
-   
+
    public Map<Class<?>, String> getLocalBusinessInterfacesJndiNames()
    {
       return Collections.unmodifiableMap(localBusinessInterfacesJndiNames);
    }
-   
+
+   public List<Method> getRemoveMethods()
+   {
+      return Collections.unmodifiableList(removeMethods);
+   }
+
    @Override
    protected EjbDescriptor<T> delegate()
    {
       return delegate;
    }
-   
+
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointProvider.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointProvider.java	2009-01-19 21:14:14 UTC (rev 1093)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointProvider.java	2009-01-19 21:19:40 UTC (rev 1094)
@@ -68,7 +68,9 @@
    {
       injectionPoints.push(InjectionPointImpl.of(injectionPoint, getCurrentBean()));
       if (beans.size() != injectionPoints.size())
+      {
          throw new IllegalStateException("Number of beans on stack is inconsistent with number of injection points: " + this);
+      }
    }
 
    /**
@@ -107,7 +109,7 @@
     * Gets the current bean
     * 
     * @return The current bean or null if there is none on the stack
-    */   
+    */
    protected Bean<?> getCurrentBean()
    {
       return beans.isEmpty() ? null : beans.peek();
@@ -117,7 +119,7 @@
     * Gets the previous bean
     * 
     * @return The previous bean or null if there is none on the stack
-    */   
+    */
    protected Bean<?> getPreviousBean()
    {
       return beans.size() < 2 ? null : beans.elementAt(beans.size() - 2);
@@ -126,8 +128,7 @@
    @Override
    public String toString()
    {
-      return "InjectionPointProvider: Bean stack = " + beans.toString() +
-         " InjectionPoint stack = " + injectionPoints.toString();
+      return "InjectionPointProvider: Bean stack = " + beans.toString() + " InjectionPoint stack = " + injectionPoints.toString();
    }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java	2009-01-19 21:14:14 UTC (rev 1093)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java	2009-01-19 21:19:40 UTC (rev 1094)
@@ -220,7 +220,9 @@
          else
          {
             if (!producerMethod)
+            {
                injectionPointProvider.pushInjectionPoint(param);
+            }
             try
             {
                parameterValues[i] = param.getValue(manager);
@@ -228,7 +230,9 @@
             finally
             {
                if (!producerMethod)
+               {
                   injectionPointProvider.popInjectionPoint();
+               }
             }
          }
       }

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/Bad.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/Bad.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/Bad.java	2009-01-19 21:19:40 UTC (rev 1094)
@@ -0,0 +1,16 @@
+package org.jboss.webbeans.test.unit.implementation;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.webbeans.RequestScoped;
+
+
+ at Stateful
+ at RequestScoped
+public class Bad implements BadLocal
+{
+   @Remove
+   public void bye()
+   {
+   }
+}

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/BadLocal.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/BadLocal.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/BadLocal.java	2009-01-19 21:19:40 UTC (rev 1094)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.unit.implementation;
+
+import javax.ejb.Local;
+import javax.ejb.Remove;
+
+ at Local
+public interface BadLocal
+{
+   @Remove
+   public void bye();
+}

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/RemoveMethodTests.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/RemoveMethodTests.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/implementation/RemoveMethodTests.java	2009-01-19 21:19:40 UTC (rev 1094)
@@ -0,0 +1,50 @@
+package org.jboss.webbeans.test.unit.implementation;
+
+import org.jboss.webbeans.bean.EnterpriseBean;
+import org.jboss.webbeans.test.unit.AbstractEjbEmbeddableTest;
+import org.testng.annotations.Test;
+
+public class RemoveMethodTests extends AbstractEjbEmbeddableTest
+{
+
+   /**
+    * If the application directly calls an EJB remove method of an instance of a
+    * session bean that is a stateful session bean and declares any scope other
+    * than @Dependent, an UnsupportedOperationException is thrown.
+    */
+   @Test(groups = { "enterprisebean", "removemethod", "lifecycle", "stub" })
+   public void testApplicationCalledRemoveMethodOfStatefulSessionBeanWithNonDependentScopeFails()
+   {
+      assert false;
+   }
+
+   /**
+    * If the application directly calls an EJB remove method of an instance of a
+    * session bean that is a stateful session bean and has scope @Dependent then
+    * no parameters are passed to the method by the container.
+    */
+   @Test(groups = { "enterprisebean", "removemethod", "lifecycle", "stub" })
+   public void testApplicationCalledRemoveMethodOfStatefulSessionBeanWithDependentScopeHasNoInjectedParameters()
+   {
+      addToEjbCache(Bad.class);
+      addToEjbCache(BadLocal.class);
+      EnterpriseBean<Bad> bean = EnterpriseBean.of(Bad.class, manager);
+      manager.addBean(bean);
+      EnterpriseBean<BadLocal> lbean = EnterpriseBean.of(BadLocal.class, manager);
+      manager.addBean(lbean);
+      BadLocal x = manager.getInstance(bean);
+      x.bye();
+   }
+
+   /**
+    * Furthermore, the container ignores the instance instead of destroying it
+    * when Bean.destroy() is called, as defined in Section 6.5, “Lifecycle of
+    * stateful session beans”.
+    */
+   @Test(groups = { "enterprisebean", "removemethod", "lifecycle", "stub" })
+   public void testApplicationCalledRemoveMethodOfStatefulSessionBeanWithDependentScopeIsIgnoredWhenDestroyed()
+   {
+      assert false;
+   }
+
+}




More information about the weld-commits mailing list