Author: jharting
Date: 2009-07-23 10:08:44 -0400 (Thu, 23 Jul 2009)
New Revision: 3156
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Farm.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Sheep.java
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/DynamicLookupTest.java
Log:
Added test for programmatic lookup + cleanup
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/DynamicLookupTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/DynamicLookupTest.java 2009-07-23
14:01:22 UTC (rev 3155)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/DynamicLookupTest.java 2009-07-23
14:08:44 UTC (rev 3156)
@@ -20,7 +20,6 @@
import javax.enterprise.inject.AmbiguousResolutionException;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.UnsatisfiedResolutionException;
-import javax.enterprise.inject.spi.Bean;
import org.hibernate.tck.annotations.SpecAssertion;
import org.hibernate.tck.annotations.SpecAssertions;
@@ -39,17 +38,13 @@
@Artifact
public class DynamicLookupTest extends AbstractJSR299Test
{
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertions({
@SpecAssertion(section = "5.7", id ="aa")
})
public void testObtainsInjectsInstanceOfInstance()
{
- Bean<ObtainsInjectionPointBean> injectionPointBean =
- getBeans(ObtainsInjectionPointBean.class).iterator().next();
-
- ObtainsInjectionPointBean injectionPoint = (ObtainsInjectionPointBean)
-
getCurrentManager().getReference(injectionPointBean,ObtainsInjectionPointBean.class,
getCurrentManager().createCreationalContext(injectionPointBean));
+ ObtainsInjectionPointBean injectionPoint =
getInstanceByType(ObtainsInjectionPointBean.class);
assert injectionPoint.getPaymentProcessor() instanceof Instance;
}
@@ -57,16 +52,11 @@
@SpecAssertions({
@SpecAssertion(section = "5.7", id ="ba"),
@SpecAssertion(section = "5.7", id ="ca"),
- @SpecAssertion(section = "5.7.1", id ="ab"),
- @SpecAssertion(section = "5.7.1", id ="ba")
+ @SpecAssertion(section = "5.7.1", id ="ab")
})
public void testDynamicLookup()
{
- Bean<ObtainsInjectionPointBean> injectionPointBean =
- getBeans(ObtainsInjectionPointBean.class).iterator().next();
-
- ObtainsInjectionPointBean injectionPoint = (ObtainsInjectionPointBean)
- getCurrentManager().getReference( injectionPointBean,
ObtainsInjectionPointBean.class,
getCurrentManager().createCreationalContext(injectionPointBean));
+ ObtainsInjectionPointBean injectionPoint =
getInstanceByType(ObtainsInjectionPointBean.class);
assert injectionPoint.getPaymentProcessor().select(new SynchronousBinding()).get()
instanceof SynchronousChequePaymentProcessor;
}
@@ -74,11 +64,7 @@
@SpecAssertion(section = "5.7.1", id ="da")
public void testDuplicateBindingsThrowsException()
{
- Bean<ObtainsInjectionPointBean> injectionPointBean =
- getBeans(ObtainsInjectionPointBean.class).iterator().next();
-
- ObtainsInjectionPointBean injectionPoint = (ObtainsInjectionPointBean)
-
getCurrentManager().getReference(injectionPointBean,ObtainsInjectionPointBean.class,
getCurrentManager().createCreationalContext(injectionPointBean));
+ ObtainsInjectionPointBean injectionPoint =
getInstanceByType(ObtainsInjectionPointBean.class);
injectionPoint.getPaymentProcessor().select(new SynchronousBinding(), new
SynchronousBinding());
}
@@ -86,11 +72,7 @@
@SpecAssertion(section = "5.7.1", id = "e")
public void testNonBindingThrowsException()
{
- Bean<ObtainsInjectionPointBean> injectionPointBean =
- getBeans(ObtainsInjectionPointBean.class).iterator().next();
-
- ObtainsInjectionPointBean injectionPoint = (ObtainsInjectionPointBean)
-
getCurrentManager().getReference(injectionPointBean,ObtainsInjectionPointBean.class,
getCurrentManager().createCreationalContext(injectionPointBean));
+ ObtainsInjectionPointBean injectionPoint =
getInstanceByType(ObtainsInjectionPointBean.class);
injectionPoint.getPaymentProcessor().select(new NonBinding());
}
@@ -126,4 +108,16 @@
Instance<PaymentProcessor> instance =
injectionPoint.getPaymentProcessor().select(new SynchronousBinding());
assert !instance.isAmbiguous();
}
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section="5.7", id="ba"),
+ @SpecAssertion(section="5.7", id="da"),
+ @SpecAssertion(section="5.7.1", id="fc")})
+ public void testGetMethodReturnsContextualReference() {
+ Sheep sheep = getInstanceByType(Sheep.class);
+ sheep.setAge(10);
+ Farm farm = getInstanceByType(Farm.class);
+ assert farm.getSheep().get().getAge() == sheep.getAge();
+ }
}
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Farm.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Farm.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Farm.java 2009-07-23
14:08:44 UTC (rev 3156)
@@ -0,0 +1,14 @@
+package org.jboss.jsr299.tck.tests.lookup.dynamic;
+
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+
+class Farm
+{
+ @Any private Instance<Sheep> sheep;
+
+ public Instance<Sheep> getSheep()
+ {
+ return sheep;
+ }
+}
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Sheep.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Sheep.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Sheep.java 2009-07-23
14:08:44 UTC (rev 3156)
@@ -0,0 +1,19 @@
+package org.jboss.jsr299.tck.tests.lookup.dynamic;
+
+import javax.enterprise.context.RequestScoped;
+
+@RequestScoped
+class Sheep
+{
+ private int age = 0;
+
+ public int getAge()
+ {
+ return age;
+ }
+
+ public void setAge(int age)
+ {
+ this.age = age;
+ }
+}
Show replies by date