Author: marius.bogoevici
Date: 2010-01-27 09:06:01 -0500 (Wed, 27 Jan 2010)
New Revision: 5639
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/BasicDecoratorResolutionTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/Complex.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/ComplexBean.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/ComplexDecorator.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/DecoratorResolutionTestsHelper.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/Simple.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SimpleBean.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SimpleDecorator.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SomeBean.java
core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/resolution/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/resolution/beans-basic.xml
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeDecoratorResolver.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/interceptor/InterceptorAndDecoratorTest.java
Log:
WELD-291
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java 2010-01-27
13:19:32 UTC (rev 5638)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -263,7 +263,7 @@
{
throw new DeploymentException(INJECTION_POINT_HAS_UNSATISFIED_DEPENDENCIES, ij,
Arrays.toString(bindings));
}
- if (resolvedBeans.size() > 1)
+ if (resolvedBeans.size() > 1 && !ij.isDelegate())
{
throw new DeploymentException(INJECTION_POINT_HAS_AMBIGUOUS_DEPENDENCIES, ij,
Arrays.toString(bindings) + "; Possible dependencies: " + resolvedBeans);
}
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeDecoratorResolver.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeDecoratorResolver.java 2010-01-27
13:19:32 UTC (rev 5638)
+++
core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeDecoratorResolver.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -43,7 +43,9 @@
@Override
protected boolean matches(Resolvable resolvable, Decorator<?> bean)
{
- return Reflections.matches(Collections.singleton(bean.getDelegateType()),
resolvable.getTypeClosure()) &&
Beans.containsAllBindings(bean.getDelegateQualifiers(), resolvable.getQualifiers(),
getBeanManager()) &&
getBeanManager().getEnabledDecoratorClasses().contains(bean.getBeanClass());
+ return Reflections.matches(Collections.singleton(bean.getDelegateType()),
resolvable.getTypeClosure())
+ && Beans.containsAllBindings(bean.getDelegateQualifiers(),
resolvable.getQualifiers(), getBeanManager())
+ &&
getBeanManager().getEnabledDecoratorClasses().contains(bean.getBeanClass());
}
@Override
Modified:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/interceptor/InterceptorAndDecoratorTest.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/interceptor/InterceptorAndDecoratorTest.java 2010-01-27
13:19:32 UTC (rev 5638)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/interceptor/InterceptorAndDecoratorTest.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -28,7 +28,7 @@
public class InterceptorAndDecoratorTest extends AbstractWeldTest
{
- @Test(description="WELD-314", groups = "broken")
+ @Test(description="WELD-314")
public void test()
{
ServiceImpl.invocationCount = 0;
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/BasicDecoratorResolutionTest.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/BasicDecoratorResolutionTest.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/BasicDecoratorResolutionTest.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.weld.tests.decorators.resolution;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+import javax.enterprise.inject.spi.Decorator;
+import javax.enterprise.util.AnnotationLiteral;
+
+import java.util.*;
+
+/**
+ * @author Marius Bogoevici
+ */
+@Artifact
+(a)BeansXml("beans-basic.xml")
+public class BasicDecoratorResolutionTest extends AbstractWeldTest
+{
+
+ @Test
+ public void testBasicDecoratorInvocation()
+ {
+ SimpleBean simpleBean = getReference(SimpleBean.class, new
AnnotationLiteral<Simple>(){});
+ String result = simpleBean.hello("world");
+ assert "simple-Hello, world-simple".equals(result);
+ }
+
+ @Test
+ public void testComplexDecoratorInvocation()
+ {
+ ComplexBean complexBean = getReference(ComplexBean.class, new
AnnotationLiteral<Complex>(){});
+ String result = complexBean.hello("world");
+ assert "simple-complex-Sophisticated Hello,
world-complex-simple".equals(result);
+ }
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/Complex.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/Complex.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/Complex.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.tests.decorators.resolution;
+
+import javax.inject.Qualifier;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Marius Bogoevici
+ */
+@Qualifier
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.TYPE, ElementType.FIELD})
+@Documented
+public @interface Complex
+{
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/ComplexBean.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/ComplexBean.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/ComplexBean.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.weld.tests.decorators.resolution;
+
+/**
+ * @author Marius Bogoevici
+ */
+@Complex
+public class ComplexBean implements SomeBean
+{
+ public String hello(String name)
+ {
+ return "Sophisticated Hello, " + name;
+ }
+
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/ComplexDecorator.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/ComplexDecorator.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/ComplexDecorator.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.weld.tests.decorators.resolution;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.enterprise.inject.Any;
+import javax.inject.Inject;
+
+/**
+ * @author Marius Bogoevici
+ */
+@Decorator
+public class ComplexDecorator implements SomeBean
+{
+ @Inject @Delegate @Any ComplexBean delegate;
+
+ public String hello(String name)
+ {
+ return "complex-" +delegate.hello(name) +"-complex";
+ }
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/DecoratorResolutionTestsHelper.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/DecoratorResolutionTestsHelper.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/DecoratorResolutionTestsHelper.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.weld.tests.decorators.resolution;
+
+import javax.enterprise.inject.spi.Decorator;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class DecoratorResolutionTestsHelper
+{
+ public static boolean decoratorClassesMatch(List<Decorator<?>>
decoratorList, Collection<Class<?>> expectedDecoratorClasses)
+ {
+ if (decoratorList.size() != expectedDecoratorClasses.size())
+ return false;
+ Collection<Class<?>> expectedDecoratedClassesCopy = new
ArrayList<Class<?>>(expectedDecoratorClasses);
+ for (Decorator<?> decorator: decoratorList)
+ {
+ if (!expectedDecoratedClassesCopy.remove(decorator.getBeanClass()))
+ return false;
+ }
+ return expectedDecoratedClassesCopy.size() == 0;
+ }
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/Simple.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/Simple.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/Simple.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.weld.tests.decorators.resolution;
+
+import javax.inject.Qualifier;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Marius Bogoevici
+ */
+@Qualifier
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.TYPE, ElementType.FIELD})
+@Documented
+public @interface Simple
+{
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SimpleBean.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SimpleBean.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SimpleBean.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.weld.tests.decorators.resolution;
+
+/**
+ * @author Marius Bogoevici
+ */
+@Simple
+public class SimpleBean implements SomeBean
+{
+ public String hello(String name)
+ {
+ return "Hello, " + name;
+ }
+
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SimpleDecorator.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SimpleDecorator.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SimpleDecorator.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.weld.tests.decorators.resolution;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.enterprise.inject.Any;
+import javax.inject.Inject;
+
+/**
+ * @author Marius Bogoevici
+ */
+@Decorator
+public class SimpleDecorator implements SomeBean
+{
+ @Inject @Delegate @Any SomeBean delegate;
+
+ public String hello(String name)
+ {
+ return "simple-" +delegate.hello(name) +"-simple";
+ }
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SomeBean.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SomeBean.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/resolution/SomeBean.java 2010-01-27
14:06:01 UTC (rev 5639)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.weld.tests.decorators.resolution;
+
+/**
+ * @author Marius Bogoevici
+ */
+public interface SomeBean
+{
+ String hello(String name);
+}
Added:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/resolution/beans-basic.xml
===================================================================
---
core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/resolution/beans-basic.xml
(rev 0)
+++
core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/resolution/beans-basic.xml 2010-01-27
14:06:01 UTC (rev 5639)
@@ -0,0 +1,23 @@
+<!--
+ ~ JBoss, Home of Professional Open Source
+ ~ Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.
+ -->
+
+<beans>
+ <decorators>
+
<decorator>org.jboss.weld.tests.decorators.resolution.SimpleDecorator</decorator>
+
<decorator>org.jboss.weld.tests.decorators.resolution.ComplexDecorator</decorator>
+ </decorators>
+</beans>