[webbeans-commits] Webbeans SVN: r3394 - tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition and 2 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Aug 3 07:19:53 EDT 2009
Author: dallen6
Date: 2009-08-03 07:19:53 -0400 (Mon, 03 Aug 2009)
New Revision: 3394
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/NonMeta.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/Dog.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/DogHouse.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/InjectionPointDecorator.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/Terrier.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/DecoratorDefinitionTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/FooDecorator.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/BeanManagerTest.java
tck/trunk/impl/src/main/resources/tck-audit.xml
Log:
New TCK tests for ch. 11 and some fixes to resolveDecorators() to properly check arguments.
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-08-03 08:43:00 UTC (rev 3393)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-08-03 11:19:53 UTC (rev 3394)
@@ -529,21 +529,11 @@
@SuppressWarnings("unchecked")
public <T> Set<ObserverMethod<?, T>> resolveObserverMethods(T event, Annotation... bindings)
{
+ checkBindingTypes(Arrays.asList(bindings));
Class<?> clazz = event.getClass();
- for (Annotation annotation : bindings)
- {
- if (!getServices().get(MetaAnnotationStore.class).getBindingTypeModel(annotation.annotationType()).isValid())
- {
- throw new IllegalArgumentException("Not a binding type " + annotation);
- }
- }
- HashSet<Annotation> bindingAnnotations = new HashSet<Annotation>(Arrays.asList(bindings));
- if (bindingAnnotations.size() < bindings.length)
- {
- throw new IllegalArgumentException("Duplicate binding types: " + bindings);
- }
// Manually hack in the default annotations here. We need to redo all the annotation defaulting throughout. PLM
+ HashSet<Annotation> bindingAnnotations = new HashSet<Annotation>(Arrays.asList(bindings));
if (bindingAnnotations.size() == 0)
{
bindingAnnotations.add(new CurrentLiteral());
@@ -559,6 +549,23 @@
return observers;
}
+ private void checkBindingTypes(Collection<Annotation> bindings)
+ {
+ HashSet<Annotation> bindingAnnotations = new HashSet<Annotation>(bindings);
+ for (Annotation annotation : bindings)
+ {
+ if (!getServices().get(MetaAnnotationStore.class).getBindingTypeModel(annotation.annotationType()).isValid())
+ {
+ throw new IllegalArgumentException("Not a binding type " + annotation);
+ }
+ }
+ if (bindingAnnotations.size() < bindings.size())
+ {
+ throw new IllegalArgumentException("Duplicate binding types: " + bindings);
+ }
+
+ }
+
private void checkEventType(Type eventType)
{
Type[] types;
@@ -971,16 +978,27 @@
*/
public List<Decorator<?>> resolveDecorators(Set<Type> types, Annotation... bindings)
{
+ checkResolveDecoratorsArguments(types, Arrays.asList(bindings));
// TODO Fix this cast and make the resolver return a list
- return new ArrayList(decoratorResolver.resolve(ResolvableFactory.of(types, bindings)));
+ return new ArrayList<Decorator<?>>(decoratorResolver.resolve(ResolvableFactory.of(types, bindings)));
}
public List<Decorator<?>> resolveDecorators(Set<Type> types, Set<Annotation> bindings)
{
+ checkResolveDecoratorsArguments(types, bindings);
// TODO Fix this cast and make the resolver return a list
- return new ArrayList(decoratorResolver.resolve(ResolvableFactory.of(types, bindings)));
+ return new ArrayList<Decorator<?>>(decoratorResolver.resolve(ResolvableFactory.of(types, bindings)));
}
+ private void checkResolveDecoratorsArguments(Set<Type> types, Collection<Annotation> bindings)
+ {
+ if (types.isEmpty())
+ {
+ throw new IllegalArgumentException("No decorator types were specified in the set");
+ }
+ checkBindingTypes(bindings);
+ }
+
/**
* Resolves a list of interceptors based on interception type and interceptor
* bindings
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/DecoratorDefinitionTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/DecoratorDefinitionTest.java 2009-08-03 08:43:00 UTC (rev 3393)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/DecoratorDefinitionTest.java 2009-08-03 11:19:53 UTC (rev 3394)
@@ -17,9 +17,13 @@
package org.jboss.jsr299.tck.tests.decorators.definition;
import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
import java.util.List;
import javax.decorator.Decorates;
+import javax.enterprise.inject.AnnotationLiteral;
import javax.enterprise.inject.Current;
import javax.enterprise.inject.spi.Decorator;
@@ -70,7 +74,9 @@
({
@SpecAssertion(section="8.1", id="b"),
@SpecAssertion(section="8.1", id="c"),
- @SpecAssertion(section="11.1.1", id="b")
+ @SpecAssertion(section="11.1.1", id="b"),
+ @SpecAssertion(section="11.3.12", id="a"),
+ @SpecAssertion(section="11.3.12", id="b")
})
public void testDecoratedTypes()
{
@@ -115,7 +121,8 @@
@Test
@SpecAssertions({
@SpecAssertion(section="8.2", id="b"),
- @SpecAssertion(section="8.3", id="aa")
+ @SpecAssertion(section="8.3", id="aa"),
+ @SpecAssertion(section="11.3.12", id="a")
})
public void testDecoratorOrdering()
{
@@ -123,7 +130,6 @@
assert decorators.size() == 2;
assert decorators.get(0).getTypes().contains(BazDecorator.class);
assert decorators.get(1).getTypes().contains(BazDecorator1.class);
-
}
@Test
@@ -145,5 +151,27 @@
assert getCurrentManager().resolveDecorators(Field.TYPES).isEmpty();
}
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ @SpecAssertion(section="11.3.12", id="c")
+ public void testDuplicateBindingsOnResolveDecoratorsFails()
+ {
+ Annotation binding = new AnnotationLiteral<Meta>() {};
+ getCurrentManager().resolveDecorators(FooBar.TYPES, binding, binding);
+ }
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ @SpecAssertion(section="11.3.12", id="d")
+ public void testNonBindingsOnResolveDecoratorsFails()
+ {
+ Annotation binding = new AnnotationLiteral<NonMeta>() {};
+ getCurrentManager().resolveDecorators(FooBar.TYPES, binding);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ @SpecAssertion(section="11.3.12", id="e")
+ public void testEmptyTypeSetOnResolveDecoratorsFails()
+ {
+ Annotation binding = new AnnotationLiteral<NonMeta>() {};
+ getCurrentManager().resolveDecorators(new HashSet<Type>(), binding);
+ }
}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/FooDecorator.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/FooDecorator.java 2009-08-03 08:43:00 UTC (rev 3393)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/FooDecorator.java 2009-08-03 11:19:53 UTC (rev 3394)
@@ -24,6 +24,7 @@
*
*/
@Decorator
+ at Meta
public class FooDecorator extends AbstractFooDecorator implements Foo, Bar
{
Copied: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/NonMeta.java (from rev 3392, tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/Meta.java)
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/NonMeta.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/definition/NonMeta.java 2009-08-03 11:19:53 UTC (rev 3394)
@@ -0,0 +1,19 @@
+package org.jboss.jsr299.tck.tests.decorators.definition;
+
+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;
+
+ at Target( { TYPE, METHOD, PARAMETER, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+ at interface NonMeta
+{
+
+}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/BeanManagerTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/BeanManagerTest.java 2009-08-03 08:43:00 UTC (rev 3393)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/BeanManagerTest.java 2009-08-03 11:19:53 UTC (rev 3394)
@@ -20,11 +20,15 @@
import java.util.HashSet;
import java.util.Set;
+import javax.enterprise.inject.AmbiguousResolutionException;
+import javax.enterprise.inject.InjectionException;
import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.PassivationCapable;
import org.jboss.jsr299.tck.AbstractJSR299Test;
import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
import org.jboss.test.audit.annotations.SpecVersion;
import org.jboss.testharness.impl.packaging.Artifact;
import org.testng.annotations.Test;
@@ -61,4 +65,28 @@
beans.addAll(getCurrentManager().getBeans(DerivedBean.class));
getCurrentManager().resolve(beans);
}
+
+ @Test(expectedExceptions = AmbiguousResolutionException.class)
+ @SpecAssertion(section = "11.3.8", id = "b")
+ public void testAmbiguousDependencyNotResolved()
+ {
+ Set<Bean<?>> beans = new HashSet<Bean<?>>();
+ beans.addAll(getCurrentManager().getBeans(Dog.class));
+ beans.addAll(getCurrentManager().getBeans(Terrier.class));
+ getCurrentManager().resolve(beans);
+ }
+
+ @Test(groups = "ri-broken", expectedExceptions = InjectionException.class)
+ @SpecAssertions({
+ @SpecAssertion(section = "11.3.9", id = "a"),
+ @SpecAssertion(section = "11.3.9", id = "b")
+ })
+ //WBRI-333
+ public void testValidateThrowsException()
+ {
+ DogHouse dogHouse = getInstanceByType(DogHouse.class);
+ InjectionPoint injectionPoint = new InjectionPointDecorator(dogHouse.getDog().getInjectedMetadata());
+ // Wrap the injection point to change the type to a more generalized class
+ getCurrentManager().validate(injectionPoint);
+ }
}
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/Dog.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/Dog.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/Dog.java 2009-08-03 11:19:53 UTC (rev 3394)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.extensions.beanManager;
+
+class Dog
+{
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/Dog.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/DogHouse.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/DogHouse.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/DogHouse.java 2009-08-03 11:19:53 UTC (rev 3394)
@@ -0,0 +1,14 @@
+package org.jboss.jsr299.tck.tests.extensions.beanManager;
+
+import javax.enterprise.inject.Current;
+
+class DogHouse
+{
+ @Current
+ private Terrier dog;
+
+ public Terrier getDog()
+ {
+ return dog;
+ }
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/DogHouse.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/InjectionPointDecorator.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/InjectionPointDecorator.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/InjectionPointDecorator.java 2009-08-03 11:19:53 UTC (rev 3394)
@@ -0,0 +1,55 @@
+package org.jboss.jsr299.tck.tests.extensions.beanManager;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+class InjectionPointDecorator implements InjectionPoint
+{
+ private final InjectionPoint injectionPoint;
+
+ public InjectionPointDecorator(InjectionPoint injectionPoint)
+ {
+ this.injectionPoint = injectionPoint;
+ }
+
+ public Annotated getAnnotated()
+ {
+ return injectionPoint.getAnnotated();
+ }
+
+ public Bean<?> getBean()
+ {
+ return injectionPoint.getBean();
+ }
+
+ public Set<Annotation> getBindings()
+ {
+ return injectionPoint.getBindings();
+ }
+
+ public Member getMember()
+ {
+ return injectionPoint.getMember();
+ }
+
+ public Type getType()
+ {
+ return Dog.class;
+ }
+
+ public boolean isDelegate()
+ {
+ return injectionPoint.isDelegate();
+ }
+
+ public boolean isTransient()
+ {
+ return injectionPoint.isTransient();
+ }
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/InjectionPointDecorator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/Terrier.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/Terrier.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/Terrier.java 2009-08-03 11:19:53 UTC (rev 3394)
@@ -0,0 +1,15 @@
+package org.jboss.jsr299.tck.tests.extensions.beanManager;
+
+import javax.enterprise.inject.Current;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+class Terrier extends Dog
+{
+ @Current
+ private InjectionPoint injectedMetadata;
+
+ public InjectionPoint getInjectedMetadata()
+ {
+ return injectedMetadata;
+ }
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/Terrier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: tck/trunk/impl/src/main/resources/tck-audit.xml
===================================================================
--- tck/trunk/impl/src/main/resources/tck-audit.xml 2009-08-03 08:43:00 UTC (rev 3393)
+++ tck/trunk/impl/src/main/resources/tck-audit.xml 2009-08-03 11:19:53 UTC (rev 3394)
@@ -4412,8 +4412,9 @@
<section id="11.3.9" title="Validating a dependency">
<assertion id="a">
<text>The |BeanManager.validate()| operation validates a dependency.</text>
+ <note>Statement of intent</note>
</assertion>
-
+
<assertion id="b">
<text>The method |validate()| validates the dependency and throws an |InjectionException| if there is a deployment problem (for example, an unsatisfied or unresolvable ambiguous dependency) associated with the injection point.</text>
</assertion>
More information about the weld-commits
mailing list