[weld-commits] Weld SVN: r5488 - in core/trunk/tests/src: test/java/org/jboss/weld/tests and 2 other directories.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Mon Jan 18 11:02:56 EST 2010
Author: pete.muir at jboss.org
Date: 2010-01-18 11:02:56 -0500 (Mon, 18 Jan 2010)
New Revision: 5488
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/TestableObserverMethod.java
Modified:
core/trunk/tests/src/main/java/org/jboss/weld/test/BeanManagerLocator.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/activities/ActivitiesTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/activities/current/EventCurrentActivityTest.java
Log:
WELD-83
Modified: core/trunk/tests/src/main/java/org/jboss/weld/test/BeanManagerLocator.java
===================================================================
--- core/trunk/tests/src/main/java/org/jboss/weld/test/BeanManagerLocator.java 2010-01-18 15:11:18 UTC (rev 5487)
+++ core/trunk/tests/src/main/java/org/jboss/weld/test/BeanManagerLocator.java 2010-01-18 16:02:56 UTC (rev 5488)
@@ -22,11 +22,11 @@
{
if (ServletTestRunner.getCurrentServletContext() != null)
{
- return ServletHelper.getModuleBeanManager(ServletTestRunner.getCurrentServletContext());
+ return ServletHelper.getModuleBeanManager(ServletTestRunner.getCurrentServletContext()).getCurrent();
}
else if (getTestArchive() != null)
{
- return Container.instance().beanDeploymentArchives().get(getTestArchive());
+ return Container.instance().beanDeploymentArchives().get(getTestArchive()).getCurrent();
}
else
{
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/TestableObserverMethod.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/TestableObserverMethod.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/TestableObserverMethod.java 2010-01-18 16:02:56 UTC (rev 5488)
@@ -0,0 +1,10 @@
+package org.jboss.weld.tests;
+
+import javax.enterprise.inject.spi.ObserverMethod;
+
+public interface TestableObserverMethod<T> extends ObserverMethod<T>
+{
+
+ public boolean isObserved();
+
+}
\ No newline at end of file
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/TestableObserverMethod.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/activities/ActivitiesTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/activities/ActivitiesTest.java 2010-01-18 15:11:18 UTC (rev 5487)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/activities/ActivitiesTest.java 2010-01-18 16:02:56 UTC (rev 5488)
@@ -11,38 +11,44 @@
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Reception;
+import javax.enterprise.event.TransactionPhase;
import javax.enterprise.inject.UnsatisfiedResolutionException;
import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.ObserverMethod;
import javax.enterprise.util.AnnotationLiteral;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.weld.bean.ForwardingBean;
+import org.jboss.weld.literal.AnyLiteral;
import org.jboss.weld.literal.DefaultLiteral;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.test.AbstractWeldTest;
+import org.jboss.weld.util.collections.Arrays2;
import org.testng.annotations.Test;
-
/**
*
* Spec version: 20090519
- *
+ *
*/
@Artifact
public class ActivitiesTest extends AbstractWeldTest
{
- private static final Set<Annotation> DEFAULT_QUALIFIERS = Collections.<Annotation>singleton(DefaultLiteral.INSTANCE);
+ private static final Set<Annotation> DEFAULT_QUALIFIERS = Collections.<Annotation> singleton(DefaultLiteral.INSTANCE);
private Bean<?> createDummyBean(BeanManager beanManager, final Type injectionPointType)
{
final Set<InjectionPoint> injectionPoints = new HashSet<InjectionPoint>();
final Set<Type> types = new HashSet<Type>();
final Set<Annotation> bindings = new HashSet<Annotation>();
- bindings.add(new AnnotationLiteral<Tame>() {});
+ bindings.add(new AnnotationLiteral<Tame>()
+ {
+ });
types.add(Object.class);
final Bean<?> bean = new Bean<Object>()
{
@@ -192,15 +198,15 @@
assert childActivity.getInjectableReference(dummyBean.getInjectionPoints().iterator().next(), childActivity.createCreationalContext(dummyBean)) != null;
}
-// @Test
-// public void testObserverBelongingToParentActivityBelongsToChildActivity()
-// {
-// assert getCurrentManager().resolveObservers(new NightTime()).size() == 1;
-// Observer<?> observer = getCurrentManager().resolveObservers(new NightTime()).iterator().next();
-// BeanManager childActivity = getCurrentManager().createActivity();
-// assert childActivity.resolveObservers(new NightTime()).size() == 1;
-// assert childActivity.resolveObservers(new NightTime()).iterator().next().equals(observer);
-// }
+ @Test
+ public void testObserverBelongingToParentActivityBelongsToChildActivity()
+ {
+ assert getCurrentManager().resolveObserverMethods(new NightTime()).size() == 1;
+ ObserverMethod<?> observer = getCurrentManager().resolveObserverMethods(new NightTime()).iterator().next();
+ BeanManager childActivity = getCurrentManager().createActivity();
+ assert childActivity.resolveObserverMethods(new NightTime()).size() == 1;
+ assert childActivity.resolveObserverMethods(new NightTime()).iterator().next().equals(observer);
+ }
@Test
public void testObserverBelongingToParentFiresForChildActivity()
@@ -236,10 +242,12 @@
BeanManagerImpl childActivity = getCurrentManager().createActivity();
Bean<?> dummyBean = createDummyBean(childActivity, Cow.class);
childActivity.addBean(dummyBean);
- assert getBeans(Object.class, new AnnotationLiteral<Tame>() {}).size() == 0;
+ assert getBeans(Object.class, new AnnotationLiteral<Tame>()
+ {
+ }).size() == 0;
}
- @Test(expectedExceptions=UnsatisfiedResolutionException.class)
+ @Test(expectedExceptions = UnsatisfiedResolutionException.class)
public void testInstanceProcessedByParentActivity()
{
Context dummyContext = new DummyContext();
@@ -248,9 +256,11 @@
final Bean<Cow> bean = getBeans(Cow.class).iterator().next();
BeanManagerImpl childActivity = getCurrentManager().createActivity();
final Set<Annotation> bindingTypes = new HashSet<Annotation>();
- bindingTypes.add(new AnnotationLiteral<Tame>() {});
+ bindingTypes.add(new AnnotationLiteral<Tame>()
+ {
+ });
childActivity.addBean(new ForwardingBean<Cow>()
- {
+ {
@Override
protected Bean<Cow> delegate()
@@ -270,28 +280,52 @@
return Collections.emptySet();
}
- });
+ });
getReference(Field.class).get();
}
@Test
public void testObserverBelongingToChildDoesNotFireForParentActivity()
{
-
-// BeanManager childActivity = getCurrentManager().createActivity();
-// ObserverMethod<NightTime> observer = new Observer<NightTime>()
-// {
-//
-// public boolean notify(NightTime event)
-// {
-// assert false;
-// return false;
-// }
-//
-// };
-// //TODO Fix this test to use an observer method in a child activity
-//// childActivity.addObserver(observer);
-// getCurrentManager().fireEvent(new NightTime());
+
+ BeanManagerImpl childActivity = getCurrentManager().createActivity();
+ ObserverMethod<NightTime> observer = new ObserverMethod<NightTime>()
+ {
+
+ public void notify(NightTime event)
+ {
+ assert false;
+ }
+
+ public Class<?> getBeanClass()
+ {
+ return NightTime.class;
+ }
+
+ public Set<Annotation> getObservedQualifiers()
+ {
+ return Arrays2.asSet(AnyLiteral.INSTANCE, DefaultLiteral.INSTANCE);
+ }
+
+ public Type getObservedType()
+ {
+ return NightTime.class;
+ }
+
+ public Reception getReception()
+ {
+ return Reception.ALWAYS;
+ }
+
+ public TransactionPhase getTransactionPhase()
+ {
+ return TransactionPhase.IN_PROGRESS;
+ }
+
+ };
+ // TODO Fix this test to use an observer method in a child activity
+ childActivity.addObserver(observer);
+ getCurrentManager().fireEvent(new NightTime());
}
}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/activities/current/EventCurrentActivityTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/activities/current/EventCurrentActivityTest.java 2010-01-18 15:11:18 UTC (rev 5487)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/activities/current/EventCurrentActivityTest.java 2010-01-18 16:02:56 UTC (rev 5488)
@@ -1,30 +1,35 @@
package org.jboss.weld.tests.activities.current;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.Set;
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Reception;
+import javax.enterprise.event.TransactionPhase;
import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.weld.literal.AnyLiteral;
+import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.test.AbstractWeldTest;
+import org.jboss.weld.tests.TestableObserverMethod;
import org.testng.annotations.Test;
/**
*
* Spec version: 20090519
- *
+ *
*/
@Artifact
public class EventCurrentActivityTest extends AbstractWeldTest
{
-
private static class DummyContext implements Context
{
- private boolean active = true;
-
public <T> T get(Contextual<T> contextual)
{
return null;
@@ -42,44 +47,62 @@
public boolean isActive()
{
- return active;
+ return true;
}
- public void setActive(boolean active)
- {
- this.active = active;
- }
-
}
- @Test
+
+ @Test(groups = "broken")
public void testEventProcessedByCurrentActivity()
{
-// Context dummyContext = new DummyContext();
-// getCurrentManager().addContext(dummyContext);
-// WeldManager childActivity = getCurrentManager().createActivity();
-// TestableObserver<NightTime> observer = new TestableObserver<NightTime>()
-// {
-//
-// boolean observed = false;
-//
-// public boolean notify(NightTime event)
-// {
-// observed = true;
-// return false;
-// }
-//
-// public boolean isObserved()
-// {
-// return observed;
-// }
+ DummyContext dummyContext = new DummyContext();
+ getCurrentManager().addContext(dummyContext);
+ BeanManagerImpl childActivity = getCurrentManager().createActivity();
+ TestableObserverMethod<NightTime> observer = new TestableObserverMethod<NightTime>()
+ {
-// };
- //TODO Fix this test to use observer method within a child activity
-// childActivity.addObserver(observer);
-// childActivity.setCurrent(dummyContext.getScopeType());
-// createContextualInstance(Dusk.class).ping();
-// assert observer.isObserved();
+ boolean observed = false;
+
+ public void notify(NightTime event)
+ {
+ observed = true;
+ }
+
+ public boolean isObserved()
+ {
+ return observed;
+ }
+
+ public Class<?> getBeanClass()
+ {
+ return NightTime.class;
+ }
+
+ public Set<Annotation> getObservedQualifiers()
+ {
+ return Collections.<Annotation>singleton(AnyLiteral.INSTANCE);
+ }
+
+ public Type getObservedType()
+ {
+ return NightTime.class;
+ }
+
+ public Reception getReception()
+ {
+ return Reception.ALWAYS;
+ }
+
+ public TransactionPhase getTransactionPhase()
+ {
+ return TransactionPhase.IN_PROGRESS;
+ }
+
+ };
+ childActivity.addObserver(observer);
+ childActivity.setCurrent(dummyContext.getScope());
+ getReference(Dusk.class).ping();
+ assert observer.isObserved();
}
-
}
More information about the weld-commits
mailing list