Author: swd847
Date: 2010-02-02 06:19:58 -0500 (Tue, 02 Feb 2010)
New Revision: 5708
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/Author.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/AuthorLiteral.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogConsumer.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogFormatter.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogSource.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/Consumer.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/ConsumerLiteral.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/FormattedBlog.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/FormattedBlogLiteral.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/MultipleBeansExtension.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/MultipleBeansTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/UselessBean.java
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/multipleBeans/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/multipleBeans/javax.enterprise.inject.spi.Extension
Log:
WELD-406
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/Author.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/Author.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/Author.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,16 @@
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.FIELD, ElementType.TYPE, ElementType.METHOD })
+public @interface Author
+{
+ public String name();
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/AuthorLiteral.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/AuthorLiteral.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/AuthorLiteral.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,23 @@
+/**
+ *
+ */
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+class AuthorLiteral extends AnnotationLiteral<Author> implements Author
+{
+
+ final String name;
+
+ AuthorLiteral(String name)
+ {
+ this.name = name;
+ }
+
+ public String name()
+ {
+ return name;
+ }
+
+}
\ No newline at end of file
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogConsumer.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogConsumer.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogConsumer.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,11 @@
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+import javax.inject.Inject;
+
+@Consumer(name = "Barry")
+public class BlogConsumer
+{
+ @Inject
+ @FormattedBlog(name = "Barry")
+ public String blogContent;
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogFormatter.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogFormatter.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogFormatter.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,19 @@
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+public class BlogFormatter
+{
+ @Inject
+ @Author(name = "Barry")
+ public String content;
+
+ @Produces
+ @FormattedBlog(name = "Barry")
+ public String format()
+ {
+ return "+" + content + "+";
+ }
+
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogSource.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogSource.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/BlogSource.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,14 @@
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+import javax.enterprise.inject.Produces;
+
+public class BlogSource
+{
+ @Produces
+ @Author(name = "Barry")
+ String barrysBlog = "Barry's content";
+
+ @Produces
+ @Author(name = "Bob")
+ String bobsBlog = "Bob's content";
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/Consumer.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/Consumer.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/Consumer.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,16 @@
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.FIELD, ElementType.TYPE, ElementType.METHOD })
+public @interface Consumer
+{
+ public String name();
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/ConsumerLiteral.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/ConsumerLiteral.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/ConsumerLiteral.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,23 @@
+/**
+ *
+ */
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+class ConsumerLiteral extends AnnotationLiteral<Consumer> implements Consumer
+{
+
+ final String name;
+
+ ConsumerLiteral(String name)
+ {
+ this.name = name;
+ }
+
+ public String name()
+ {
+ return name;
+ }
+
+}
\ No newline at end of file
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/FormattedBlog.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/FormattedBlog.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/FormattedBlog.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,16 @@
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.FIELD, ElementType.TYPE, ElementType.METHOD })
+public @interface FormattedBlog
+{
+ public String name();
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/FormattedBlogLiteral.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/FormattedBlogLiteral.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/FormattedBlogLiteral.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,23 @@
+/**
+ *
+ */
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+class FormattedBlogLiteral extends AnnotationLiteral<FormattedBlog> implements
FormattedBlog
+{
+
+ final String name;
+
+ FormattedBlogLiteral(String name)
+ {
+ this.name = name;
+ }
+
+ public String name()
+ {
+ return name;
+ }
+
+}
\ No newline at end of file
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/MultipleBeansExtension.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/MultipleBeansExtension.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/MultipleBeansExtension.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,58 @@
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Inject;
+
+import org.jboss.weld.tests.util.annotated.TestAnnotatedTypeBuilder;
+
+/**
+ * Extension that registers addition types via the SPI
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class MultipleBeansExtension implements Extension
+{
+
+ public void addNewAnnotatedTypes(@Observes BeforeBeanDiscovery event) throws
SecurityException, NoSuchFieldException, NoSuchMethodException
+ {
+ TestAnnotatedTypeBuilder<BlogFormatter> formatter = new
TestAnnotatedTypeBuilder<BlogFormatter>(BlogFormatter.class);
+ Field content = BlogFormatter.class.getField("content");
+ formatter.addToField(content, new InjectLiteral());
+ formatter.addToField(content, new AuthorLiteral("Bob"));
+ Method format = BlogFormatter.class.getMethod("format");
+ formatter.addToMethod(format, new ProducesLiteral());
+ formatter.addToMethod(format, new FormattedBlogLiteral("Bob"));
+ event.addAnnotatedType(formatter.create());
+
+ TestAnnotatedTypeBuilder<BlogConsumer> consumer = new
TestAnnotatedTypeBuilder<BlogConsumer>(BlogConsumer.class);
+ consumer.addToClass(new ConsumerLiteral("Bob"));
+ content = BlogConsumer.class.getField("blogContent");
+ consumer.addToField(content, new InjectLiteral());
+ consumer.addToField(content, new FormattedBlogLiteral("Bob"));
+ event.addAnnotatedType(consumer.create());
+
+ // two beans that are exactly the same
+ // this is not very useful, however should still work
+ TestAnnotatedTypeBuilder<UselessBean> uselessBuilder = new
TestAnnotatedTypeBuilder<UselessBean>(UselessBean.class);
+ event.addAnnotatedType(uselessBuilder.create());
+
+ }
+
+ private static class InjectLiteral extends AnnotationLiteral<Inject> implements
Inject
+ {
+
+ }
+
+ private static class ProducesLiteral extends AnnotationLiteral<Produces>
implements Produces
+ {
+
+ }
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/MultipleBeansTest.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/MultipleBeansTest.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/MultipleBeansTest.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,61 @@
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Packaging;
+import org.jboss.testharness.impl.packaging.PackagingType;
+import org.jboss.testharness.impl.packaging.jsr299.Extension;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+/**
+ * Tests that it is possible to add multiple beans with the same java class type
+ * through the SPI
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+@Artifact
+@IntegrationTest
+(a)Packaging(PackagingType.EAR)
+(a)Extension("javax.enterprise.inject.spi.Extension")
+@Classes(packages = { "org.jboss.weld.tests.util.annotated" })
+public class MultipleBeansTest extends AbstractWeldTest
+{
+
+ @Test
+ public void testFormatterRegistered()
+ {
+ // test that we have added two beans with the same qualifiers
+ assert getBeans(BlogFormatter.class).size() == 2;
+ // test that the beans which have different producer methods produce
+ // different values
+ assert getReference(String.class, new
FormattedBlogLiteral("Bob")).equals("+Bob's content+");
+ assert getReference(String.class, new
FormattedBlogLiteral("Barry")).equals("+Barry's content+");
+ }
+
+ @Test
+ public void testBlogConsumed()
+ {
+ // test that the two different BlogConsumers have been registered
+ // correctly
+ BlogConsumer consumer = getReference(BlogConsumer.class, new
ConsumerLiteral("Barry"));
+ assert consumer.blogContent.equals("+Barry's content+");
+ consumer = getReference(BlogConsumer.class, new ConsumerLiteral("Bob"));
+ assert consumer.blogContent.equals("+Bob's content+");
+ }
+
+ /**
+ * Apparently it is not possible to add two beans that are exactly the same.
+ * Even though this is not very useful it should still be possible.
+ *
+ */
+ @Test(groups = { "broken" })
+ public void testTwoBeansExactlyTheSame()
+ {
+ assert getBeans(UselessBean.class).size() == 2;
+ }
+
+}
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/UselessBean.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/UselessBean.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/multipleBeans/UselessBean.java 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1,12 @@
+package org.jboss.weld.tests.extensions.multipleBeans;
+
+/**
+ *
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class UselessBean
+{
+
+}
Added:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/multipleBeans/javax.enterprise.inject.spi.Extension
===================================================================
---
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/multipleBeans/javax.enterprise.inject.spi.Extension
(rev 0)
+++
core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/multipleBeans/javax.enterprise.inject.spi.Extension 2010-02-02
11:19:58 UTC (rev 5708)
@@ -0,0 +1 @@
+org.jboss.weld.tests.extensions.multipleBeans.MultipleBeansExtension