[webbeans-commits] Webbeans SVN: r231 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 1 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Tue Nov 4 05:45:28 EST 2008
Author: nickarls
Date: 2008-11-04 05:45:28 -0500 (Tue, 04 Nov 2008)
New Revision: 231
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/JackRussellTerrier.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Pumi.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/RussellTerrier.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Toller.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/WelshCorgie.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EnterpriseBeanModel.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EnterpriseBeanModelTest.java
Log:
Some more EJB tests + fixes
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EnterpriseBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EnterpriseBeanModel.java 2008-11-04 08:27:26 UTC (rev 230)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EnterpriseBeanModel.java 2008-11-04 10:45:28 UTC (rev 231)
@@ -1,12 +1,19 @@
package org.jboss.webbeans.model.bean;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import javax.webbeans.DefinitionException;
import javax.webbeans.Dependent;
import javax.webbeans.Destructor;
+import javax.webbeans.Disposes;
+import javax.webbeans.Initializer;
+import javax.webbeans.Observes;
+import javax.webbeans.Produces;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.injectable.BeanConstructor;
@@ -73,6 +80,7 @@
return location;
}
+
// TODO loggigng
protected void initRemoveMethod(ManagerImpl container)
{
@@ -80,7 +88,8 @@
{
if (getEjbMetaData().getRemoveMethods().size() == 1)
{
- super.removeMethod = new InjectableMethod<Object>(getEjbMetaData().getRemoveMethods().get(0));
+// super.removeMethod = new InjectableMethod<Object>(getEjbMetaData().getRemoveMethods().get(0));
+ super.removeMethod = checkRemoveMethod(getEjbMetaData().getRemoveMethods().get(0));
}
else if (getEjbMetaData().getRemoveMethods().size() > 1)
{
@@ -94,7 +103,7 @@
}
if (possibleRemoveMethods.size() == 1)
{
- super.removeMethod = new InjectableMethod<Object>(possibleRemoveMethods.get(0));
+ super.removeMethod = checkRemoveMethod(possibleRemoveMethods.get(0));
}
else if (possibleRemoveMethods.size() > 1)
{
@@ -115,11 +124,43 @@
List<Method> destroysMethods = Reflections.getMethods(getType(), Destructor.class);
if (destroysMethods.size() > 0)
{
- throw new RuntimeException("Only stateful enterprise beans can have methods annotated @Destructor; " + getType() + " is not a stateful enterprise bean");
+ throw new DefinitionException("Only stateful enterprise beans can have methods annotated @Destructor; " + getType() + " is not a stateful enterprise bean");
}
}
}
+
+ private InjectableMethod<?> checkRemoveMethod(Method method)
+ {
+ if (method.isAnnotationPresent(Initializer.class)) {
+ throw new DefinitionException("Remove methods cannot be initializers on " + method.getName());
+ }
+ if (method.isAnnotationPresent(Produces.class)) {
+ throw new DefinitionException("Remove methods cannot be producers on " + method.getName());
+ }
+ if (hasParameterAnnotation(method.getParameterAnnotations(), Disposes.class)) {
+ throw new DefinitionException("Remove method can't have @Disposes annotated parameters on " + method.getName());
+ }
+ if (hasParameterAnnotation(method.getParameterAnnotations(), Observes.class)) {
+ throw new DefinitionException("Remove method can't have @Observes annotated parameters on " + method.getName());
+ }
+ return new InjectableMethod<Object>(method);
+ }
+
+
+ //FIXME move up?
+ private boolean hasParameterAnnotation(Annotation[][] parameterAnnotations, Class<? extends Annotation> clazz)
+ {
+ for (Annotation[] parameter : parameterAnnotations) {
+ for (Annotation annotation : parameter) {
+ if (annotation.annotationType() == clazz) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
@Override
protected AbstractClassBeanModel<? extends T> getSpecializedType()
{
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EnterpriseBeanModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EnterpriseBeanModelTest.java 2008-11-04 08:27:26 UTC (rev 230)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EnterpriseBeanModelTest.java 2008-11-04 10:45:28 UTC (rev 231)
@@ -16,12 +16,17 @@
import org.jboss.webbeans.test.beans.broken.Greyhound;
import org.jboss.webbeans.test.beans.broken.Husky;
import org.jboss.webbeans.test.beans.broken.IrishTerrier;
+import org.jboss.webbeans.test.beans.broken.JackRussellTerrier;
import org.jboss.webbeans.test.beans.broken.Pekingese;
import org.jboss.webbeans.test.beans.broken.Poodle;
import org.jboss.webbeans.test.beans.broken.Pug;
+import org.jboss.webbeans.test.beans.broken.Pumi;
import org.jboss.webbeans.test.beans.broken.Rottweiler;
+import org.jboss.webbeans.test.beans.broken.RussellTerrier;
import org.jboss.webbeans.test.beans.broken.Saluki;
import org.jboss.webbeans.test.beans.broken.Spitz;
+import org.jboss.webbeans.test.beans.broken.Toller;
+import org.jboss.webbeans.test.beans.broken.WelshCorgie;
import org.jboss.webbeans.test.beans.broken.Whippet;
import org.jboss.webbeans.test.util.Util;
import org.testng.annotations.Test;
@@ -182,7 +187,8 @@
@SpecAssertion(section = "3.3.2")
public void testObjectIsInAPITypes()
{
- assert false;
+ EnterpriseBeanModel<Laika> laika = Util.createEnterpriseBeanModel(Laika.class, manager);
+ assert laika.getApiTypes().contains(Object.class);
}
@Test
@@ -306,23 +312,30 @@
@Test(expectedExceptions = DefinitionException.class)
@SpecAssertion(section = "3.3.5.1")
+ public void testAnnotationDefinedEJBWithDestructorWithDisposesParameterFails()
+ {
+ EnterpriseBeanModel<Pumi> pumi = Util.createEnterpriseBeanModel(Pumi.class, manager);
+ }
+
+ @Test(expectedExceptions = DefinitionException.class)
+ @SpecAssertion(section = "3.3.5.1")
public void testEJBWithInitializerAnnotationOnRemoveMethodFails()
{
- assert false;
+ EnterpriseBeanModel<JackRussellTerrier> jackRussellTerrier = Util.createEnterpriseBeanModel(JackRussellTerrier.class, manager);
}
@Test(expectedExceptions = DefinitionException.class)
@SpecAssertion(section = "3.3.5.1")
public void testEJBWithProducerAnnotationOnRemoveMethodFails()
{
- assert false;
+ EnterpriseBeanModel<RussellTerrier> russellTerrier = Util.createEnterpriseBeanModel(RussellTerrier.class, manager);
}
@Test(expectedExceptions = DefinitionException.class)
@SpecAssertion(section = "3.3.5.1")
public void testEJBWithRemoveMethodTakingObserverAnnotatedParameterFails()
{
- assert false;
+ EnterpriseBeanModel<Toller> toller = Util.createEnterpriseBeanModel(Toller.class, manager);
}
// TODO Separate section for XML defined beans?
@@ -384,6 +397,11 @@
assert pitbull.getName().equals("pitbull");
}
+ @Test(expectedExceptions=DefinitionException.class)
+ public void testStatelessEJBsWithDestructorAnnotationFails()
+ {
+ EnterpriseBeanModel<WelshCorgie> welshCorgie = Util.createEnterpriseBeanModel(WelshCorgie.class, manager);
+ }
/*
@Test
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/JackRussellTerrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/JackRussellTerrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/JackRussellTerrier.java 2008-11-04 10:45:28 UTC (rev 231)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.webbeans.Initializer;
+
+ at Stateful
+public class JackRussellTerrier
+{
+ @Remove
+ @Initializer
+ public void destroy() {
+
+ }
+}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Pumi.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Pumi.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Pumi.java 2008-11-04 10:45:28 UTC (rev 231)
@@ -0,0 +1,17 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.webbeans.Disposes;
+
+import org.jboss.webbeans.test.annotations.Tame;
+import org.jboss.webbeans.test.beans.Horse;
+
+ at Stateful
+public class Pumi
+{
+ @Remove
+ public void destroy(@Disposes @Tame Horse horse) {
+
+ }
+}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/RussellTerrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/RussellTerrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/RussellTerrier.java 2008-11-04 10:45:28 UTC (rev 231)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.webbeans.Produces;
+
+ at Stateful
+public class RussellTerrier
+{
+ @Remove
+ @Produces
+ public void destroy() {
+
+ }
+}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Toller.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Toller.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Toller.java 2008-11-04 10:45:28 UTC (rev 231)
@@ -0,0 +1,17 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.webbeans.Observes;
+
+import org.jboss.webbeans.test.annotations.Tame;
+import org.jboss.webbeans.test.beans.Horse;
+
+ at Stateful
+public class Toller
+{
+ @Remove
+ public void destroy(@Observes @Tame Horse horse) {
+
+ }
+}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/WelshCorgie.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/WelshCorgie.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/WelshCorgie.java 2008-11-04 10:45:28 UTC (rev 231)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import javax.ejb.Stateless;
+import javax.webbeans.Destructor;
+
+ at Stateless
+public class WelshCorgie
+{
+ @Destructor
+ public void destroy() {
+
+ }
+}
More information about the weld-commits
mailing list