Author: pete.muir(a)jboss.org
Date: 2009-03-29 19:14:16 -0400 (Sun, 29 Mar 2009)
New Revision: 2257
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/ActivitiesTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/Cow.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/Fox.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/NightTime.java
Log:
Start on activities tests
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/ActivitiesTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/ActivitiesTest.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/ActivitiesTest.java 2009-03-29
23:14:16 UTC (rev 2257)
@@ -0,0 +1,222 @@
+package org.jboss.jsr299.tck.tests.activities;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.context.Context;
+import javax.context.Contextual;
+import javax.context.CreationalContext;
+import javax.context.Dependent;
+import javax.event.Observer;
+import javax.inject.Production;
+import javax.inject.manager.Bean;
+import javax.inject.manager.InjectionPoint;
+import javax.inject.manager.Manager;
+
+import org.hibernate.tck.annotations.SpecAssertion;
+import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.testng.annotations.Test;
+
+@Artifact
+public class ActivitiesTest extends AbstractJSR299Test
+{
+
+ private Bean<?> createDummyBean(Manager manager, final Type injectionPointType)
+ {
+ final Set<InjectionPoint> injectionPoints = new
HashSet<InjectionPoint>();
+ final Set<Type> types = new HashSet<Type>();
+ types.add(Object.class);
+ types.add(injectionPointType);
+ final Bean<?> bean = new Bean<Object>(manager)
+ {
+
+
+
+ @Override
+ public Set<Annotation> getBindings()
+ {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Class<? extends Annotation> getDeploymentType()
+ {
+ return Production.class;
+ }
+
+ @Override
+ public Set<? extends InjectionPoint> getInjectionPoints()
+ {
+ return injectionPoints;
+ }
+
+ @Override
+ public String getName()
+ {
+ return null;
+ }
+
+ @Override
+ public Class<? extends Annotation> getScopeType()
+ {
+ return Dependent.class;
+ }
+
+ @Override
+ public Set<Type> getTypes()
+ {
+ return types;
+ }
+
+ @Override
+ public boolean isNullable()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isSerializable()
+ {
+ return false;
+ }
+
+ public Object create(CreationalContext<Object> creationalContext)
+ {
+ return null;
+ }
+
+ public void destroy(Object instance)
+ {
+
+ }
+
+ };
+ InjectionPoint injectionPoint = new InjectionPoint()
+ {
+
+ public <T extends Annotation> T getAnnotation(Class<T>
annotationType)
+ {
+ return null;
+ }
+
+ public Annotation[] getAnnotations()
+ {
+ return new Annotation[0];
+ }
+
+ public Bean<?> getBean()
+ {
+ return bean;
+ }
+
+ public Set<Annotation> getBindings()
+ {
+ return Collections.emptySet();
+ }
+
+ public Member getMember()
+ {
+ return null;
+ }
+
+ public Type getType()
+ {
+ return Object.class;
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation>
annotationType)
+ {
+ return false;
+ }
+
+ };
+ injectionPoints.add(injectionPoint);
+ return bean;
+ }
+
+ private static @interface Dummy {}
+
+ private static class DummyContext implements Context
+ {
+
+ public <T> T get(Contextual<T> contextual)
+ {
+ return null;
+ }
+
+ public <T> T get(Contextual<T> contextual, CreationalContext<T>
creationalContext)
+ {
+ return null;
+ }
+
+ public Class<? extends Annotation> getScopeType()
+ {
+ return Dummy.class;
+ }
+
+ public boolean isActive()
+ {
+ return false;
+ }
+
+ }
+
+ @Test(groups="ri-broken")
+ @SpecAssertion(section="11.6", id="b")
+ public void testBeanBelongingToParentActivityBelongsToChildActivity()
+ {
+ assert getCurrentManager().resolveByType(Cow.class).size() == 1;
+ Bean<?> bean =
getCurrentManager().resolveByType(Cow.class).iterator().next();
+ Manager childActivity = getCurrentManager().createActivity();
+ assert childActivity.resolveByType(Cow.class).size() == 1;
+ assert childActivity.resolveByType(Cow.class).iterator().next().equals(bean);
+ }
+
+ @Test(groups="ri-broken")
+ @SpecAssertion(section="11.6", id="c")
+ public void testBeanBelongingToParentActivityCanBeInjectedIntoChildActivityBean()
+ {
+ assert getCurrentManager().resolveByType(Cow.class).size() == 1;
+ Bean<?> bean =
getCurrentManager().resolveByType(Cow.class).iterator().next();
+ Manager childActivity = getCurrentManager().createActivity();
+ Bean<?> dummyBean = createDummyBean(childActivity, Cow.class);
+ childActivity.addBean(dummyBean);
+ assert
childActivity.getInstanceToInject(dummyBean.getInjectionPoints().iterator().next()) !=
null;
+ }
+
+ @Test(groups="ri-broken")
+ @SpecAssertion(section="11.6", id="j")
+ public void testObserverBelongingToParentActivityBelongsToChildActivity()
+ {
+ assert getCurrentManager().resolveObservers(new NightTime()).size() == 1;
+ Observer<?> observer = getCurrentManager().resolveObservers(new
NightTime()).iterator().next();
+ Manager childActivity = getCurrentManager().createActivity();
+ assert childActivity.resolveObservers(new NightTime()).size() == 1;
+ assert childActivity.resolveObservers(new
NightTime()).iterator().next().equals(observer);
+ }
+
+ @Test(groups="ri-broken")
+ @SpecAssertion(section="11.6", id="k")
+ public void testObserverBelongingToParentFiresForChildActivity()
+ {
+ Fox.setObserved(false);
+ Manager childActivity = getCurrentManager().createActivity();
+ childActivity.fireEvent(new NightTime());
+ assert Fox.isObserved();
+ }
+
+ @Test(groups="ri-broken")
+ @SpecAssertion(section="11.6", id="l")
+ public void testContextObjectBelongingToParentBelongsToChild()
+ {
+ getCurrentManager().addContext(new DummyContext());
+ Manager childActivity = getCurrentManager().createActivity();
+ assert childActivity.getContext(Dummy.class) != null;
+ }
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/ActivitiesTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/Cow.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/Cow.java
(rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/Cow.java 2009-03-29
23:14:16 UTC (rev 2257)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.activities;
+
+public class Cow
+{
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/Cow.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/Fox.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/Fox.java
(rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/Fox.java 2009-03-29
23:14:16 UTC (rev 2257)
@@ -0,0 +1,25 @@
+package org.jboss.jsr299.tck.tests.activities;
+
+import javax.event.Observes;
+
+public class Fox
+{
+
+ private static boolean observed = false;
+
+ public void observe(@Observes NightTime nighttime)
+ {
+ observed = true;
+ }
+
+ public static boolean isObserved()
+ {
+ return observed;
+ }
+
+ public static void setObserved(boolean observed)
+ {
+ Fox.observed = observed;
+ }
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/Fox.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/NightTime.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/NightTime.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/NightTime.java 2009-03-29
23:14:16 UTC (rev 2257)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.activities;
+
+public class NightTime
+{
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/activities/NightTime.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Show replies by date