Author: pete.muir(a)jboss.org
Date: 2009-12-09 13:52:30 -0500 (Wed, 09 Dec 2009)
New Revision: 5255
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Special.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Temp.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/TempConsumer.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/TempProducer.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Useless.java
Modified:
core/trunk/tests/src/main/java/org/jboss/weld/test/AbstractWeldTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java
Log:
WELD-311
Modified: core/trunk/tests/src/main/java/org/jboss/weld/test/AbstractWeldTest.java
===================================================================
--- core/trunk/tests/src/main/java/org/jboss/weld/test/AbstractWeldTest.java 2009-12-09
17:10:51 UTC (rev 5254)
+++ core/trunk/tests/src/main/java/org/jboss/weld/test/AbstractWeldTest.java 2009-12-09
18:52:30 UTC (rev 5255)
@@ -180,13 +180,13 @@
@SuppressWarnings("unchecked")
public <T> T createContextualInstance(Class<T> beanType, Annotation...
bindings)
{
- return (T) createContextualInstance((Type) beanType, bindings);
+ Bean<?> bean = getBean(beanType, bindings);
+ return (T) getCurrentManager().getReference(bean, beanType,
getCurrentManager().createCreationalContext(bean));
}
-
- public Object createContextualInstance(Type beanType, Annotation... bindings)
+
+ public <T> T getReference(Bean<T> bean)
{
- Bean<?> bean = getBean(beanType, bindings);
- return getCurrentManager().getReference(bean, beanType,
getCurrentManager().createCreationalContext(bean));
+ return (T) getCurrentManager().getReference(bean, bean.getBeanClass(),
getCurrentManager().createCreationalContext(bean));
}
@SuppressWarnings("unchecked")
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java 2009-12-09
17:10:51 UTC (rev 5254)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java 2009-12-09
18:52:30 UTC (rev 5255)
@@ -1,8 +1,16 @@
package org.jboss.weld.tests.scope;
+import java.lang.annotation.Annotation;
+
import javax.enterprise.context.Dependent;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.util.AnnotationLiteral;
import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.weld.Container;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.context.beanstore.HashMapBeanStore;
import org.jboss.weld.test.AbstractWeldTest;
import org.testng.annotations.Test;
@@ -10,10 +18,46 @@
public class ScopeTest extends AbstractWeldTest
{
+ private static Annotation USELESS_LITERAL = new AnnotationLiteral<Useless>()
{};
+ private static Annotation SPECIAL_LITERAL = new AnnotationLiteral<Special>()
{};
+
@Test(description="WELD-322")
public void testScopeDeclaredOnSubclassOverridesScopeOnSuperClass()
{
assert
getCurrentManager().resolve(getCurrentManager().getBeans(Bar.class)).getScope().equals(Dependent.class);
}
+ @Test(description="WELD-311")
+ public void testScopeOfProducerMethod()
+ {
+ Bean<Temp> specialTempBean = getBean(Temp.class, SPECIAL_LITERAL);
+ Bean<Temp> uselessTempBean = getBean(Temp.class, USELESS_LITERAL);
+ assert specialTempBean.getScope().equals(RequestScoped.class);
+ assert uselessTempBean.getScope().equals(RequestScoped.class);
+ assert getReference(specialTempBean).getNumber() == 10;
+ assert getReference(uselessTempBean).getNumber() == 11;
+
+ TempConsumer tempConsumer = createContextualInstance(TempConsumer.class);
+ tempConsumer.getSpecialTemp().setNumber(101);
+ tempConsumer.getUselessTemp().setNumber(102);
+
+ assert tempConsumer.getSpecialTemp().getNumber() == 101;
+ assert tempConsumer.getUselessTemp().getNumber() == 102;
+ assert getReference(specialTempBean).getNumber() == 101;
+ assert getReference(uselessTempBean).getNumber() == 102;
+
+ newRequest();
+
+ assert tempConsumer.getSpecialTemp().getNumber() == 10;
+ assert tempConsumer.getUselessTemp().getNumber() == 102;
+ assert getReference(specialTempBean).getNumber() == 10;
+ assert getReference(uselessTempBean).getNumber() == 102;
+ }
+
+ private void newRequest()
+ {
+ ContextLifecycle lifecycle =
Container.instance().deploymentServices().get(ContextLifecycle.class);
+ lifecycle.endRequest("test",
lifecycle.getRequestContext().getBeanStore());
+ lifecycle.beginRequest("test", new HashMapBeanStore());
+ }
}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Special.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Special.java
(rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Special.java 2009-12-09
18:52:30 UTC (rev 5255)
@@ -0,0 +1,20 @@
+package org.jboss.weld.tests.scope;
+
+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 java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target({FIELD, METHOD, TYPE, PARAMETER})
+public @interface Special
+{
+
+}
Property changes on:
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Special.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Temp.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Temp.java
(rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Temp.java 2009-12-09
18:52:30 UTC (rev 5255)
@@ -0,0 +1,28 @@
+package org.jboss.weld.tests.scope;
+
+public class Temp
+{
+
+ private int number;
+
+ public Temp(int number)
+ {
+ this.number = number;
+ }
+
+ public Temp()
+ {
+ number = 0;
+ }
+
+ public int getNumber()
+ {
+ return number;
+ }
+
+ public void setNumber(int number)
+ {
+ this.number = number;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Temp.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/TempConsumer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/TempConsumer.java
(rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/TempConsumer.java 2009-12-09
18:52:30 UTC (rev 5255)
@@ -0,0 +1,24 @@
+package org.jboss.weld.tests.scope;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+@ApplicationScoped
+public class TempConsumer
+{
+
+ @Inject @Special Temp specialTemp;
+ @Inject @Useless Temp uselessTemp;
+
+ public Temp getSpecialTemp()
+ {
+ return specialTemp;
+ }
+
+ public Temp getUselessTemp()
+ {
+ return uselessTemp;
+ }
+
+
+}
Property changes on:
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/TempConsumer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/TempProducer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/TempProducer.java
(rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/TempProducer.java 2009-12-09
18:52:30 UTC (rev 5255)
@@ -0,0 +1,28 @@
+package org.jboss.weld.tests.scope;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+@Named
+@SessionScoped
+public class TempProducer implements Serializable
+{
+
+ @Produces
+ @RequestScoped
+ @Special
+ public Temp getTemp()
+ {
+ return new Temp(10);
+ }
+
+ @Produces
+ @RequestScoped
+ @Useless
+ Temp t = new Temp(11);
+
+}
\ No newline at end of file
Property changes on:
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/TempProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Useless.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Useless.java
(rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Useless.java 2009-12-09
18:52:30 UTC (rev 5255)
@@ -0,0 +1,20 @@
+package org.jboss.weld.tests.scope;
+
+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 java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target({FIELD, METHOD, TYPE, PARAMETER})
+public @interface Useless
+{
+
+}
Property changes on:
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/Useless.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Show replies by date