[webbeans-commits] Webbeans SVN: r258 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/model/bean and 5 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Thu Nov 6 08:40:54 EST 2008
Author: pete.muir at jboss.org
Date: 2008-11-06 08:40:53 -0500 (Thu, 06 Nov 2008)
New Revision: 258
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/WolfSpider.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BrokenSpiderProducer.java
Removed:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BeanWithFinalProducerMethod.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/AnimalStereotype.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/LadybirdSpider.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java
Log:
Start to fix producer tests
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java 2008-11-06 11:55:14 UTC (rev 257)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -1,22 +1,23 @@
package org.jboss.webbeans.bean;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.model.bean.BeanModel;
+import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
public class ProducerBean<T> extends AbstractBean<T>
{
+
+ private ProducerMethodBeanModel<T> model;
- public ProducerBean(ManagerImpl manager)
+ public ProducerBean(ProducerMethodBeanModel<T> model, ManagerImpl manager)
{
super(manager);
- // TODO Auto-generated constructor stub
+ this.model = model;
}
@Override
- public BeanModel<T, ?> getModel()
+ public ProducerMethodBeanModel<T> getModel()
{
- // TODO Auto-generated method stub
- return null;
+ return model;
}
@Override
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java 2008-11-06 11:55:14 UTC (rev 257)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -41,7 +41,7 @@
protected Class<? extends Annotation> deploymentType;
protected Class<T> type;
protected InjectableMethod<?> removeMethod;
- private Set<Class<?>> apiTypes;
+ protected Set<Class<?>> apiTypes;
protected Set<Injectable<?, ?>> injectionPoints;
private boolean primitive;
protected ManagerImpl manager;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java 2008-11-06 11:55:14 UTC (rev 257)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -4,10 +4,13 @@
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.HashSet;
import java.util.Set;
import javax.webbeans.DefinitionException;
-import javax.webbeans.Dependent;
+import javax.webbeans.Destructor;
+import javax.webbeans.Disposes;
+import javax.webbeans.Observes;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.injectable.InjectableMethod;
@@ -22,7 +25,7 @@
private MethodConstructor<T> constructor;
- private AnnotatedItem<T, Method> xmlAnnotatedItem = null /*new SimpleAnnotatedItem<T, Method>(new HashMap<Class<? extends Annotation>, Annotation>())*/;
+ private AnnotatedItem<T, Method> xmlAnnotatedItem;
private AnnotatedMethod<T> annotatedMethod;
private BeanModel<?, ?> declaringBean;
@@ -31,10 +34,11 @@
private String location;
private Type declaredBeanType;
- public ProducerMethodBeanModel(AnnotatedMethod<T> annotatedMethod, ManagerImpl container)
+ public ProducerMethodBeanModel(AnnotatedMethod<T> annotatedMethod, AnnotatedMethod<T> xmlAnnotatedMethod, ManagerImpl manager)
{
this.annotatedMethod = annotatedMethod;
- init(container);
+ this.xmlAnnotatedItem = xmlAnnotatedMethod;
+ init(manager);
}
@Override
@@ -80,7 +84,6 @@
protected void initDeclaringBean(ManagerImpl container)
{
- // TODO replace
declaringBean = container.getModelManager().getBeanModel(getAnnotatedItem().getDelegate().getDeclaringClass());
}
@@ -95,11 +98,18 @@
{
throw new DefinitionException("Producer method cannot be static " + annotatedMethod);
}
- // TODO Check if declaring class is a WB bean
- if (!getScopeType().equals(Dependent.class) && getAnnotatedItem().isFinal())
+ else if (getAnnotatedItem().isAnnotationPresent(Destructor.class))
{
- throw new RuntimeException("Final producer method must have @Dependent scope " + annotatedMethod);
+ throw new DefinitionException("Producer method cannot be annotated @Destructor");
}
+ else if (getAnnotatedItem().getAnnotatedParameters(Observes.class).size() > 0)
+ {
+ throw new DefinitionException("Producer method cannot have parameter annotated @Observes");
+ }
+ else if (getAnnotatedItem().getAnnotatedParameters(Disposes.class).size() > 0)
+ {
+ throw new DefinitionException("Producer method cannot have parameter annotated @Disposes");
+ }
}
protected void initRemoveMethod(ManagerImpl container)
@@ -165,6 +175,26 @@
}
}
+ @Override
+ protected void initApiTypes()
+ {
+ if (getType().isArray() || getType().isPrimitive())
+ {
+ super.apiTypes = new HashSet<Class<?>>();
+ super.apiTypes.add(getType());
+ super.apiTypes.add(Object.class);
+ }
+ else if (getType().isInterface())
+ {
+ super.initApiTypes();
+ super.apiTypes.add(Object.class);
+ }
+ else
+ {
+ super.initApiTypes();
+ }
+ }
+
private Type getDeclaredBeanType()
{
if (declaredBeanType == null)
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java 2008-11-06 11:55:14 UTC (rev 257)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -1,5 +1,6 @@
package org.jboss.webbeans.test;
+import static org.jboss.webbeans.test.util.Util.createProducerModel;
import static org.jboss.webbeans.test.util.Util.createSimpleModel;
import java.lang.reflect.Method;
@@ -10,7 +11,6 @@
import org.jboss.webbeans.contexts.AbstractContext;
import org.jboss.webbeans.contexts.RequestContext;
-import org.jboss.webbeans.introspector.impl.SimpleAnnotatedMethod;
import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
import org.jboss.webbeans.test.beans.SpiderProducer;
@@ -70,7 +70,7 @@
SimpleBeanModel<SpiderProducer> producer = createSimpleModel(SpiderProducer.class, manager);
manager.getModelManager().addBeanModel(producer);
Method nullProducer = SpiderProducer.class.getMethod("produceShelob");
- ProducerMethodBeanModel<Tarantula> producerModel = new ProducerMethodBeanModel<Tarantula>(new SimpleAnnotatedMethod<Tarantula>(nullProducer), manager);
+ ProducerMethodBeanModel<Tarantula> producerModel = createProducerModel(Tarantula.class, nullProducer, manager);
//Bean<Tarantula> shelobBean = new ProducerBeanImpl<Tarantula>(producerModel, manager);
//assert context.get(shelobBean, true) == null;
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java 2008-11-06 11:55:14 UTC (rev 257)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -1,14 +1,14 @@
package org.jboss.webbeans.test;
-import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
+import static org.jboss.webbeans.test.util.Util.createProducerModel;
+import static org.jboss.webbeans.test.util.Util.createSimpleModel;
import java.lang.reflect.Method;
import javax.webbeans.Current;
import javax.webbeans.DefinitionException;
+import javax.webbeans.RequestScoped;
-import org.jboss.webbeans.introspector.impl.SimpleAnnotatedClass;
-import org.jboss.webbeans.introspector.impl.SimpleAnnotatedMethod;
import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
@@ -18,10 +18,13 @@
import org.jboss.webbeans.test.beans.DaddyLongLegs;
import org.jboss.webbeans.test.beans.DeadlyAnimal;
import org.jboss.webbeans.test.beans.DeadlySpider;
+import org.jboss.webbeans.test.beans.LadybirdSpider;
import org.jboss.webbeans.test.beans.Spider;
import org.jboss.webbeans.test.beans.SpiderProducer;
import org.jboss.webbeans.test.beans.Tarantula;
+import org.jboss.webbeans.test.beans.WolfSpider;
import org.jboss.webbeans.test.beans.broken.BeanWithStaticProducerMethod;
+import org.jboss.webbeans.test.beans.broken.BrokenSpiderProducer;
import org.testng.annotations.Test;
public class ProducerMethodBeanModelTest extends AbstractTest
@@ -30,23 +33,23 @@
@Test(groups="producerMethod") @SpecAssertion(section="2.5.3")
public void testProducerMethodInheritsDeploymentTypeOfDeclaringWebBean() throws Exception
{
- SimpleBeanModel<SpiderProducer> model = new SimpleBeanModel<SpiderProducer>(new SimpleAnnotatedClass<SpiderProducer>(SpiderProducer.class), getEmptyAnnotatedType(SpiderProducer.class), manager);
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
manager.getModelManager().addBeanModel(model);
Method method = SpiderProducer.class.getMethod("produceTameTarantula");
- ProducerMethodBeanModel<Tarantula> tarantulaModel = new ProducerMethodBeanModel<Tarantula>(new SimpleAnnotatedMethod<Tarantula>(method), manager);
+ ProducerMethodBeanModel<Tarantula> tarantulaModel = createProducerModel(Tarantula.class, method, manager);
tarantulaModel.getDeploymentType().equals(AnotherDeploymentType.class);
}
@Test(groups="producerMethod", expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4")
public void testStaticMethod() throws Exception
{
- SimpleBeanModel<BeanWithStaticProducerMethod> model = new SimpleBeanModel<BeanWithStaticProducerMethod>(new SimpleAnnotatedClass<BeanWithStaticProducerMethod>(BeanWithStaticProducerMethod.class), getEmptyAnnotatedType(BeanWithStaticProducerMethod.class), manager);
+ SimpleBeanModel<BeanWithStaticProducerMethod> model = createSimpleModel(BeanWithStaticProducerMethod.class, manager);
manager.getModelManager().addBeanModel(model);
Method method = BeanWithStaticProducerMethod.class.getMethod("getString");
- new ProducerMethodBeanModel<String>(new SimpleAnnotatedMethod<String>(method), manager);
+ createProducerModel(String.class, method, manager);
}
- @Test(groups="producerMethod", expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4")
+ @Test(groups={"producerMethod", "enterpiseBeans"}, expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4")
public void testProducerMethodIsNotBusinessMethod() throws Exception
{
assert false;
@@ -83,7 +86,7 @@
assert false;
}
- @Test(groups="producerMethod") @SpecAssertion(section="3.4")
+ @Test(groups={"producerMethod", "deployment"}) @SpecAssertion(section="3.4")
public void testBeanDeclaresMultipleProducerMethods()
{
assert false;
@@ -92,10 +95,10 @@
@Test(groups="producerMethod") @SpecAssertion(section="3.4")
public void testDefaultBindingType() throws Exception
{
- SimpleBeanModel<SpiderProducer> model = new SimpleBeanModel<SpiderProducer>(new SimpleAnnotatedClass<SpiderProducer>(SpiderProducer.class), getEmptyAnnotatedType(SpiderProducer.class), manager);
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
manager.getModelManager().addBeanModel(model);
Method method = SpiderProducer.class.getMethod("produceTarantula");
- ProducerMethodBeanModel<Tarantula> tarantulaModel = new ProducerMethodBeanModel<Tarantula>(new SimpleAnnotatedMethod<Tarantula>(method), manager);
+ ProducerMethodBeanModel<Tarantula> tarantulaModel = createProducerModel(Tarantula.class, method, manager);
assert tarantulaModel.getBindingTypes().size() == 1;
assert tarantulaModel.getBindingTypes().iterator().next().annotationType().equals(Current.class);
}
@@ -103,37 +106,62 @@
@Test(groups="producerMethod") @SpecAssertion(section="3.4.1")
public void testApiTypeForClassReturn() throws Exception
{
- SimpleBeanModel<SpiderProducer> model = new SimpleBeanModel<SpiderProducer>(new SimpleAnnotatedClass<SpiderProducer>(SpiderProducer.class), getEmptyAnnotatedType(SpiderProducer.class), manager);
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
manager.getModelManager().addBeanModel(model);
Method method = SpiderProducer.class.getMethod("produceTarantula");
- ProducerMethodBeanModel<Tarantula> tarantulaModel = new ProducerMethodBeanModel<Tarantula>(new SimpleAnnotatedMethod<Tarantula>(method), manager);
+ ProducerMethodBeanModel<Tarantula> tarantulaModel = createProducerModel(Tarantula.class, method, manager);
+ assert tarantulaModel.getApiTypes().size() == 6;
assert tarantulaModel.getApiTypes().contains(Tarantula.class);
assert tarantulaModel.getApiTypes().contains(DeadlySpider.class);
assert tarantulaModel.getApiTypes().contains(Spider.class);
assert tarantulaModel.getApiTypes().contains(Animal.class);
assert tarantulaModel.getApiTypes().contains(DeadlyAnimal.class);
- assert !tarantulaModel.getApiTypes().contains(Object.class);
+ assert tarantulaModel.getApiTypes().contains(Object.class);
}
@Test(groups="producerMethod") @SpecAssertion(section="3.4.1")
+ public void testApiTypeForInterfaceReturn() throws Exception
+ {
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
+ manager.getModelManager().addBeanModel(model);
+ Method method = SpiderProducer.class.getMethod("makeASpider");
+ ProducerMethodBeanModel<Animal> animalModel = createProducerModel(Animal.class, method, manager);
+ assert animalModel.getApiTypes().size() == 2;
+ assert animalModel.getApiTypes().contains(Animal.class);
+ assert animalModel.getApiTypes().contains(Object.class);
+ }
+
+ @Test(groups="producerMethod") @SpecAssertion(section="3.4.1")
public void testApiTypeForPrimitiveReturn() throws Exception
{
- assert false;
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
+ manager.getModelManager().addBeanModel(model);
+ Method method = SpiderProducer.class.getMethod("getWolfSpiderSize");
+ ProducerMethodBeanModel<Integer> intModel = createProducerModel(int.class, method, manager);
+ assert intModel.getApiTypes().size() == 2;
+ assert intModel.getApiTypes().contains(int.class);
+ assert intModel.getApiTypes().contains(Object.class);
}
@Test(groups="producerMethod") @SpecAssertion(section="3.4.1")
public void testApiTypeForArrayTypeReturn() throws Exception
{
- assert false;
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
+ manager.getModelManager().addBeanModel(model);
+ Method method = SpiderProducer.class.getMethod("getSpiders");
+ ProducerMethodBeanModel<Spider[]> spidersModel = createProducerModel(Spider[].class, method, manager);
+ assert spidersModel.getApiTypes().size() == 2;
+ assert spidersModel.getApiTypes().contains(Spider[].class);
+ assert spidersModel.getApiTypes().contains(Object.class);
}
@Test(groups="producerMethod") @SpecAssertion(section="3.4.2")
public void testBindingType() throws Exception
{
- SimpleBeanModel<SpiderProducer> model = new SimpleBeanModel<SpiderProducer>(new SimpleAnnotatedClass<SpiderProducer>(SpiderProducer.class), getEmptyAnnotatedType(SpiderProducer.class), manager);
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
manager.getModelManager().addBeanModel(model);
Method method = SpiderProducer.class.getMethod("produceTameTarantula");
- ProducerMethodBeanModel<Tarantula> tarantulaModel = new ProducerMethodBeanModel<Tarantula>(new SimpleAnnotatedMethod<Tarantula>(method), manager);
+ ProducerMethodBeanModel<Tarantula> tarantulaModel = createProducerModel(Tarantula.class, method, manager);
assert tarantulaModel.getBindingTypes().size() == 1;
assert tarantulaModel.getBindingTypes().iterator().next().annotationType().equals(Tame.class);
}
@@ -141,51 +169,70 @@
@Test(groups="producerMethod") @SpecAssertion(section="3.4.2")
public void testScopeType() throws Exception
{
- assert false;
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
+ manager.getModelManager().addBeanModel(model);
+ Method method = SpiderProducer.class.getMethod("produceDaddyLongLegs");
+ ProducerMethodBeanModel<DaddyLongLegs> daddyLongLegsModel = createProducerModel(DaddyLongLegs.class, method, manager);
+ assert daddyLongLegsModel.getScopeType().equals(RequestScoped.class);
+
+ // TODO Inherit scope from returned web bean?
}
@Test(groups="producerMethod") @SpecAssertion(section="3.4.2")
public void testDeploymentType() throws Exception
{
- assert false;
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
+ manager.getModelManager().addBeanModel(model);
+ Method method = SpiderProducer.class.getMethod("getLadybirdSpider");
+ ProducerMethodBeanModel<LadybirdSpider> ladybirdSpiderModel = createProducerModel(LadybirdSpider.class, method, manager);
+ assert ladybirdSpiderModel.getDeploymentType().equals(AnotherDeploymentType.class);
}
@Test(groups="producerMethod") @SpecAssertion(section="3.4.2")
public void testNamedMethod() throws Exception
{
- SimpleBeanModel<SpiderProducer> model = new SimpleBeanModel<SpiderProducer>(new SimpleAnnotatedClass<SpiderProducer>(SpiderProducer.class), getEmptyAnnotatedType(SpiderProducer.class), manager);
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
manager.getModelManager().addBeanModel(model);
Method method = SpiderProducer.class.getMethod("produceBlackWidow");
- ProducerMethodBeanModel<BlackWidow> blackWidowSpiderModel = new ProducerMethodBeanModel<BlackWidow>(new SimpleAnnotatedMethod<BlackWidow>(method), manager);
+ ProducerMethodBeanModel<BlackWidow> blackWidowSpiderModel = createProducerModel(BlackWidow.class, method, manager);
assert blackWidowSpiderModel.getName().equals("blackWidow");
}
@Test(groups="producerMethod") @SpecAssertion(section="3.4.2")
public void testDefaultNamedMethod() throws Exception
{
- SimpleBeanModel<SpiderProducer> model = new SimpleBeanModel<SpiderProducer>(new SimpleAnnotatedClass<SpiderProducer>(SpiderProducer.class), getEmptyAnnotatedType(SpiderProducer.class), manager);
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
manager.getModelManager().addBeanModel(model);
Method method = SpiderProducer.class.getMethod("produceDaddyLongLegs");
- ProducerMethodBeanModel<DaddyLongLegs> daddyLongLegsSpiderModel = new ProducerMethodBeanModel<DaddyLongLegs>(new SimpleAnnotatedMethod<DaddyLongLegs>(method), manager);
+ ProducerMethodBeanModel<DaddyLongLegs> daddyLongLegsSpiderModel = createProducerModel(DaddyLongLegs.class, method, manager);
assert daddyLongLegsSpiderModel.getName().equals("produceDaddyLongLegs");
}
@Test(groups="producerMethod", expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4")
- public void testProducerMethodAnnotatedObserver()
+ public void testProducerMethodAnnotatedDestructor() throws Exception
{
- assert false;
+ SimpleBeanModel<BrokenSpiderProducer> model = createSimpleModel(BrokenSpiderProducer.class, manager);
+ manager.getModelManager().addBeanModel(model);
+ Method method = BrokenSpiderProducer.class.getMethod("destroy");
+ createProducerModel(String.class, method, manager);
}
@Test(groups="producerMethod", expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4")
- public void testProducerMethodWithParameterAnnotatedDisposes()
+ public void testProducerMethodWithParameterAnnotatedDisposes() throws Exception
{
- assert false;
+ SimpleBeanModel<BrokenSpiderProducer> model = createSimpleModel(BrokenSpiderProducer.class, manager);
+ manager.getModelManager().addBeanModel(model);
+ Method method = BrokenSpiderProducer.class.getMethod("dispose", String.class);
+ createProducerModel(String.class, method, manager);
}
@Test(groups="producerMethod", expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4")
- public void testProducerMethodWithParameterAnnotatedObserves()
+ public void testProducerMethodWithParameterAnnotatedObserves() throws Exception
{
- assert false;
+ SimpleBeanModel<BrokenSpiderProducer> model = createSimpleModel(BrokenSpiderProducer.class, manager);
+ manager.getModelManager().addBeanModel(model);
+ Method method = BrokenSpiderProducer.class.getMethod("observe", String.class);
+ createProducerModel(String.class, method, manager);
}
@Test(groups="disposalMethod") @SpecAssertion(section="3.3.4")
@@ -249,8 +296,14 @@
}
@Test(groups="producerMethod") @SpecAssertion(section={"2.7.2", "3.4.2"})
- public void testSingleStereotype()
+ public void testStereotype() throws Exception
{
- assert false;
+ SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);
+ manager.getModelManager().addBeanModel(model);
+ Method method = SpiderProducer.class.getMethod("produceWolfSpider");
+ ProducerMethodBeanModel<WolfSpider> wolfSpiderModel = createProducerModel(WolfSpider.class, method, manager);
+ assert wolfSpiderModel.getMergedStereotypes().getRequiredTypes().size() == 1;
+ assert wolfSpiderModel.getMergedStereotypes().getRequiredTypes().contains(Animal.class);
+ assert wolfSpiderModel.getScopeType().equals(RequestScoped.class);
}
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/AnimalStereotype.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/AnimalStereotype.java 2008-11-06 11:55:14 UTC (rev 257)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/AnimalStereotype.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -1,5 +1,6 @@
package org.jboss.webbeans.test.annotations;
+import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -12,7 +13,7 @@
import org.jboss.webbeans.test.beans.Animal;
@Stereotype(requiredTypes=Animal.class)
- at Target( { TYPE })
+ at Target( { TYPE, METHOD })
@Retention(RUNTIME)
@RequestScoped
public @interface AnimalStereotype
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/LadybirdSpider.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/LadybirdSpider.java 2008-11-06 11:55:14 UTC (rev 257)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/LadybirdSpider.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -1,5 +1,8 @@
package org.jboss.webbeans.test.beans;
+import javax.webbeans.ApplicationScoped;
+
+ at ApplicationScoped
public class LadybirdSpider extends Spider
{
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java 2008-11-06 11:55:14 UTC (rev 257)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -3,7 +3,9 @@
import javax.webbeans.Dependent;
import javax.webbeans.Named;
import javax.webbeans.Produces;
+import javax.webbeans.RequestScoped;
+import org.jboss.webbeans.test.annotations.AnimalStereotype;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
import org.jboss.webbeans.test.annotations.Tame;
@@ -11,6 +13,8 @@
public class SpiderProducer
{
+ private static Spider[] ALL_SPIDERS = { new Tarantula(), new LadybirdSpider(), new DaddyLongLegs() };
+
@Produces @Tame public Tarantula produceTameTarantula()
{
return new DefangedTarantula();
@@ -31,18 +35,39 @@
return new BlackWidow();
}
- @Produces @Named public DaddyLongLegs produceDaddyLongLegs()
+ @Produces @Named @RequestScoped public DaddyLongLegs produceDaddyLongLegs()
{
return new DaddyLongLegs();
}
- @Produces @Named public LadybirdSpider getLadybirdSpider()
+ @Produces @Named @AnotherDeploymentType public LadybirdSpider getLadybirdSpider()
{
return new LadybirdSpider();
}
- @Produces @Named("Shelob") public Tarantula produceShelob() {
+ @Produces @Named("Shelob") public Tarantula produceShelob()
+ {
return null;
}
+
+ @Produces @AnimalStereotype public WolfSpider produceWolfSpider()
+ {
+ return new WolfSpider();
+ }
+
+ @Produces public Animal makeASpider()
+ {
+ return new WolfSpider();
+ }
+
+ @Produces public int getWolfSpiderSize()
+ {
+ return 4;
+ }
+
+ @Produces public Spider[] getSpiders()
+ {
+ return ALL_SPIDERS;
+ }
}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/WolfSpider.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/WolfSpider.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/WolfSpider.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.beans;
+
+public class WolfSpider implements Animal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/WolfSpider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BeanWithFinalProducerMethod.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BeanWithFinalProducerMethod.java 2008-11-06 11:55:14 UTC (rev 257)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BeanWithFinalProducerMethod.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -1,16 +0,0 @@
-package org.jboss.webbeans.test.beans.broken;
-
-import javax.webbeans.Produces;
-import javax.webbeans.Production;
-import javax.webbeans.RequestScoped;
-
- at Production
-public class BeanWithFinalProducerMethod
-{
-
- @Produces @RequestScoped public final String getString()
- {
- return "Pete";
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BrokenSpiderProducer.java (from rev 257, ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BeanWithFinalProducerMethod.java)
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BrokenSpiderProducer.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BrokenSpiderProducer.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -0,0 +1,31 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import javax.webbeans.Destructor;
+import javax.webbeans.Disposes;
+import javax.webbeans.Observes;
+import javax.webbeans.Produces;
+import javax.webbeans.Production;
+
+ at Production
+public class BrokenSpiderProducer
+{
+
+ @Produces
+ public String observe(@Observes String foo)
+ {
+ return "foo";
+ }
+
+ @Produces
+ public String dispose(@Disposes String foo)
+ {
+ return "foo";
+ }
+
+ @Produces @Destructor
+ public String destroy()
+ {
+ return "foo";
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/BrokenSpiderProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java 2008-11-06 11:55:14 UTC (rev 257)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java 2008-11-06 13:40:53 UTC (rev 258)
@@ -1,13 +1,18 @@
package org.jboss.webbeans.test.util;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
import java.util.HashMap;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bean.ProducerBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.impl.SimpleAnnotatedClass;
+import org.jboss.webbeans.introspector.impl.SimpleAnnotatedMethod;
import org.jboss.webbeans.model.bean.EnterpriseBeanModel;
+import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
public class Util
@@ -37,7 +42,20 @@
return new EnterpriseBeanModel<T>(new SimpleAnnotatedClass<T>(clazz), xmlAnnotatedType, manager);
}
+ public static <T> ProducerBean<T> createProducerMethodBean(Class<T> type, Method method, ManagerImpl manager)
+ {
+ return new ProducerBean<T>(createProducerModel(type, method, null, manager), manager);
+ }
+ public static <T> ProducerMethodBeanModel<T> createProducerModel(Class<T> type, Method method, ManagerImpl manager)
+ {
+ return createProducerModel(type, method, null, manager);
+ }
+
+ public static <T> ProducerMethodBeanModel<T> createProducerModel(Class<T> type, Method method, AnnotatedMethod<T> xmlAnnotatedMethod, ManagerImpl manager)
+ {
+ return new ProducerMethodBeanModel<T>(new SimpleAnnotatedMethod<T>(method), xmlAnnotatedMethod, manager);
+ }
@Deprecated
public static <T> AnnotatedClass<T> getEmptyAnnotatedType(Class<T> type)
More information about the weld-commits
mailing list