Author: gavin.king(a)jboss.com
Date: 2008-12-07 12:55:49 -0500 (Sun, 07 Dec 2008)
New Revision: 446
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerFieldBeanLifecycleTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerFieldBeanModelTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/OtherSpiderProducer.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/OtherBrokenSpiderProducer.java
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/AnimalStereotype.java
Log:
tests for producer fields
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerFieldBeanLifecycleTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerFieldBeanLifecycleTest.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerFieldBeanLifecycleTest.java 2008-12-07
17:55:49 UTC (rev 446)
@@ -0,0 +1,60 @@
+package org.jboss.webbeans.test;
+
+import static org.jboss.webbeans.util.BeanFactory.createProducerFieldBean;
+import static org.jboss.webbeans.util.BeanFactory.createSimpleBean;
+
+import java.lang.reflect.Field;
+
+import javax.webbeans.IllegalProductException;
+
+import org.jboss.webbeans.bean.ProducerFieldBean;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.test.beans.OtherSpiderProducer;
+import org.jboss.webbeans.test.beans.Spider;
+import org.jboss.webbeans.test.beans.Tarantula;
+import org.jboss.webbeans.test.beans.broken.OtherBrokenSpiderProducer;
+import org.testng.annotations.Test;
+
+public class ProducerFieldBeanLifecycleTest extends AbstractTest
+{
+
+ @Test(groups="producerField") @SpecAssertion(section="5.6")
+ public void testProducerFieldBeanCreate() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> spiderProducer =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(spiderProducer);
+ Field method = OtherSpiderProducer.class.getField("produceTarantula");
+ ProducerFieldBean<Tarantula> tarantulaBean =
createProducerFieldBean(Tarantula.class, method, spiderProducer);
+ Tarantula tarantula = tarantulaBean.create();
+ assert tarantula != null;
+ }
+
+ @Test(groups={"stub", "specialization"})
@SpecAssertion(section="3.3.3")
+ public void testSpecializedBeanAlwaysUsed()
+ {
+ // TODO Placeholder
+ assert false;
+ }
+
+
+ @Test(groups="producerField") @SpecAssertion(section={"3.4",
"5.6", "8.3"})
+ public void testProducerFieldReturnsNullIsDependent() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> spiderProducer =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(spiderProducer);
+ Field method = OtherSpiderProducer.class.getField("getNullSpider");
+ ProducerFieldBean<Spider> spiderBean = createProducerFieldBean(Spider.class,
method, spiderProducer);
+ Spider spider = spiderBean.create();
+ assert spider == null;
+ }
+
+ @Test(groups="producerField",
expectedExceptions=IllegalProductException.class) @SpecAssertion(section={"3.4",
"5.6"})
+ public void testProducerFieldReturnsNullIsNotDependent() throws Exception
+ {
+ SimpleBean<OtherBrokenSpiderProducer> spiderProducer =
createSimpleBean(OtherBrokenSpiderProducer.class);
+ manager.addBean(spiderProducer);
+ Field method =
OtherBrokenSpiderProducer.class.getField("getRequestScopedSpider");
+ createProducerFieldBean(Spider.class, method, spiderProducer).create();
+ }
+
+}
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerFieldBeanModelTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerFieldBeanModelTest.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerFieldBeanModelTest.java 2008-12-07
17:55:49 UTC (rev 446)
@@ -0,0 +1,270 @@
+package org.jboss.webbeans.test;
+
+import static org.jboss.webbeans.util.BeanFactory.createProducerFieldBean;
+import static org.jboss.webbeans.util.BeanFactory.createSimpleBean;
+
+import java.lang.reflect.Field;
+
+import javax.webbeans.Current;
+import javax.webbeans.DefinitionException;
+import javax.webbeans.Production;
+import javax.webbeans.RequestScoped;
+
+import org.jboss.webbeans.bean.ProducerFieldBean;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
+import org.jboss.webbeans.test.annotations.Tame;
+import org.jboss.webbeans.test.beans.Animal;
+import org.jboss.webbeans.test.beans.BlackWidow;
+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.FunnelWeaver;
+import org.jboss.webbeans.test.beans.LadybirdSpider;
+import org.jboss.webbeans.test.beans.OtherSpiderProducer;
+import org.jboss.webbeans.test.beans.Spider;
+import org.jboss.webbeans.test.beans.Tarantula;
+import org.jboss.webbeans.test.beans.WolfSpider;
+import org.jboss.webbeans.test.beans.broken.OtherBrokenSpiderProducer;
+import org.testng.annotations.Test;
+
+public class ProducerFieldBeanModelTest extends AbstractTest
+{
+
+ @Test(groups="producerField") @SpecAssertion(section="2.5.3")
+ public void testProducerFieldInheritsDeploymentTypeOfDeclaringWebBean() throws
Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field =
OtherSpiderProducer.class.getField("produceTameTarantula");
+ ProducerFieldBean<Tarantula> tarantulaModel =
createProducerFieldBean(Tarantula.class, field, bean);
+ tarantulaModel.getDeploymentType().equals(AnotherDeploymentType.class);
+ }
+
+ /*@Test(groups="producerField",
expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4")
+ public void testStaticField() throws Exception
+ {
+ SimpleBean<BeanWithStaticProducerField> bean =
createSimpleBean(BeanWithStaticProducerField.class);
+ manager.addBean(bean);
+ Field field = BeanWithStaticProducerField.class.getField("getString");
+ createProducerFieldBean(String.class, field, bean);
+ }*/
+
+ @Test(groups={"stub", "producerField",
"enterpriseBeans", "stub"},
expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4")
+ public void testProducerFieldIsNotBusinessField() throws Exception
+ {
+ assert false;
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section="3.4")
+ public void testParameterizedReturnType() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field =
OtherSpiderProducer.class.getField("getFunnelWeaverSpider");
+ createProducerFieldBean(FunnelWeaver.class, field, bean);
+ }
+
+ @Test(groups="producerField", expectedExceptions=DefinitionException.class)
@SpecAssertion(section="3.4")
+ public void testParameterizedReturnTypeWithWildcard() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field =
OtherSpiderProducer.class.getField("getAnotherFunnelWeaver");
+ createProducerFieldBean(FunnelWeaver.class, field, bean);
+ }
+
+ @Test(groups={"stub", "producerField", "deployment"})
@SpecAssertion(section="3.4")
+ public void testBeanDeclaresMultipleProducerFields()
+ {
+ assert false;
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section={"3.4",
"2.3.1"})
+ public void testDefaultBindingType() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field = OtherSpiderProducer.class.getField("produceTarantula");
+ ProducerFieldBean<Tarantula> tarantulaModel =
createProducerFieldBean(Tarantula.class, field, bean);
+ assert tarantulaModel.getBindingTypes().size() == 1;
+ assert
tarantulaModel.getBindingTypes().iterator().next().annotationType().equals(Current.class);
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section="3.4.1")
+ public void testApiTypeForClassReturn() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field = OtherSpiderProducer.class.getField("produceTarantula");
+ ProducerFieldBean<Tarantula> tarantulaModel =
createProducerFieldBean(Tarantula.class, field, bean);
+ assert tarantulaModel.getTypes().size() == 6;
+ assert tarantulaModel.getTypes().contains(Tarantula.class);
+ assert tarantulaModel.getTypes().contains(DeadlySpider.class);
+ assert tarantulaModel.getTypes().contains(Spider.class);
+ assert tarantulaModel.getTypes().contains(Animal.class);
+ assert tarantulaModel.getTypes().contains(DeadlyAnimal.class);
+ assert tarantulaModel.getTypes().contains(Object.class);
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section="3.4.1")
+ public void testApiTypeForInterfaceReturn() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field = OtherSpiderProducer.class.getField("makeASpider");
+ ProducerFieldBean<Animal> animalModel = createProducerFieldBean(Animal.class,
field, bean);
+ assert animalModel.getTypes().size() == 2;
+ assert animalModel.getTypes().contains(Animal.class);
+ assert animalModel.getTypes().contains(Object.class);
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section="3.4.1")
+ public void testApiTypeForPrimitiveReturn() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field = OtherSpiderProducer.class.getField("getWolfSpiderSize");
+ ProducerFieldBean<Integer> intModel = createProducerFieldBean(int.class,
field, bean);
+ assert intModel.getTypes().size() == 2;
+ assert intModel.getTypes().contains(int.class);
+ assert intModel.getTypes().contains(Object.class);
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section={"3.4.1",
"2.2"})
+ public void testApiTypeForArrayTypeReturn() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field = OtherSpiderProducer.class.getField("getSpiders");
+ ProducerFieldBean<Spider[]> spidersModel =
createProducerFieldBean(Spider[].class, field, bean);
+ assert spidersModel.getTypes().size() == 2;
+ assert spidersModel.getTypes().contains(Spider[].class);
+ assert spidersModel.getTypes().contains(Object.class);
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section="3.4.2")
+ public void testBindingType() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field =
OtherSpiderProducer.class.getField("produceTameTarantula");
+ ProducerFieldBean<Tarantula> tarantulaModel =
createProducerFieldBean(Tarantula.class, field, bean);
+ assert tarantulaModel.getBindingTypes().size() == 1;
+ assert
tarantulaModel.getBindingTypes().iterator().next().annotationType().equals(Tame.class);
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section="3.4.2")
+ public void testScopeType() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field =
OtherSpiderProducer.class.getField("produceDaddyLongLegs");
+ ProducerFieldBean<DaddyLongLegs> daddyLongLegsModel =
createProducerFieldBean(DaddyLongLegs.class, field, bean);
+ assert daddyLongLegsModel.getScopeType().equals(RequestScoped.class);
+
+ // TODO Inherit scope from returned web bean?
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section="3.4.2")
+ public void testDeploymentType() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field = OtherSpiderProducer.class.getField("getLadybirdSpider");
+ ProducerFieldBean<LadybirdSpider> ladybirdSpiderModel =
createProducerFieldBean(LadybirdSpider.class, field, bean);
+ assert ladybirdSpiderModel.getDeploymentType().equals(Production.class);
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section="3.4.2")
+ public void testNamedField() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field = OtherSpiderProducer.class.getField("produceBlackWidow");
+ ProducerFieldBean<BlackWidow> blackWidowSpiderModel =
createProducerFieldBean(BlackWidow.class, field, bean);
+ assert blackWidowSpiderModel.getName().equals("blackWidow");
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section="3.4.2")
+ public void testDefaultNamedField() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field =
OtherSpiderProducer.class.getField("produceDaddyLongLegs");
+ ProducerFieldBean<DaddyLongLegs> daddyLongLegsSpiderModel =
createProducerFieldBean(DaddyLongLegs.class, field, bean);
+ assert
daddyLongLegsSpiderModel.getName().equals("produceDaddyLongLegs");
+ }
+
+ @Test(groups={"stub", "disposalField"})
@SpecAssertion(section="3.3.4")
+ public void testDisposalFieldNonStatic()
+ {
+ // TODO Placeholder
+ assert false;
+ }
+
+ @Test(groups={"stub", "disposalField"})
@SpecAssertion(section="3.3.4")
+ public void testDisposalFieldFieldDeclaredOnWebBeanImplementationClass()
+ {
+ // TODO Placeholder
+ assert false;
+ }
+
+ @Test(groups={"stub", "disposalField"})
@SpecAssertion(section="3.3.4")
+ public void testDisposalFieldBindingAnnotations()
+ {
+ // TODO Placeholder
+ assert false;
+ }
+
+ @Test(groups={"stub", "disposalField"})
@SpecAssertion(section="3.3.4")
+ public void testDisposalFieldDefaultBindingAnnotations()
+ {
+ // TODO Placeholder
+ assert false;
+ }
+
+ @Test(groups={"stub", "disposalField"})
@SpecAssertion(section="3.3.4")
+ public void testDisposalFieldDoesNotResolveToProducerField()
+ {
+ // TODO Placeholder
+ assert false;
+ }
+
+ @Test(groups={"stub", "disposalField"})
@SpecAssertion(section="3.3.5")
+ public void testDisposalFieldDeclaredOnEnabledBean()
+ {
+ // TODO Placeholder
+ // TODO Move this
+
+ assert false;
+ }
+
+ @Test(groups={"stub", "disposalField"})
@SpecAssertion(section="3.3.5")
+ public void testBeanCanDeclareMultipleDisposalFields()
+ {
+ // TODO move this
+ // TODO Placeholder
+ assert false;
+ }
+
+ @Test(groups={"stub", "disposalField"})
@SpecAssertion(section="3.3.5")
+ public void testProducerFieldHasNoMoreThanOneDisposalField()
+ {
+ // TODO move this
+ // TODO Placeholder
+ assert false;
+ }
+
+ @Test(groups="producerField") @SpecAssertion(section={"2.7.2",
"3.4.2", "2.2"})
+ public void testStereotype() throws Exception
+ {
+ SimpleBean<OtherSpiderProducer> bean =
createSimpleBean(OtherSpiderProducer.class);
+ manager.addBean(bean);
+ Field field = OtherSpiderProducer.class.getField("produceWolfSpider");
+ ProducerFieldBean<WolfSpider> wolfSpiderModel =
createProducerFieldBean(WolfSpider.class, field, bean);
+ 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-12-07
17:50:01 UTC (rev 445)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/AnimalStereotype.java 2008-12-07
17:55:49 UTC (rev 446)
@@ -1,5 +1,6 @@
package org.jboss.webbeans.test.annotations;
+import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -13,7 +14,7 @@
import org.jboss.webbeans.test.beans.Animal;
@Stereotype(requiredTypes=Animal.class)
-@Target( { TYPE, METHOD })
+@Target( { TYPE, METHOD, FIELD })
@Retention(RUNTIME)
@RequestScoped
public @interface AnimalStereotype
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/OtherSpiderProducer.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/OtherSpiderProducer.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/OtherSpiderProducer.java 2008-12-07
17:55:49 UTC (rev 446)
@@ -0,0 +1,49 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Dependent;
+import javax.webbeans.Named;
+import javax.webbeans.Produces;
+import javax.webbeans.Production;
+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;
+
+@AnotherDeploymentType
+public class OtherSpiderProducer
+{
+
+ private static Spider[] ALL_SPIDERS = { new Tarantula(), new LadybirdSpider(), new
DaddyLongLegs() };
+
+ @Produces @Tame public Tarantula produceTameTarantula = new DefangedTarantula();
+
+ @Produces public Tarantula produceTarantula = new Tarantula();
+
+ @Produces @Dependent public final TrapdoorSpider produceTrapdoorSpider = new
TrapdoorSpider();
+
+ @Produces @Named("blackWidow") public BlackWidow produceBlackWidow = new
BlackWidow();
+
+ @Produces @Named @RequestScoped public DaddyLongLegs produceDaddyLongLegs = new
DaddyLongLegs();
+
+ @Produces @Named @Production public LadybirdSpider getLadybirdSpider = new
LadybirdSpider();
+
+ @Produces @Named("Shelob") public Tarantula produceShelob;
+
+ @Produces @AnimalStereotype public WolfSpider produceWolfSpider = new WolfSpider();
+
+ @Produces public Animal makeASpider = new WolfSpider();
+
+ @Produces public int getWolfSpiderSize = 4;
+
+ @Produces public Spider[] getSpiders = ALL_SPIDERS;
+
+ @Produces public String[] getStrings = new String[0];
+
+ @Produces public FunnelWeaver<?> getAnotherFunnelWeaver = new
FunnelWeaver<Object>();
+
+ @Produces public FunnelWeaver<Spider> getFunnelWeaverSpider = new
FunnelWeaver<Spider>();
+
+ @Produces public Spider getNullSpider = null;
+
+}
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/OtherBrokenSpiderProducer.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/OtherBrokenSpiderProducer.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/OtherBrokenSpiderProducer.java 2008-12-07
17:55:49 UTC (rev 446)
@@ -0,0 +1,36 @@
+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;
+import javax.webbeans.RequestScoped;
+
+import org.jboss.webbeans.test.beans.Spider;
+
+@Production
+public class OtherBrokenSpiderProducer
+{
+
+ @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";
+ }
+
+ @Produces @RequestScoped public Spider getRequestScopedSpider = null;
+
+}