[webbeans-commits] Webbeans SVN: r1423 - tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu Feb 5 13:33:40 EST 2009


Author: dallen6
Date: 2009-02-05 13:33:40 -0500 (Thu, 05 Feb 2009)
New Revision: 1423

Added:
   tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/SensitiveFox.java
Modified:
   tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/DependentContextTest.java
Log:
Implemented more of the dependent context tests.

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-05 13:45:36 UTC (rev 1422)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/DependentContextTest.java	2009-02-05 18:33:40 UTC (rev 1423)
@@ -29,11 +29,9 @@
       deployBeans(Fox.class, FoxRun.class);
       Set<Bean<Fox>> foxBeans = manager.resolveByType(Fox.class);
       assert foxBeans.size() == 1;
-      Bean<Fox> foxBean = foxBeans.iterator().next();
       Set<Bean<FoxRun>> foxRunBeans = manager.resolveByType(FoxRun.class);
       assert foxRunBeans.size() == 1;
       Bean<FoxRun> foxRunBean = foxRunBeans.iterator().next();
-      manager.addBean(foxBean);
       FoxRun foxRun = foxRunBean.create(new MyCreationalContext<FoxRun>());
       assert !foxRun.fox.equals(foxRun.anotherFox);
    }
@@ -41,12 +39,17 @@
    /**
     * Any injected instance of the (@Dependent scoped) bean is bound to the
     * lifecycle of the bean, servlet or EJB into which it is injected.
+    * 
+    * @throws Exception
     */
-   @Test(groups = { "contexts", "stub" })
+   @Test(groups = { "contexts" })
    @SpecAssertion(section = "8.3", id = "unknown")
-   public void testDependentBeansBoundToLifecycleOfContainingBean()
+   public void testDependentBeansBoundToLifecycleOfContainingBean() throws Exception
    {
-      assert false;
+      // Once injected, dependent beans will be destroyed when the
+      // containing bean is destroyed. This other test should
+      // satisfy this assertion.
+      testDestroyingParentDestroysDependents();
    }
 
    /**
@@ -65,8 +68,6 @@
          {
             Set<Bean<Fox>> foxBeans = manager.resolveByType(Fox.class);
             assert foxBeans.size() == 1;
-            Bean<Fox> foxBean = foxBeans.iterator().next();
-            manager.addBean(foxBean);
 
             Fox fox1 = configuration().getContainers().evaluateValueExpression("#{fox}", Fox.class);
             Fox fox2 = configuration().getContainers().evaluateValueExpression("#{fox}", Fox.class);
@@ -250,10 +251,12 @@
     * container to receive a producer method, producer field, disposal method or
     * observer method invocation, or
     */
-   @Test(groups = { "stub", "contexts", "producerField" })
+   @Test(groups = { "stub", "contexts", "producerField", "underInvestigation" })
    @SpecAssertion(section = "8.3", id = "unknown")
    public void testContextIsActiveWhenInvokingProducerField()
    {
+      // TODO Rather difficult to detect anything when a producer field is
+      // accessed
       assert false;
    }
 
@@ -291,12 +294,24 @@
 
    /**
     * while a Unified EL expression is evaluated, or
+    * @throws Exception 
     */
-   @Test(groups = { "stub", "contexts", "el" })
+   @Test(groups = { "contexts", "el" })
    @SpecAssertion(section = "8.3", id = "unknown")
-   public void testContextIsActiveWhenEvaluatingElExpression()
+   public void testContextIsActiveWhenEvaluatingElExpression() throws Exception
    {
-      assert false;
+      deployBeans(SensitiveFox.class);
+      SensitiveFox.setManager(manager);
+      new RunInDependentContext()
+      {
+         @Override
+         protected void execute() throws Exception
+         {
+            String foxName = configuration().getContainers().evaluateMethodExpression("#{sensitiveFox.getName}", String.class, new Class[0], new Object[0]);
+            assert foxName != null;
+            assert SensitiveFox.isDependentContextActiveDuringEval();
+         }
+      }.run();
    }
 
    /**
@@ -314,24 +329,41 @@
    /**
     * when the container is creating or destroying a contextual instance of a
     * bean or injecting its dependencies, or
+    * 
+    * @throws Exception
     */
-   @Test(groups = { "stub", "contexts", "beanLifecycle" })
+   @Test(groups = { "contexts", "beanLifecycle" })
    @SpecAssertion(section = "8.3", id = "unknown")
-   public void testContextIsActiveDuringBeanCreation()
+   public void testContextIsActiveDuringBeanCreation() throws Exception
    {
-      //TODO Previous test was not testing that context was active precisely
-      assert false;
+      deployBeans(SensitiveFox.class);
+      SensitiveFox.setManager(manager);
+      new RunInDependentContext()
+      {
+
+         @Override
+         protected void execute() throws Exception
+         {
+            SensitiveFox fox1 = manager.getInstanceByType(SensitiveFox.class);
+            assert fox1 != null;
+            assert fox1.isDependentContextActiveDuringCreate();
+         }
+
+      }.run();
    }
 
    /**
     * when the container is creating or destroying a contextual instance of a
     * bean or injecting its dependencies, or
     */
-   @Test(groups = { "stub", "contexts", "beanDestruction" })
+   @Test(groups = { "broken", "contexts", "beanDestruction" })
    @SpecAssertion(section = "8.3", id = "unknown")
    public void testContextIsActiveDuringBeanDestruction()
    {
-      assert false;
+      // Since the only way to check the context during bean
+      // destruction is to have a disposal method, we'll use
+      // that test to verify this behavior.
+      this.testContextIsActiveWhenInvokingDisposalMethod();
    }
 
    /**
@@ -351,79 +383,185 @@
    /**
     * destroy all dependent objects of a contextual bean instance when the
     * instance is destroyed,
+    * 
+    * @throws Exception
     */
-   @Test(groups = { "broken", "contexts", "beanDestruction" })
+   @Test(groups = { "contexts", "beanDestruction" })
    @SpecAssertion(section = "8.3.2", id = "unknown")
-   public void testDestroyingParentDestroysDependents()
+   public void testDestroyingParentDestroysDependents() throws Exception
    {
       deployBeans(Farm.class, Horse.class, Stable.class);
-      assert manager.resolveByType(Farm.class).size() == 1;
-      Bean<Farm> farmBean = manager.resolveByType(Farm.class).iterator().next();
-      Farm farm = manager.getInstanceByType(Farm.class);
-      Stable.destroyed = false;
-      Horse.destroyed = false;
-      farmBean.destroy(farm);
-      assert Stable.destroyed;
-      assert Horse.destroyed;
+      new RunInDependentContext()
+      {
+
+         @Override
+         protected void execute() throws Exception
+         {
+            assert manager.resolveByType(Farm.class).size() == 1;
+            Bean<Farm> farmBean = manager.resolveByType(Farm.class).iterator().next();
+            Farm farm = manager.getInstanceByType(Farm.class);
+            Stable.destroyed = false;
+            Horse.destroyed = false;
+            farmBean.destroy(farm);
+            assert Stable.destroyed;
+            assert Horse.destroyed;
+         }
+
+      }.run();
    }
 
    /**
     * destroy all @Dependent scoped contextual instances created during an EL
     * expression evaluation when the evaluation completes, and
+    * 
+    * @throws Exception
     */
-   @Test(groups = { "stub", "contexts", "el" })
+   @Test(groups = { "contexts", "el" })
    @SpecAssertion(section = "8.3.2", id = "unknown")
-   public void testDependentsDestroyedWhenElEvaluationCompletes()
+   public void testDependentsDestroyedWhenElEvaluationCompletes() throws Exception
    {
-      assert false;
+      deployBeans(Fox.class);
+      new RunInDependentContext()
+      {
+         @Override
+         protected void execute() throws Exception
+         {
+            Set<Bean<Fox>> foxBeans = manager.resolveByType(Fox.class);
+            assert foxBeans.size() == 1;
+            Bean<Fox> foxBean = foxBeans.iterator().next();
+
+            Fox fox1 = configuration().getContainers().evaluateValueExpression("#{fox}", Fox.class);
+            assert fox1 != null;
+            assert manager.getContext(Dependent.class).get(foxBean) == null;
+         }
+      }.run();
    }
 
    /**
     * destroy any @Dependent scoped contextual instance created to receive a
     * producer method, producer field, disposal method or observer method
     * invocation when the invocation completes
+    * 
+    * @throws Exception
     */
-   @Test(groups = { "stub", "contexts", "producerMethod" })
+   @Test(groups = { "contexts", "producerMethod" })
    @SpecAssertion(section = "8.3.2", id = "unknown")
-   public void testDependentsDestroyedWhenProducerMethodCompletes()
+   public void testDependentsDestroyedWhenProducerMethodCompletes() throws Exception
    {
-      assert false;
+      deployBeans(SpiderProducer.class);
+      new RunInDependentContext()
+      {
+
+         @Override
+         protected void execute() throws Exception
+         {
+            Bean<SpiderProducer> spiderProducer = manager.resolveByType(SpiderProducer.class).iterator().next();
+            Context dependentContext = manager.getContext(Dependent.class);
+            SpiderProducer currentSpiderProducerInstance = dependentContext.get(spiderProducer);
+            // Should not have any instance of this bean yet
+            assert currentSpiderProducerInstance == null;
+            Tarantula spiderInstance = manager.getInstanceByType(Tarantula.class);
+            assert spiderInstance != null;
+            currentSpiderProducerInstance = dependentContext.get(spiderProducer);
+            // Still should not have any instance of this bean (already
+            // destroyed)
+            assert currentSpiderProducerInstance == null;
+         }
+
+      }.run();
    }
 
    /**
     * destroy any @Dependent scoped contextual instance created to receive a
     * producer method, producer field, disposal method or observer method
     * invocation when the invocation completes
+    * 
+    * @throws Exception
     */
-   @Test(groups = { "stub", "contexts", "producerField" })
+   @Test(groups = { "contexts", "producerField" })
    @SpecAssertion(section = "8.3.2", id = "unknown")
-   public void testDependentsDestroyedWhenProducerFieldCompletes()
+   public void testDependentsDestroyedWhenProducerFieldCompletes() throws Exception
    {
-      assert false;
+      deployBeans(OtherSpiderProducer.class);
+      new RunInDependentContext()
+      {
+
+         @Override
+         protected void execute() throws Exception
+         {
+            Bean<OtherSpiderProducer> spiderProducer = manager.resolveByType(OtherSpiderProducer.class).iterator().next();
+            Context dependentContext = manager.getContext(Dependent.class);
+            OtherSpiderProducer currentSpiderProducerInstance = dependentContext.get(spiderProducer);
+            // Should not have any instance of this bean yet
+            assert currentSpiderProducerInstance == null;
+            Tarantula spiderInstance = manager.getInstanceByType(Tarantula.class);
+            assert spiderInstance != null;
+            currentSpiderProducerInstance = dependentContext.get(spiderProducer);
+            // Still should not have any instance of this bean (already
+            // destroyed)
+            assert currentSpiderProducerInstance == null;
+         }
+
+      }.run();
    }
 
    /**
     * destroy any @Dependent scoped contextual instance created to receive a
     * producer method, producer field, disposal method or observer method
     * invocation when the invocation completes
+    * 
+    * @throws Exception
     */
-   @Test(groups = { "stub", "contexts", "disposalMethod" })
+   @Test(groups = { "contexts", "disposalMethod" })
    @SpecAssertion(section = "8.3.2", id = "unknown")
-   public void testDependentsDestroyedWhenDisposalMethodCompletes()
+   public void testDependentsDestroyedWhenDisposalMethodCompletes() throws Exception
    {
-      assert false;
+      deployBeans(SpiderProducer.class);
+      new RunInDependentContext()
+      {
+
+         @Override
+         protected void execute() throws Exception
+         {
+            Bean<SpiderProducer> spiderProducerBean = manager.resolveByType(SpiderProducer.class).iterator().next();
+            Bean<Tarantula> tarantulaBean = manager.resolveByType(Tarantula.class).iterator().next();
+            Tarantula tarantula = tarantulaBean.create(new MyCreationalContext<Tarantula>());
+            assert tarantula != null;
+            tarantulaBean.destroy(tarantula);
+            // No instance of this bean should exist
+            assert manager.getContext(Dependent.class).get(spiderProducerBean) == null;
+         }
+
+      }.run();
    }
 
    /**
     * destroy any @Dependent scoped contextual instance created to receive a
     * producer method, producer field, disposal method or observer method
     * invocation when the invocation completes
+    * 
+    * @throws Exception
     */
-   @Test(groups = { "stub", "contexts", "observerMethod" })
+   @Test(groups = { "contexts", "observerMethod" })
    @SpecAssertion(section = "8.3", id = "unknown")
-   public void testDependentsDestroyedWhenObserverMethodEvaluationCompletes()
+   public void testDependentsDestroyedWhenObserverMethodEvaluationCompletes() throws Exception
    {
-      assert false;
+      deployBeans(HorseStable.class);
+      new RunInDependentContext()
+      {
+
+         @Override
+         protected void execute() throws Exception
+         {
+            Bean<HorseStable> horseStableBean = manager.resolveByType(HorseStable.class).iterator().next();
+            manager.fireEvent(new HorseInStableEvent());
+            assert HorseStable.getInstanceThatObservedEvent() != null;
+            HorseStable stableInstance = manager.getContext(Dependent.class).get(horseStableBean);
+            // The instance used for the event should be destroyed
+            assert stableInstance == null;
+         }
+
+      }.run();
    }
 
 }

Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/SensitiveFox.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/SensitiveFox.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/SensitiveFox.java	2009-02-05 18:33:40 UTC (rev 1423)
@@ -0,0 +1,49 @@
+package org.jboss.webbeans.tck.unit.context.dependent;
+
+import javax.annotation.Named;
+import javax.context.Dependent;
+import javax.inject.manager.Manager;
+
+ at Dependent
+ at Named
+public class SensitiveFox
+{
+   private static Manager manager;
+
+   private boolean dependentContextActiveDuringCreate = false;
+   
+   private static boolean dependentContextActiveDuringEval = false;
+
+   public SensitiveFox()
+   {
+      if (manager.getContext(Dependent.class).isActive())
+      {
+         dependentContextActiveDuringCreate = true;
+      }
+   }
+
+   public String getName()
+   {
+      if (manager.getContext(Dependent.class).isActive())
+      {
+         dependentContextActiveDuringEval = true;
+      }
+      return "gavin";
+   }
+
+   public boolean isDependentContextActiveDuringCreate()
+   {
+      return dependentContextActiveDuringCreate;
+   }
+
+   public static boolean isDependentContextActiveDuringEval()
+   {
+      return dependentContextActiveDuringEval;
+   }
+
+   public static void setManager(Manager manager)
+   {
+      SensitiveFox.manager = manager;
+   }
+
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/context/dependent/SensitiveFox.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the weld-commits mailing list