deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-466 startScope and stopScope for ExternalContainer
Date Thu, 12 Dec 2013 07:57:22 GMT
Updated Branches:
  refs/heads/master 307c757ae -> a00c7e2f6


DELTASPIKE-466 startScope and stopScope for ExternalContainer


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/a00c7e2f
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/a00c7e2f
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/a00c7e2f

Branch: refs/heads/master
Commit: a00c7e2f6869ef9a2ea010084ed20899fc009255
Parents: 307c757
Author: gpetracek <gpetracek@apache.org>
Authored: Thu Dec 12 08:41:05 2013 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Thu Dec 12 08:42:38 2013 +0100

----------------------------------------------------------------------
 .../testcontrol/api/junit/CdiTestRunner.java    | 35 +++++++++++++++++---
 .../testcontrol/spi/ExternalContainer.java      | 14 ++++++++
 2 files changed, 45 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/a00c7e2f/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
index 8093357..9b331a9 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
@@ -425,7 +425,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
                 restrictedScopes.add(SessionScoped.class);
             }
 
-            startContexts(container, restrictedScopes.toArray(new Class[restrictedScopes.size()]));
+            startScopes(container, restrictedScopes.toArray(new Class[restrictedScopes.size()]));
         }
 
         private void bootExternalContainers()
@@ -506,7 +506,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
             this.previousProjectStage = ProjectStageProducer.getInstance().getProjectStage();
             ProjectStageProducer.setProjectStage(this.projectStage);
 
-            startContexts(CdiContainerLoader.getCdiContainer());
+            startScopes(CdiContainerLoader.getCdiContainer());
         }
 
         void applyAfterMethodConfig()
@@ -528,7 +528,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
             CdiTestSuiteRunner.setContainerStarted(true);
         }
 
-        private void startContexts(CdiContainer container, Class<? extends Annotation>...
restrictedScopes)
+        private void startScopes(CdiContainer container, Class<? extends Annotation>...
restrictedScopes)
         {
             ContextControl contextControl = container.getContextControl();
 
@@ -555,9 +555,13 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
 
                 try
                 {
-                    contextControl.stopContext(scopeAnnotation); //force a clean context
+                    //force a clean context - TODO discuss onScopeStopped call
+                    contextControl.stopContext(scopeAnnotation);
+
                     contextControl.startContext(scopeAnnotation);
                     this.startedScopes.add(scopeAnnotation);
+
+                    onScopeStarted(scopeAnnotation);
                 }
                 catch (RuntimeException e)
                 {
@@ -615,6 +619,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
                 try
                 {
                     contextControl.stopContext(scopeAnnotation);
+                    onScopeStopped(scopeAnnotation);
                 }
                 catch (RuntimeException e)
                 {
@@ -624,5 +629,27 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
                 }
             }
         }
+
+        private void onScopeStarted(Class<? extends Annotation> scopeClass)
+        {
+            if (this.externalContainers != null)
+            {
+                for (ExternalContainer externalContainer : this.externalContainers)
+                {
+                    externalContainer.startScope(scopeClass);
+                }
+            }
+        }
+
+        private void onScopeStopped(Class<? extends Annotation> scopeClass)
+        {
+            if (this.externalContainers != null)
+            {
+                for (ExternalContainer externalContainer : this.externalContainers)
+                {
+                    externalContainer.stopScope(scopeClass);
+                }
+            }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/a00c7e2f/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/spi/ExternalContainer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/spi/ExternalContainer.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/spi/ExternalContainer.java
index ab4e8c8..250845f 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/spi/ExternalContainer.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/spi/ExternalContainer.java
@@ -18,6 +18,8 @@
  */
 package org.apache.deltaspike.testcontrol.spi;
 
+import java.lang.annotation.Annotation;
+
 public interface ExternalContainer
 {
     /**
@@ -31,4 +33,16 @@ public interface ExternalContainer
     void shutdown();
 
     int getOrdinal();
+
+    /**
+     * Signals a started scope
+     * @param scopeClass annotation-class of the scope
+     */
+    void startScope(Class<? extends Annotation> scopeClass);
+
+    /**
+     * Signals a stopped scope
+     * @param scopeClass annotation-class of the scope
+     */
+    void stopScope(Class<? extends Annotation> scopeClass);
 }


Mime
View raw message