Author: jharting
Date: 2009-07-21 04:04:41 -0400 (Tue, 21 Jul 2009)
New Revision: 3104
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Asynchronous.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/AsynchronousBinding.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SimplePaymentProcessor.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Synchronous.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SynchronousBinding.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SynchronousChequePaymentProcessor.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/AbstractAnimal.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Animal.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/BuiltinInstanceTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Cow.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Farm.java
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/DynamicLookupTest.java
Log:
Programmatic lookup tests
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Asynchronous.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Asynchronous.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Asynchronous.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,19 @@
+package org.jboss.jsr299.tck.tests.lookup.dynamic;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.inject.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+@interface Asynchronous {
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/AsynchronousBinding.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/AsynchronousBinding.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/AsynchronousBinding.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.lookup.dynamic;
+
+import javax.enterprise.inject.AnnotationLiteral;
+
+class AsynchronousBinding extends AnnotationLiteral<Asynchronous> implements
Asynchronous {
+}
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-21
07:54:15 UTC (rev 3103)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/DynamicLookupTest.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -1,8 +1,25 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.jboss.jsr299.tck.tests.lookup.dynamic;
-import static org.jboss.jsr299.tck.tests.lookup.dynamic.PayBy.PaymentMethod.CHEQUE;
+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;
@@ -15,6 +32,7 @@
* Tests for dynamic lookup features
*
* @author Shane Bryzak
+ * @author Jozef Hartinger
*
* Spec version: 20090625
*/
@@ -25,7 +43,7 @@
@SpecAssertions({
@SpecAssertion(section = "5.7", id ="aa")
})
- public void testInstanceMayBeInjected()
+ public void testObtainsInjectsInstanceOfInstance()
{
Bean<ObtainsInjectionPointBean> injectionPointBean =
getBeans(ObtainsInjectionPointBean.class).iterator().next();
@@ -37,42 +55,75 @@
@Test(groups = "ri-broken")
@SpecAssertions({
- @SpecAssertion(section = "5.7", id ="ba"),
+ @SpecAssertion(section = "5.7", id ="review"),
@SpecAssertion(section = "5.7", id ="ca"),
- @SpecAssertion(section = "5.7.1", id ="aa")
+ @SpecAssertion(section = "5.7.1", id ="ab"),
+ @SpecAssertion(section = "5.7.1", id ="ba")
})
- public void testInstanceReturnsContextualReference()
+ public void testDynamicLookup()
{
Bean<ObtainsInjectionPointBean> injectionPointBean =
getBeans(ObtainsInjectionPointBean.class).iterator().next();
ObtainsInjectionPointBean injectionPoint = (ObtainsInjectionPointBean)
getCurrentManager().getReference( injectionPointBean,
ObtainsInjectionPointBean.class,
getCurrentManager().createCreationalContext(injectionPointBean));
- assert injectionPoint.getPaymentProcessor().get() instanceof
ChequePaymentProcessor;
+ assert injectionPoint.getPaymentProcessor().select(new SynchronousBinding()).get()
instanceof SynchronousChequePaymentProcessor;
}
@Test(groups = "ri-broken", expectedExceptions =
IllegalArgumentException.class)
@SpecAssertion(section = "5.7.1", id ="da")
- public void testSelectDuplicateBindingsThrowsException()
+ public void testDuplicateBindingsThrowsException()
{
Bean<ObtainsInjectionPointBean> injectionPointBean =
getBeans(ObtainsInjectionPointBean.class).iterator().next();
ObtainsInjectionPointBean injectionPoint = (ObtainsInjectionPointBean)
getCurrentManager().getReference(injectionPointBean,ObtainsInjectionPointBean.class,
getCurrentManager().createCreationalContext(injectionPointBean));
- injectionPoint.getPaymentProcessor().select(new PayByBinding() { public
PaymentMethod value() { return CHEQUE; }});
+ injectionPoint.getPaymentProcessor().select(new SynchronousBinding(), new
SynchronousBinding());
}
@Test(groups = "ri-broken", expectedExceptions =
IllegalArgumentException.class)
@SpecAssertion(section = "5.7.1", id = "e")
- public void testSelectNonBindingThrowsException()
+ public void testNonBindingThrowsException()
{
Bean<ObtainsInjectionPointBean> injectionPointBean =
getBeans(ObtainsInjectionPointBean.class).iterator().next();
ObtainsInjectionPointBean injectionPoint = (ObtainsInjectionPointBean)
getCurrentManager().getReference(injectionPointBean,ObtainsInjectionPointBean.class,
getCurrentManager().createCreationalContext(injectionPointBean));
- injectionPoint.getPaymentProcessor().select(new NonBinding() );
+ injectionPoint.getPaymentProcessor().select(new NonBinding());
}
+ @Test(groups = "ri-broken", expectedExceptions =
UnsatisfiedResolutionException.class)
+ @SpecAssertions({
+ @SpecAssertion(section = "5.7.1", id = "fb"),
+ @SpecAssertion(section = "5.7.1", id = "l")})
+ public void testUnsatisfiedDependencyThrowsException()
+ {
+ ObtainsInjectionPointBean injectionPoint =
getInstanceByType(ObtainsInjectionPointBean.class);
+ assert !injectionPoint.getPaymentProcessor().isUnsatisfied();
+
+ Instance<PaymentProcessor> instance =
injectionPoint.getPaymentProcessor().select(new AsynchronousBinding());
+ assert instance.isUnsatisfied();
+
+ instance.get();
+ }
+
+ @Test(expectedExceptions = AmbiguousResolutionException.class)
+ @SpecAssertion(section = "5.7.1", id = "fb")
+ public void testAmbiguousDependencyThrowsException()
+ {
+ ObtainsInjectionPointBean injectionPoint =
getInstanceByType(ObtainsInjectionPointBean.class);
+ injectionPoint.getPaymentProcessor().get();
+ }
+
+ @Test(groups= "ri-broken")
+ @SpecAssertion(section = "5.7.1", id = "m")
+ public void testIsAmbiguous()
+ {
+ ObtainsInjectionPointBean injectionPoint =
getInstanceByType(ObtainsInjectionPointBean.class);
+ assert injectionPoint.getPaymentProcessor().isAmbiguous();
+ Instance<PaymentProcessor> instance =
injectionPoint.getPaymentProcessor().select(new SynchronousBinding());
+ assert !instance.isAmbiguous();
+ }
}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SimplePaymentProcessor.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SimplePaymentProcessor.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SimplePaymentProcessor.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,11 @@
+package org.jboss.jsr299.tck.tests.lookup.dynamic;
+
+class SimplePaymentProcessor implements PaymentProcessor
+{
+
+ public void process()
+ {
+
+ }
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Synchronous.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Synchronous.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/Synchronous.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,19 @@
+package org.jboss.jsr299.tck.tests.lookup.dynamic;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.inject.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+@interface Synchronous {
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SynchronousBinding.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SynchronousBinding.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SynchronousBinding.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,7 @@
+package org.jboss.jsr299.tck.tests.lookup.dynamic;
+
+import javax.enterprise.inject.AnnotationLiteral;
+
+public class SynchronousBinding extends AnnotationLiteral<Synchronous> implements
Synchronous{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SynchronousChequePaymentProcessor.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SynchronousChequePaymentProcessor.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/SynchronousChequePaymentProcessor.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,12 @@
+package org.jboss.jsr299.tck.tests.lookup.dynamic;
+
+import static org.jboss.jsr299.tck.tests.lookup.dynamic.PayBy.PaymentMethod.CHEQUE;
+
+@PayBy(CHEQUE) @Synchronous
+class SynchronousChequePaymentProcessor implements PaymentProcessor
+{
+ public void process()
+ {
+
+ }
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/AbstractAnimal.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/AbstractAnimal.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/AbstractAnimal.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,22 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.jsr299.tck.tests.lookup.dynamic.builtin;
+
+abstract class AbstractAnimal implements Animal
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Animal.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Animal.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Animal.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,22 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.jsr299.tck.tests.lookup.dynamic.builtin;
+
+interface Animal
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/BuiltinInstanceTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/BuiltinInstanceTest.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/BuiltinInstanceTest.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.jsr299.tck.tests.lookup.dynamic.builtin;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.TypeLiteral;
+import javax.enterprise.inject.spi.Bean;
+
+import org.hibernate.tck.annotations.SpecAssertion;
+import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for built-in Instance.
+ *
+ * Spec version: 2009625
+ */
+
+@Artifact
+public class BuiltinInstanceTest extends AbstractJSR299Test {
+
+ @Test
+ @SpecAssertion(section = "5.7.2", id = "d")
+ public void testScopeOfBuiltinInstance() {
+ Bean<Instance<Cow>> bean = getBeans(new
TypeLiteral<Instance<Cow>>() {}).iterator().next();
+ assert Dependent.class.equals(bean.getScopeType());
+ }
+
+ @Test
+ @SpecAssertion(section = "5.7.2", id = "e")
+ public void testNameOfBuiltinInstance() {
+ Bean<Instance<Cow>> bean = getBeans(new
TypeLiteral<Instance<Cow>>() {}).iterator().next();
+ assert bean.getName() == null;
+ }
+
+ @Test
+ @SpecAssertion(section = "5.7.2", id = "a")
+ public void testInstanceProvidedForEveryLegalBeanType() {
+ Farm farm = getInstanceByType(Farm.class);
+ assert farm.getAnimal() != null;
+ assert farm.getAbstractAnimal() != null;
+ assert farm.getCow() != null;
+ }
+
+ @Test
+ @SpecAssertion(section = "5.7.2", id = "g")
+ public void testInstanceIsPassivationCapable() {
+ Bean<Instance> instance = getBeans(Instance.class).iterator().next();
+ // TODO assert instance.isSerializable();
+ }
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Cow.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Cow.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Cow.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,22 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.jsr299.tck.tests.lookup.dynamic.builtin;
+
+class Cow extends AbstractAnimal
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Farm.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Farm.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dynamic/builtin/Farm.java 2009-07-21
08:04:41 UTC (rev 3104)
@@ -0,0 +1,30 @@
+package org.jboss.jsr299.tck.tests.lookup.dynamic.builtin;
+
+import javax.enterprise.inject.Current;
+import javax.enterprise.inject.Instance;
+
+class Farm extends AbstractAnimal
+{
+ @Current
+ private Instance<Animal> animal;
+ @Current
+ private Instance<AbstractAnimal> abstractAnimal;
+ @Current
+ private Instance<Cow> cow;
+
+ public Instance<Animal> getAnimal()
+ {
+ return animal;
+ }
+
+ public Instance<AbstractAnimal> getAbstractAnimal()
+ {
+ return abstractAnimal;
+ }
+
+ public Instance<Cow> getCow()
+ {
+ return cow;
+ }
+
+}