[webbeans-commits] Webbeans SVN: r1416 - in tck/trunk/impl/src/main/java/org/jboss/webbeans/tck: unit/context/dependent and 1 other directory.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Wed Feb 4 16:32:20 EST 2009
Author: dallen6
Date: 2009-02-04 16:32:20 -0500 (Wed, 04 Feb 2009)
New Revision: 1416
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/ApplicationHorseStable.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/HorseInStableEvent.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/HorseStable.java
Modified:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/integration/context/dependent/DependentContextTest.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/DependentContextTest.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/SpiderProducer.java
Log:
A few more tests added for dependent context.
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/integration/context/dependent/DependentContextTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/integration/context/dependent/DependentContextTest.java 2009-02-04 19:34:41 UTC (rev 1415)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/integration/context/dependent/DependentContextTest.java 2009-02-04 21:32:20 UTC (rev 1416)
@@ -37,6 +37,54 @@
}
/**
+ * when the container is injecting dependencies of an EJB or servlet or when
+ * a @PostConstruct or @PreDestroy callback is invoked by the EJB container.
+ */
+ @Test(groups = { "contexts", "injection", "stub", "servlet", "integration" })
+ @SpecAssertion(section = "8.3", id = "unknown")
+ public void testContextIsActiveDuringServletDependencyInjection()
+ {
+ assert false;
+ }
+
+ /**
+ * when the container is injecting dependencies of an EJB or servlet or when
+ * a @PostConstruct or @PreDestroy callback is invoked by the EJB container.
+ */
+ @Test(groups = { "contexts", "postconstruct", "stub", "ejb3", "integration" })
+ @SpecAssertion(section = "8.3", id = "unknown")
+ public void testContextIsActiveDuringEJBPostConstruct()
+ {
+ assert false;
+ }
+
+ /**
+ * A bean, EJB or servlet may obtain an instance of a bean with scope @Dependent
+ * via dependency injection or by calling Manager.getInstance(),
+ * Manager.getInstanceByType() or Instance.get() when the @Dependent scope is
+ * active.
+ */
+ @Test(groups = { "stub", "contexts", "ejb3", "integration" })
+ @SpecAssertion(section = "8.3.1", id = "unknown")
+ public void testEjbBeanMayCreateInstanceWheneverScopeActive()
+ {
+ assert false;
+ }
+
+ /**
+ * A bean, EJB or servlet may obtain an instance of a bean with scope @Dependent
+ * via dependency injection or by calling Manager.getInstance(),
+ * Manager.getInstanceByType() or Instance.get() when the @Dependent scope is
+ * active.
+ */
+ @Test(groups = { "stub", "contexts", "servlet", "integration" })
+ @SpecAssertion(section = "8.3.1", id = "unknown")
+ public void testServletBeanMayCreateInstanceWheneverScopeIsActive()
+ {
+ assert false;
+ }
+
+ /**
* destroy all dependent objects of an EJB bean or Servlet when the EJB bean
* or Servlet is destroyed,
*/
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/ApplicationHorseStable.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/ApplicationHorseStable.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/ApplicationHorseStable.java 2009-02-04 21:32:20 UTC (rev 1416)
@@ -0,0 +1,33 @@
+package org.jboss.webbeans.tck.unit.context.dependent;
+
+import javax.context.ApplicationScoped;
+import javax.context.Dependent;
+import javax.event.Observes;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
+
+ at ApplicationScoped
+class ApplicationHorseStable
+{
+ @Current
+ private Manager manager;
+ private static boolean dependentContextActive = false;
+
+ public void horseEntered(@Observes HorseInStableEvent horseEvent)
+ {
+ if (manager.getContext(Dependent.class).isActive())
+ {
+ dependentContextActive = true;
+ }
+ }
+
+ public static boolean isDependentContextActive()
+ {
+ return ApplicationHorseStable.dependentContextActive;
+ }
+
+ public static void setDependentContextActive(boolean dependentContextActive)
+ {
+ ApplicationHorseStable.dependentContextActive = dependentContextActive;
+ }
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/ApplicationHorseStable.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/DependentContextTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/DependentContextTest.java 2009-02-04 19:34:41 UTC (rev 1415)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/DependentContextTest.java 2009-02-04 21:32:20 UTC (rev 1416)
@@ -42,7 +42,7 @@
* Any injected instance of the (@Dependent scoped) bean is bound to the
* lifecycle of the bean, servlet or EJB into which it is injected.
*/
- @Test(groups = { "contexts", "el", "stub" })
+ @Test(groups = { "contexts", "stub" })
@SpecAssertion(section = "8.3", id = "unknown")
public void testDependentBeansBoundToLifecycleOfContainingBean()
{
@@ -115,24 +115,57 @@
* Any instance of the (@Dependent-scoped) Web Bean that receives a producer
* method, producer field, disposal method or observer method invocation
* exists to service that invocation only
+ *
+ * @throws Exception
*/
- @Test(groups = { "stub", "contexts", "disposalMethod" })
+ @Test(groups = { "broken", "contexts", "disposalMethod" })
@SpecAssertion(section = "8.3", id = "unknown")
- public void testInstanceUsedForDisposalMethodNotShared()
+ public void testInstanceUsedForDisposalMethodNotShared() throws Exception
{
- assert false;
+ deployBeans(SpiderProducer.class);
+ new RunInDependentContext()
+ {
+
+ @Override
+ protected void execute() throws Exception
+ {
+ SpiderProducer spiderProducer = manager.getInstanceByType(SpiderProducer.class);
+ Bean<Tarantula> tarantulaBean = manager.resolveByType(Tarantula.class).iterator().next();
+ Tarantula tarantula = tarantulaBean.create(new MyCreationalContext<Tarantula>());
+ assert tarantula != null;
+ tarantulaBean.destroy(tarantula);
+ assert SpiderProducer.getInstanceUsedForDisposal() != null;
+ assert SpiderProducer.getInstanceUsedForDisposal() != spiderProducer;
+ }
+
+ }.run();
}
/**
* Any instance of the (@Dependent-scoped) Web Bean that receives a producer
* method, producer field, disposal method or observer method invocation
* exists to service that invocation only
+ *
+ * @throws Exception
*/
- @Test(groups = { "stub", "contexts", "observerMethod" })
+ @Test(groups = { "contexts", "observerMethod" })
@SpecAssertion(section = "8.3", id = "unknown")
- public void testInstanceUsedForObserverMethodNotShared()
+ public void testInstanceUsedForObserverMethodNotShared() throws Exception
{
- assert false;
+ deployBeans(HorseStable.class);
+ new RunInDependentContext()
+ {
+
+ @Override
+ protected void execute() throws Exception
+ {
+ HorseStable firstStableInstance = manager.getInstanceByType(HorseStable.class);
+ manager.fireEvent(new HorseInStableEvent());
+ assert HorseStable.getInstanceThatObservedEvent() != null;
+ assert HorseStable.getInstanceThatObservedEvent() != firstStableInstance;
+ }
+
+ }.run();
}
/**
@@ -201,11 +234,15 @@
* container to receive a producer method, producer field, disposal method or
* observer method invocation, or
*/
- @Test(groups = { "stub", "contexts", "producerMethod" })
+ @Test(groups = { "contexts", "producerMethod" })
@SpecAssertion(section = "8.3", id = "unknown")
public void testContextIsActiveWhenInvokingProducerMethod()
{
- assert false;
+ deployBeans(SpiderProducer.class);
+ Bean<Tarantula> tarantulaBean = manager.resolveByType(Tarantula.class).iterator().next();
+ Tarantula tarantula = tarantulaBean.create(new MyCreationalContext<Tarantula>());
+ assert tarantula != null;
+ assert SpiderProducer.isDependentContextActive();
}
/**
@@ -218,7 +255,6 @@
public void testContextIsActiveWhenInvokingProducerField()
{
assert false;
- // assert manager.getContext(Dependent.class).isActive();
}
/**
@@ -226,11 +262,17 @@
* container to receive a producer method, producer field, disposal method or
* observer method invocation, or
*/
- @Test(groups = { "stub", "contexts", "disposalMethod" })
+ @Test(groups = { "broken", "contexts", "disposalMethod" })
@SpecAssertion(section = "8.3", id = "unknown")
public void testContextIsActiveWhenInvokingDisposalMethod()
{
- assert false;
+ deployBeans(SpiderProducer.class);
+ Bean<Tarantula> tarantulaBean = manager.resolveByType(Tarantula.class).iterator().next();
+ Tarantula tarantula = tarantulaBean.create(new MyCreationalContext<Tarantula>());
+ assert tarantula != null;
+ SpiderProducer.setDependentContextActive(false);
+ tarantulaBean.destroy(tarantula);
+ assert SpiderProducer.isDependentContextActive();
}
/**
@@ -238,11 +280,13 @@
* container to receive a producer method, producer field, disposal method or
* observer method invocation, or
*/
- @Test(groups = { "stub", "contexts", "observerMethod" })
+ @Test(groups = { "contexts", "observerMethod" })
@SpecAssertion(section = "8.3", id = "unknown")
public void testContextIsActiveWhenInvokingObserverMethod()
{
- assert false;
+ deployBeans(HorseStable.class);
+ manager.fireEvent(new HorseInStableEvent());
+ assert HorseStable.isDependentContextActive();
}
/**
@@ -258,26 +302,25 @@
/**
* while an observer method is invoked, or
*/
- @Test(groups = { "stub", "contexts", "el" })
+ @Test(groups = { "contexts", "observerMethod" })
@SpecAssertion(section = "8.3", id = "unknown")
public void testContextIsActiveWhenInvokingObserver()
{
- assert false;
+ deployBeans(ApplicationHorseStable.class);
+ manager.fireEvent(new HorseInStableEvent());
+ assert HorseStable.isDependentContextActive();
}
/**
* when the container is creating or destroying a contextual instance of a
* bean or injecting its dependencies, or
*/
- @Test(groups = { "contexts", "beanLifecycle" })
+ @Test(groups = { "stub", "contexts", "beanLifecycle" })
@SpecAssertion(section = "8.3", id = "unknown")
public void testContextIsActiveDuringBeanCreation()
{
- // Slightly roundabout, but I can't see a better way to test atm
- deployBeans(FoxRun.class, Fox.class);
- Bean<FoxRun> foxRunBean = manager.resolveByType(FoxRun.class).iterator().next();
- FoxRun foxRun = foxRunBean.create(new MyCreationalContext<FoxRun>());
- assert foxRun.fox != null;
+ //TODO Previous test was not testing that context was active precisely
+ assert false;
}
/**
@@ -306,65 +349,6 @@
}
/**
- * when the container is injecting dependencies of an EJB or servlet or when
- * a @PostConstruct or @PreDestroy callback is invoked by the EJB container.
- */
- @Test(groups = { "contexts", "injection", "stub", "servlet" })
- @SpecAssertion(section = "8.3", id = "unknown")
- public void testContextIsActiveDuringServletDependencyInjection()
- {
- assert false;
- }
-
- /**
- * when the container is injecting dependencies of an EJB or servlet or when
- * a @PostConstruct or @PreDestroy callback is invoked by the EJB container.
- */
- @Test(groups = { "contexts", "postconstruct", "stub", "ejb3" })
- @SpecAssertion(section = "8.3", id = "unknown")
- public void testContextIsActiveDuringEJBPostConstruct()
- {
- assert false;
- }
-
- /**
- * when the container is injecting dependencies of an EJB or servlet or when
- * a @PostConstruct or @PreDestroy callback is invoked by the EJB container.
- */
- @Test(groups = { "contexts", "predestroy", "stub", "ejb3" })
- @SpecAssertion(section = "8.3", id = "unknown")
- public void testContextIsActiveDuringEJBPreDestroy()
- {
- assert false;
- }
-
- /**
- * A bean, EJB or servlet may obtain an instance of a bean with scope @Dependent
- * via dependency injection or by calling Manager.getInstance(),
- * Manager.getInstanceByType() or Instance.get() when the @Dependent scope is
- * active.
- */
- @Test(groups = { "stub", "contexts", "ejb3", "initializerMethod" })
- @SpecAssertion(section = "8.3.1", id = "unknown")
- public void testEjbBeanMayCreateInstanceWheneverScopeActive()
- {
- assert false;
- }
-
- /**
- * A bean, EJB or servlet may obtain an instance of a bean with scope @Dependent
- * via dependency injection or by calling Manager.getInstance(),
- * Manager.getInstanceByType() or Instance.get() when the @Dependent scope is
- * active.
- */
- @Test(groups = { "stub", "contexts", "servlet", "initializerMethod" })
- @SpecAssertion(section = "8.3.1", id = "unknown")
- public void testServletBeanMayCreateInstanceWheneverScopeIsActive()
- {
- assert false;
- }
-
- /**
* destroy all dependent objects of a contextual bean instance when the
* instance is destroyed,
*/
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/HorseInStableEvent.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/HorseInStableEvent.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/HorseInStableEvent.java 2009-02-04 21:32:20 UTC (rev 1416)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.unit.context.dependent;
+
+class HorseInStableEvent
+{
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/HorseInStableEvent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/HorseStable.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/HorseStable.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/HorseStable.java 2009-02-04 21:32:20 UTC (rev 1416)
@@ -0,0 +1,39 @@
+package org.jboss.webbeans.tck.unit.context.dependent;
+
+import javax.context.Dependent;
+import javax.event.Observes;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
+
+ at Dependent
+class HorseStable
+{
+ @Current
+ private Manager manager;
+ private static boolean dependentContextActive = false;
+ private static HorseStable instanceThatObservedEvent = null;
+
+ public void horseEntered(@Observes HorseInStableEvent horseEvent)
+ {
+ if (manager.getContext(Dependent.class).isActive())
+ {
+ dependentContextActive = true;
+ }
+ instanceThatObservedEvent = this;
+ }
+
+ public static boolean isDependentContextActive()
+ {
+ return HorseStable.dependentContextActive;
+ }
+
+ public static void setDependentContextActive(boolean dependentContextActive)
+ {
+ HorseStable.dependentContextActive = dependentContextActive;
+ }
+
+ public static HorseStable getInstanceThatObservedEvent()
+ {
+ return instanceThatObservedEvent;
+ }
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/HorseStable.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/SpiderProducer.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/SpiderProducer.java 2009-02-04 19:34:41 UTC (rev 1415)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/SpiderProducer.java 2009-02-04 21:32:20 UTC (rev 1416)
@@ -1,17 +1,50 @@
package org.jboss.webbeans.tck.unit.context.dependent;
+import javax.context.Dependent;
+import javax.inject.Current;
import javax.inject.Disposes;
import javax.inject.Produces;
+import javax.inject.manager.Manager;
class SpiderProducer
{
+ @Current
+ private Manager manager;
+
+ private static boolean dependentContextActive = false;
+
+ private static SpiderProducer instanceUsedForDisposal = null;
+
@Produces public Tarantula produceTarantula()
{
+ if (manager.getContext(Dependent.class).isActive())
+ {
+ dependentContextActive = true;
+ }
return new Tarantula();
}
public void disposeTarantula(@Disposes Tarantula tarantula)
{
-
+ if (manager.getContext(Dependent.class).isActive())
+ {
+ dependentContextActive = true;
+ }
+ instanceUsedForDisposal = this;
}
+
+ public static boolean isDependentContextActive()
+ {
+ return dependentContextActive;
+ }
+
+ public static void setDependentContextActive(boolean dependentContextActive)
+ {
+ SpiderProducer.dependentContextActive = dependentContextActive;
+ }
+
+ public static SpiderProducer getInstanceUsedForDisposal()
+ {
+ return instanceUsedForDisposal;
+ }
}
More information about the weld-commits
mailing list