deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject deltaspike git commit: DELTASPIKE-785 make CdiTestRunner configurable
Date Thu, 20 Nov 2014 10:42:54 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master ad138369b -> 449ec285b


DELTASPIKE-785 make CdiTestRunner configurable

This is really important to enable CdiTestRunner to pick up
DataSources and other stuff needed when running embedded EE containers.


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

Branch: refs/heads/master
Commit: 449ec285b28b0dbee9c49bc005ec0c7ebdcbcacf
Parents: ad13836
Author: Mark Struberg <struberg@apache.org>
Authored: Thu Nov 20 11:41:31 2014 +0100
Committer: Mark Struberg <struberg@apache.org>
Committed: Thu Nov 20 11:41:31 2014 +0100

----------------------------------------------------------------------
 .../testcontrol/api/junit/CdiTestRunner.java    | 27 +++++++++++++++++++-
 .../api/junit/CdiTestSuiteRunner.java           |  7 +++--
 2 files changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/449ec285/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 c91bafc..c6f12ef 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
@@ -23,6 +23,7 @@ import org.apache.deltaspike.cdise.api.CdiContainer;
 import org.apache.deltaspike.cdise.api.CdiContainerLoader;
 import org.apache.deltaspike.cdise.api.ContextControl;
 import org.apache.deltaspike.core.api.config.ConfigResolver;
+import org.apache.deltaspike.core.api.config.PropertyLoader;
 import org.apache.deltaspike.core.api.projectstage.ProjectStage;
 import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
 import org.apache.deltaspike.core.api.provider.BeanProvider;
@@ -57,6 +58,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Properties;
 import java.util.Set;
 import java.util.Stack;
 import java.util.concurrent.CopyOnWriteArraySet;
@@ -64,8 +66,23 @@ import java.util.logging.Handler;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+/**
+ * A JUnit test runner to start up with a CDI or embedded JavaEE container.
+ *
+ * <p>If the underlying container supports it you can even pass in  a property file
+ * to the bootstrap. You can configure the name of the configuration file via a
+ * {@link org.apache.deltaspike.core.api.config.ConfigResolver} property named
+ * <code>cdiTestRunnerConfig</code>. By default the name of the config file is
+ * <code>cdiTestRunnerConfig.properties</code>.</p>
+ */
 public class CdiTestRunner extends BlockJUnit4ClassRunner
 {
+    /**
+     * The configuration switch to define the configuration properties file.
+     * By default the property file which gets loaded has the exactly same name.
+     */
+    public static final String TEST_RUNNER_CONFIG = "cdiTestRunnerConfig";
+
     private static final Logger LOGGER = Logger.getLogger(CdiTestRunner.class.getName());
 
     private static final boolean USE_TEST_CLASS_AS_CDI_BEAN;
@@ -121,6 +138,14 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
         });
     }
 
+    public static Properties getTestContainerConfig()
+    {
+        String cdiTestRunnerConfig =
+                ConfigResolver.getProjectStageAwarePropertyValue(TEST_RUNNER_CONFIG, TEST_RUNNER_CONFIG);
+        return PropertyLoader.getProperties(cdiTestRunnerConfig);
+    }
+
+
     @Override
     public void run(RunNotifier runNotifier)
     {
@@ -452,7 +477,7 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
             {
                 if (!CdiTestSuiteRunner.isContainerStarted())
                 {
-                    container.boot();
+                    container.boot(getTestContainerConfig());
                     setContainerStarted();
 
                     bootExternalContainers(testClass);

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/449ec285/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
index 2cfd918..fc4448c 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestSuiteRunner.java
@@ -37,8 +37,10 @@ import java.util.logging.Logger;
 @SuppressWarnings("UnusedDeclaration")
 public class CdiTestSuiteRunner extends Suite
 {
+
     private static final boolean STOP_CONTAINER;
-    private static boolean containerStarted; //TODO
+
+    private static volatile boolean containerStarted; //TODO
 
     private final Class<?> testSuiteClass;
 
@@ -86,7 +88,7 @@ public class CdiTestSuiteRunner extends Suite
 
         if (!containerStarted)
         {
-            container.boot();
+            container.boot(CdiTestRunner.getTestContainerConfig());
             containerStarted = true;
         }
 
@@ -106,6 +108,7 @@ public class CdiTestSuiteRunner extends Suite
         }
     }
 
+
     public static boolean isContainerStarted()
     {
         return containerStarted;


Mime
View raw message