Author: jharting
Date: 2009-10-14 05:44:19 -0400 (Wed, 14 Oct 2009)
New Revision: 4031
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Bread.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Cheap.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/CheapLiteral.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Expensive.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ExpensiveLiteral.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Fruit.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Grocery.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryAnnotatedType.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryInterceptor.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryInterceptorBinding.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Milk.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/NamedStereotype.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Shop.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotated.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedConstructor.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedField.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedMethod.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedParameter.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TropicalFruit.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Vegetables.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Water.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Yogurt.java
cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/annotated/beans.xml
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeObserver.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeTest.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedType.java
Log:
CDITCK-4 Tests for section 11.4
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Bread.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Bread.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Bread.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,11 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+class Bread
+{
+ @SuppressWarnings("unused")
+ private boolean fresh;
+
+ public Bread(boolean fresh) {
+ this.fresh = fresh;
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Cheap.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Cheap.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Cheap.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,22 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import static java.lang.annotation.ElementType.FIELD;
+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.inject.Qualifier;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@Qualifier
+@interface Cheap
+{
+
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/CheapLiteral.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/CheapLiteral.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/CheapLiteral.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,7 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import javax.enterprise.inject.AnnotationLiteral;
+
+class CheapLiteral extends AnnotationLiteral<Cheap> implements Cheap
+{
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Expensive.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Expensive.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Expensive.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,22 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import static java.lang.annotation.ElementType.FIELD;
+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.inject.Qualifier;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@Qualifier
+@interface Expensive
+{
+
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ExpensiveLiteral.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ExpensiveLiteral.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ExpensiveLiteral.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,7 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import javax.enterprise.inject.AnnotationLiteral;
+
+class ExpensiveLiteral extends AnnotationLiteral<Expensive> implements Expensive
+{
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Fruit.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Fruit.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Fruit.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,8 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+
+interface Fruit
+{
+ InjectionPoint getMetadata();
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Grocery.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Grocery.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Grocery.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,79 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+@SuppressWarnings( "unused" )
+@ApplicationScoped
+@Expensive
+class Grocery implements Shop
+{
+ private Vegetables vegetables = null;
+ private Fruit fruit;
+ private boolean constructorWithParameterUsed = false;
+ private TropicalFruit initializerFruit = null;
+ private Bread bread = new Bread(true);
+ private Water water = null;
+
+ public Grocery()
+ {
+ }
+
+ public Grocery(@Any TropicalFruit fruit) {
+ constructorWithParameterUsed = true;
+ }
+
+ public void nonInjectAnnotatedInitializer(@Any Water water) {
+ this.water = water;
+ }
+
+ @Inject
+ public void initializer(@Any TropicalFruit fruit) {
+ this.initializerFruit = fruit;
+ }
+
+ public String foo()
+ {
+ return "bar";
+ }
+
+ public boolean isVegetablesInjected()
+ {
+ return vegetables != null;
+ }
+
+ public Fruit getFruit()
+ {
+ return fruit;
+ }
+
+ public boolean isConstructorWithParameterUsed()
+ {
+ return constructorWithParameterUsed;
+ }
+
+ public TropicalFruit getInitializerFruit()
+ {
+ return initializerFruit;
+ }
+
+ public Milk getMilk()
+ {
+ return new Milk(true);
+ }
+
+ @Produces @Cheap
+ public Yogurt getYogurt(@Any TropicalFruit fruit)
+ {
+ return new Yogurt(fruit);
+ }
+
+ public boolean isWaterInjected() {
+ return water != null;
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryAnnotatedType.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryAnnotatedType.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryAnnotatedType.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,181 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.AnnotationLiteral;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+import org.jboss.jsr299.tck.literals.InjectLiteral;
+
+public class GroceryAnnotatedType<X> extends TestAnnotatedType<X>
+{
+ private final Set<Type> typeClosure = new HashSet<Type>();
+ private static boolean getBaseTypeOfFruitFieldUsed = false;
+ private static boolean getTypeClosureUsed = false;
+
+ public GroceryAnnotatedType(AnnotatedType<X> delegate)
+ {
+ super(delegate, new AnnotationLiteral<RequestScoped>()
+ {
+ }, new CheapLiteral(), new AnnotationLiteral<NamedStereotype>()
+ {
+ }, new AnnotationLiteral<GroceryInterceptorBinding>()
+ {
+ });
+ typeClosure.add(Grocery.class);
+ typeClosure.add(Object.class);
+ }
+
+ @Override
+ public Set<Type> getTypeClosure()
+ {
+ getTypeClosureUsed = true;
+ return typeClosure;
+ }
+
+ @Override
+ public Set<AnnotatedConstructor<X>> getConstructors()
+ {
+ Set<AnnotatedConstructor<X>> constructors = new
HashSet<AnnotatedConstructor<X>>();
+ for (AnnotatedConstructor<X> constructor : super.getConstructors())
+ {
+ if (constructor.getParameters().size() == 1)
+ {
+ constructors.add(wrapConstructor(constructor, new InjectLiteral()));
+ }
+ else
+ {
+ constructors.add(constructor);
+ }
+ }
+ return constructors;
+ }
+
+ @Override
+ public Set<AnnotatedField<? super X>> getFields()
+ {
+ Set<AnnotatedField<? super X>> fields = new
HashSet<AnnotatedField<? super X>>();
+ for (AnnotatedField<? super X> field : super.getFields())
+ {
+ if (field.getBaseType().equals(Vegetables.class))
+ {
+ fields.add(wrapField(field, new InjectLiteral()));
+ }
+ else if (field.getJavaMember().getName().equals("fruit"))
+ {
+ fields.add(wrapFruitField(field, new CheapLiteral(), new InjectLiteral()));
+ }
+ else if (field.getBaseType().equals(Bread.class))
+ {
+ fields.add(wrapField(field, new AnnotationLiteral<Produces>()
+ {
+ }));
+ }
+ else
+ {
+ fields.add(field);
+ }
+ }
+ return fields;
+ }
+
+ @Override
+ public Set<AnnotatedMethod<? super X>> getMethods()
+ {
+ Set<AnnotatedMethod<? super X>> methods = new
HashSet<AnnotatedMethod<? super X>>();
+ for (AnnotatedMethod<? super X> method : super.getMethods())
+ {
+ if (method.getJavaMember().getName().equals("getMilk"))
+ {
+ methods.add(wrapMethod(method, new AnnotationLiteral<Produces>()
+ {
+ }));
+ }
+ else if (method.getJavaMember().getName().equals("getYogurt"))
+ {
+ methods.add(wrapMethodAndAnnotateEveryParameterWithCheap(method, new
ExpensiveLiteral(), new AnnotationLiteral<Produces>()
+ {
+ }));
+ }
+ else if
(method.getJavaMember().getName().equals("nonInjectAnnotatedInitializer"))
+ {
+ methods.add(wrapMethod(method, new InjectLiteral()));
+ }
+ else if (method.getJavaMember().getName().equals("initializer"))
+ {
+ methods.add(wrapMethodAndAnnotateEveryParameterWithCheap(method, new
InjectLiteral()));
+ }
+ else
+ {
+ methods.add(method);
+ }
+ }
+ return methods;
+ }
+
+ private <Y> AnnotatedConstructor<Y>
wrapConstructor(AnnotatedConstructor<Y> delegate, Annotation... annotations)
+ {
+ return new TestAnnotatedConstructor<Y>(delegate, annotations);
+ }
+
+ private <Y> AnnotatedField<Y> wrapField(AnnotatedField<Y> delegate,
Annotation... annotations)
+ {
+ return new TestAnnotatedField<Y>(delegate, annotations);
+ }
+
+ private <Y> AnnotatedField<Y> wrapFruitField(AnnotatedField<Y>
delegate, Annotation... annotations)
+ {
+ return new TestAnnotatedField<Y>(delegate, annotations){
+ @Override
+ public Type getBaseType()
+ {
+ getBaseTypeOfFruitFieldUsed = true;
+ return TropicalFruit.class;
+ }
+ };
+ }
+
+ private <Y> TestAnnotatedMethod<Y> wrapMethod(AnnotatedMethod<Y>
delegate, Annotation... annotations)
+ {
+ return new TestAnnotatedMethod<Y>(delegate, annotations);
+ }
+
+ private <Y> TestAnnotatedMethod<Y>
wrapMethodAndAnnotateEveryParameterWithCheap(AnnotatedMethod<Y> delegate,
Annotation... annotations)
+ {
+ return new TestAnnotatedMethod<Y>(delegate, annotations)
+ {
+ @Override
+ public List<AnnotatedParameter<Y>> getParameters()
+ {
+ List<AnnotatedParameter<Y>> parameters = new
ArrayList<AnnotatedParameter<Y>>();
+ for (AnnotatedParameter<Y> parameter : super.getParameters())
+ {
+ parameters.add(new TestAnnotatedParameter<Y>(parameter, new
CheapLiteral()));
+ }
+ return parameters;
+ }
+
+ };
+ }
+
+ public static boolean isGetBaseTypeOfFruitFieldUsed()
+ {
+ return getBaseTypeOfFruitFieldUsed;
+ }
+
+ public static boolean isGetTypeClosureUsed()
+ {
+ return getTypeClosureUsed;
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryInterceptor.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryInterceptor.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryInterceptor.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,23 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+@Interceptor
+@GroceryInterceptorBinding
+class GroceryInterceptor
+{
+ @AroundInvoke
+ public Object interceptFoo(InvocationContext ctx) throws Exception
+ {
+ if (ctx.getMethod().getName().equals("foo"))
+ {
+ return "foo";
+ }
+ else
+ {
+ return ctx.proceed();
+ }
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryInterceptorBinding.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryInterceptorBinding.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/GroceryInterceptorBinding.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,17 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import javax.interceptor.InterceptorBinding;
+
+@InterceptorBinding
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+@interface GroceryInterceptorBinding
+{
+
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Milk.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Milk.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Milk.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,12 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+class Milk
+{
+ @SuppressWarnings("unused")
+ private boolean fresh;
+
+ public Milk(boolean fresh)
+ {
+ this.fresh = fresh;
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/NamedStereotype.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/NamedStereotype.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/NamedStereotype.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,19 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.inject.stereotype.Stereotype;
+import javax.inject.Named;
+
+@Target(TYPE)
+@Retention(RUNTIME)
+@Stereotype
+@Named
+@interface NamedStereotype
+{
+
+}
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeObserver.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeObserver.java 2009-10-14
08:20:21 UTC (rev 4030)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeObserver.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -38,13 +38,22 @@
{
wrapAnnotatedType(event);
}
+ else if (event.getAnnotatedType().getJavaClass().equals(Grocery.class))
+ {
+ wrapGroceryAnnotatedType(event);
+ }
}
private <X> void wrapAnnotatedType(ProcessAnnotatedType<X> event)
{
event.setAnnotatedType(new TestAnnotatedType<X>(event.getAnnotatedType()));
}
-
+
+ private <X> void wrapGroceryAnnotatedType(ProcessAnnotatedType<X> event)
+ {
+ event.setAnnotatedType(new
GroceryAnnotatedType<X>(event.getAnnotatedType()));
+ }
+
public static HashSet<Class<?>> getAnnotatedclasses()
{
return annotatedClasses;
@@ -54,5 +63,4 @@
{
return dogAnnotatedType;
}
-
}
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeTest.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeTest.java 2009-10-14
08:20:21 UTC (rev 4030)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/ProcessAnnotatedTypeTest.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -17,7 +17,13 @@
package org.jboss.jsr299.tck.tests.extensions.annotated;
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import javax.enterprise.context.RequestScoped;
+
import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.jsr299.tck.literals.AnyLiteral;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecAssertions;
import org.jboss.test.audit.annotations.SpecVersion;
@@ -25,15 +31,19 @@
import org.jboss.testharness.impl.packaging.IntegrationTest;
import org.jboss.testharness.impl.packaging.Resource;
import org.jboss.testharness.impl.packaging.Resources;
+import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
import org.testng.annotations.Test;
+
/**
* Tests for the extensions provided by the ProcessAnnotatedType events.
*
* @author David Allen
+ * @author Jozef Hartinger
*
*/
@Artifact
+(a)BeansXml("beans.xml")
@Resources({
@Resource(source="javax.enterprise.inject.spi.Extension",
destination="WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension")
})
@@ -41,6 +51,7 @@
@SpecVersion(spec="cdi", version="PFD2")
public class ProcessAnnotatedTypeTest extends AbstractJSR299Test
{
+
@Test
@SpecAssertions({
@SpecAssertion(section = "11.5.5", id = "a"),
@@ -82,4 +93,118 @@
{
assert getCurrentManager().getBeans(VetoedBean.class).isEmpty();
}
+
+ @Test(groups = "ri-broken")
+ @SpecAssertion(section = "11.4", id = "h")
+ // WELD-200
+ public void testGetBaseTypeUsedToDetermineTypeOfInjectionPoing() {
+ // The base type of the fruit injection point is overridden to TropicalFruit
+ assert GroceryAnnotatedType.isGetBaseTypeOfFruitFieldUsed();
+ assert getInstanceByType(Grocery.class, new
AnyLiteral()).getFruit().getMetadata().getType().equals(TropicalFruit.class);
+ }
+
+ @Test(groups = "ri-broken")
+ @SpecAssertion(section = "11.4", id = "k")
+ // WELD-201
+ public void testGetTypeClosureUsed() {
+ assert GroceryAnnotatedType.isGetTypeClosureUsed();
+ // should be [Object, Grocery] instead of [Object, Shop, Grocery]
+ assert getBeans(Grocery.class, new
AnyLiteral()).iterator().next().getTypes().size() == 2;
+ assert getBeans(Shop.class, new AnyLiteral()).size() == 0;
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "l")
+ public void testGetAnnotationUsedForGettingScopeInformation() {
+ // @ApplicationScoped is overridden by @RequestScoped
+ assert getBeans(Grocery.class, new
AnyLiteral()).iterator().next().getScope().isAssignableFrom(RequestScoped.class);
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "m")
+ public void testGetAnnotationUsedForGettingQualifierInformation() {
+ // @Expensive is overridden by @Cheap
+ assert getBeans(Grocery.class, new CheapLiteral()).size() == 1;
+ assert getBeans(Grocery.class, new ExpensiveLiteral()).size() == 0;
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "n")
+ public void testGetAnnotationUsedForGettingStereotypeInformation() {
+ // The extension adds a stereotype with @Named qualifier
+ assert getInstanceByName("grocery") != null;
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "p")
+ public void testGetAnnotationUsedForGettingInterceptorInformation() {
+ // The extension adds the GroceryInterceptorBinding
+ assert getInstanceByType(Grocery.class, new
AnyLiteral()).foo().equals("foo");
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "r")
+ public void testPreviouslyNonInjectAnnotatedConstructorIsUsed() {
+ assert getInstanceByType(Grocery.class, new
AnyLiteral()).isConstructorWithParameterUsed();
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "t")
+ public void testPreviouslyNonInjectAnnotatedFieldIsInjected() {
+ assert getInstanceByType(Grocery.class, new AnyLiteral()).isVegetablesInjected();
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "u")
+ public void testExtraQualifierIsAppliedToInjectedField() {
+ Set<Annotation> qualifiers = getInstanceByType(Grocery.class, new
AnyLiteral()).getFruit().getMetadata().getQualifiers();
+ assert qualifiers.size() == 1;
+ assert annotationSetMatches(qualifiers, Cheap.class);
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "v")
+ public void testProducesCreatesProducerField() {
+ // The extension adds @Producer to the bread field
+ assert getBeans(Bread.class, new AnyLiteral()).size() == 1;
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "w")
+ public void testInjectCreatesInitializerMethod() {
+ // The extension adds @Inject to the nonInjectAnnotatedInitializer() method
+ assert getInstanceByType(Grocery.class, new AnyLiteral()).isWaterInjected();
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "x")
+ public void testQualifierAddedToInitializerParameter() {
+ // The @Cheap qualifier is added to the method parameter
+ Set<Annotation> qualifiers = getInstanceByType(Grocery.class, new
AnyLiteral()).getInitializerFruit().getMetadata().getQualifiers();
+ assert annotationSetMatches(qualifiers, Cheap.class);
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "y")
+ public void testProducesCreatesProducerMethod() {
+ // The extension adds @Producer to the getMilk() method
+ assert getBeans(Milk.class, new AnyLiteral()).size() == 1;
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "z")
+ public void testQualifierIsAppliedToProducerMethod() {
+ // The extension adds @Expensive to the getMilk() method
+ assert getBeans(Yogurt.class, new ExpensiveLiteral()).size() == 1;
+ assert getBeans(Yogurt.class, new CheapLiteral()).size() == 0;
+ }
+
+ @Test
+ @SpecAssertion(section = "11.4", id = "aa")
+ public void testQualifierIsAppliedToProducerMethodParameter() {
+ // The @Cheap qualifier is added to the method parameter
+ Set<Annotation> qualifiers = getInstanceByType(Yogurt.class, new
AnyLiteral()).getFruit().getMetadata().getQualifiers();
+ assert qualifiers.size() == 1;
+ assert annotationSetMatches(qualifiers, Cheap.class);
+ }
}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Shop.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Shop.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Shop.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+interface Shop
+{
+
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotated.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotated.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotated.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,59 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+
+class TestAnnotated implements Annotated
+{
+
+ private Annotated delegate;
+ private Set<Annotation> annotations;
+
+ public TestAnnotated(Annotated delegate, Annotation... annotations)
+ {
+ this.delegate = delegate;
+ this.annotations = new HashSet<Annotation>(Arrays.asList(annotations));
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Annotation> T getAnnotation(Class<T> arg0)
+ {
+ for (Annotation annotation : annotations) {
+ if (arg0.isAssignableFrom(annotation.annotationType())) {
+ return (T) annotation;
+ }
+ }
+ return null;
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ return Collections.unmodifiableSet(annotations);
+ }
+
+ public Type getBaseType()
+ {
+ return delegate.getBaseType();
+ }
+
+ public Set<Type> getTypeClosure()
+ {
+ return delegate.getTypeClosure();
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> arg0)
+ {
+ for (Annotation annotation : annotations) {
+ if (arg0.isAssignableFrom(annotation.annotationType())) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedConstructor.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedConstructor.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedConstructor.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,41 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+class TestAnnotatedConstructor<X> extends TestAnnotated implements
AnnotatedConstructor<X>
+{
+
+ private AnnotatedConstructor<X> delegate;
+
+ public TestAnnotatedConstructor(AnnotatedConstructor<X> delegate, Annotation...
annotations)
+ {
+ super(delegate, annotations);
+ this.delegate = delegate;
+ }
+
+ public Constructor<X> getJavaMember()
+ {
+ return delegate.getJavaMember();
+ }
+
+ public List<AnnotatedParameter<X>> getParameters()
+ {
+ return delegate.getParameters();
+ }
+
+ public AnnotatedType<X> getDeclaringType()
+ {
+ return delegate.getDeclaringType();
+ }
+
+ public boolean isStatic()
+ {
+ return delegate.isStatic();
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedField.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedField.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedField.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,34 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+class TestAnnotatedField<X> extends TestAnnotated implements
AnnotatedField<X>
+{
+
+ private AnnotatedField<X> delegate;
+
+ public TestAnnotatedField(AnnotatedField<X> delegate, Annotation...
annotations)
+ {
+ super(delegate, annotations);
+ this.delegate = delegate;
+ }
+
+ public Field getJavaMember()
+ {
+ return delegate.getJavaMember();
+ }
+
+ public AnnotatedType<X> getDeclaringType()
+ {
+ return delegate.getDeclaringType();
+ }
+
+ public boolean isStatic()
+ {
+ return delegate.isStatic();
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedMethod.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedMethod.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedMethod.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,52 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+class TestAnnotatedMethod<X> extends TestAnnotated implements
AnnotatedMethod<X>
+{
+
+ private AnnotatedMethod<X> delegate;
+
+ public TestAnnotatedMethod(AnnotatedMethod<X> delegate, Annotation...
annotations)
+ {
+ super(delegate, annotations);
+ this.delegate = delegate;
+ }
+
+ public Method getJavaMember()
+ {
+ return delegate.getJavaMember();
+ }
+
+ public List<AnnotatedParameter<X>> getParameters()
+ {
+ return delegate.getParameters();
+ }
+
+ public AnnotatedType<X> getDeclaringType()
+ {
+ return delegate.getDeclaringType();
+ }
+
+ public boolean isStatic()
+ {
+ return delegate.isStatic();
+ }
+
+ @Override
+ public Set<Annotation> getAnnotations()
+ {
+ // TODO Auto-generated method stub
+ return super.getAnnotations();
+ }
+
+
+
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedParameter.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedParameter.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedParameter.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,28 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import java.lang.annotation.Annotation;
+
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+
+class TestAnnotatedParameter<X> extends TestAnnotated implements
AnnotatedParameter<X>
+{
+ private AnnotatedParameter<X> delegate;
+
+ public TestAnnotatedParameter(AnnotatedParameter<X> delegate, Annotation...
annotations)
+ {
+ super(delegate, annotations);
+ this.delegate = delegate;
+ }
+
+ public AnnotatedCallable<X> getDeclaringCallable()
+ {
+ return delegate.getDeclaringCallable();
+ }
+
+ public int getPosition()
+ {
+ return delegate.getPosition();
+ }
+
+}
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedType.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedType.java 2009-10-14
08:20:21 UTC (rev 4030)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TestAnnotatedType.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -1,7 +1,6 @@
package org.jboss.jsr299.tck.tests.extensions.annotated;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
import java.util.Set;
import javax.enterprise.inject.spi.AnnotatedConstructor;
@@ -9,15 +8,16 @@
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
-public class TestAnnotatedType<X> implements AnnotatedType<X>
+public class TestAnnotatedType<X> extends TestAnnotated implements
AnnotatedType<X>
{
private AnnotatedType<X> delegate;
private static boolean getConstructorsUsed = false;
private static boolean getFieldsUsed = false;
private static boolean getMethodsUsed = false;
- public TestAnnotatedType(AnnotatedType<X> delegate)
+ public TestAnnotatedType(AnnotatedType<X> delegate, Annotation...annotations)
{
+ super(delegate, annotations);
this.delegate = delegate;
}
@@ -44,31 +44,6 @@
return delegate.getMethods();
}
- public <T extends Annotation> T getAnnotation(Class<T> annotationType)
- {
- return delegate.getAnnotation(annotationType);
- }
-
- public Set<Annotation> getAnnotations()
- {
- return delegate.getAnnotations();
- }
-
- public Type getBaseType()
- {
- return delegate.getBaseType();
- }
-
- public Set<Type> getTypeClosure()
- {
- return delegate.getTypeClosure();
- }
-
- public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
- {
- return delegate.isAnnotationPresent(annotationType);
- }
-
public static boolean isGetConstructorsUsed()
{
return getConstructorsUsed;
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TropicalFruit.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TropicalFruit.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/TropicalFruit.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,16 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+
+@Cheap
+class TropicalFruit implements Fruit
+{
+ @Inject
+ private InjectionPoint metadata;
+
+ public InjectionPoint getMetadata()
+ {
+ return metadata;
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Vegetables.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Vegetables.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Vegetables.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+class Vegetables
+{
+
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Water.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Water.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Water.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,7 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+@Cheap
+class Water
+{
+
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Yogurt.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Yogurt.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/annotated/Yogurt.java 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,15 @@
+package org.jboss.jsr299.tck.tests.extensions.annotated;
+
+class Yogurt
+{
+ private TropicalFruit fruit;
+
+ public Yogurt(TropicalFruit fruit) {
+ this.fruit = fruit;
+ }
+
+ public TropicalFruit getFruit()
+ {
+ return fruit;
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/annotated/beans.xml
===================================================================
---
cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/annotated/beans.xml
(rev 0)
+++
cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/extensions/annotated/beans.xml 2009-10-14
09:44:19 UTC (rev 4031)
@@ -0,0 +1,5 @@
+<beans>
+ <interceptors>
+ <class>org.jboss.jsr299.tck.tests.extensions.annotated.GroceryInterceptor</class>
+ </interceptors>
+</beans>