deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject deltaspike git commit: DELTASPIKE-1116 allow conditional replacement of injection-points in test-classes
Date Sat, 23 Apr 2016 09:41:46 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 8f9441fcb -> 67ed43ba6


DELTASPIKE-1116 allow conditional replacement of injection-points in test-classes


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

Branch: refs/heads/master
Commit: 67ed43ba687466a4c7b3aea20de9e5a12bd50641
Parents: 8f9441f
Author: gpetracek <gpetracek@apache.org>
Authored: Sat Apr 23 11:34:24 2016 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Sat Apr 23 11:34:24 2016 +0200

----------------------------------------------------------------------
 .../deltaspike/testcontrol/api/junit/CdiTestRunner.java  |  7 ++++++-
 .../deltaspike/testcontrol/api/junit/TestBaseConfig.java | 11 +++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/67ed43ba/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 2baf5a5..8cd2593 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
@@ -78,12 +78,14 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
     private static final Logger LOGGER = Logger.getLogger(CdiTestRunner.class.getName());
 
     private static final boolean USE_TEST_CLASS_AS_CDI_BEAN;
+    private static final boolean ALLOW_INJECTION_POINT_MANIPULATION;
 
     private static Set<Integer> notifierIdentities = new CopyOnWriteArraySet<Integer>();
 
     static
     {
         USE_TEST_CLASS_AS_CDI_BEAN = TestBaseConfig.ContainerIntegration.USE_TEST_CLASS_AS_CDI_BEAN;
+        ALLOW_INJECTION_POINT_MANIPULATION = TestBaseConfig.MockIntegration.ALLOW_MANUAL_INJECTION_POINT_MANIPULATION;
     }
 
     private static ThreadLocal<Boolean> automaticScopeHandlingActive = new ThreadLocal<Boolean>();
@@ -309,7 +311,10 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
 
             if (!USE_TEST_CLASS_AS_CDI_BEAN || beans == null || beans.isEmpty())
             {
-                BeanProvider.injectFields(this.originalTarget); //fallback to simple injection
+                if (!ALLOW_INJECTION_POINT_MANIPULATION)
+                {
+                    BeanProvider.injectFields(this.originalTarget); //fallback to simple
injection
+                }
                 invokeMethod(this.originalTarget);
             }
             else

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/67ed43ba/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/TestBaseConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/TestBaseConfig.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/TestBaseConfig.java
index 7c1c70f..35c8d36 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/TestBaseConfig.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/TestBaseConfig.java
@@ -43,6 +43,8 @@ public interface TestBaseConfig extends DeltaSpikeBaseConfig
     {
         String ALLOW_MOCKED_BEANS_KEY = "deltaspike.testcontrol.mock-support.allow_mocked_beans";
         String ALLOW_MOCKED_PRODUCERS_KEY = "deltaspike.testcontrol.mock-support.allow_mocked_producers";
+        String ALLOW_MANUAL_INJECTION_POINT_MANIPULATION_KEY =
+            "deltaspike.testcontrol.mock-support.allow_manual_injection-point_manipulation";
 
         Boolean ALLOW_MOCKED_BEANS = ConfigResolver.resolve(ALLOW_MOCKED_BEANS_KEY)
                 .as(Boolean.class)
@@ -56,5 +58,14 @@ public interface TestBaseConfig extends DeltaSpikeBaseConfig
                 .withDefault(Boolean.FALSE)
                 .getValue();
 
+        //if enabled it's possible to change the value of injection-points after the injection-process
and
+        //before test-execution. that allows to replace injection-points (e.g. with a mock)
conditionally
+        //via a test-rule or @Before
+        Boolean ALLOW_MANUAL_INJECTION_POINT_MANIPULATION =
+            ConfigResolver.resolve(ALLOW_MANUAL_INJECTION_POINT_MANIPULATION_KEY)
+                .as(Boolean.class)
+                .withCurrentProjectStage(true)
+                .withDefault(Boolean.FALSE)
+                .getValue();
     }
 }


Mime
View raw message