tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: resetting system properties by default for TomEEEmbeddedRule
Date Sun, 01 Mar 2015 19:59:00 GMT
Repository: tomee
Updated Branches:
  refs/heads/develop 0b0c97414 -> 59b2ecc7c


resetting system properties by default for TomEEEmbeddedRule


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

Branch: refs/heads/develop
Commit: 59b2ecc7cc087cd59c4536ccd4c92d346fe8cf60
Parents: 0b0c974
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Sun Mar 1 20:58:40 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Sun Mar 1 20:58:40 2015 +0100

----------------------------------------------------------------------
 .../tomee/embedded/junit/TomEEEmbeddedRule.java    | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/59b2ecc7/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedRule.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedRule.java
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedRule.java
index 83af365..c9cd6d8 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedRule.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/junit/TomEEEmbeddedRule.java
@@ -28,12 +28,14 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Properties;
 
 import static java.util.Arrays.asList;
 
 public class TomEEEmbeddedRule implements TestRule {
     private final Configuration configuration;
     private final File docBase;
+    private boolean resetSystemProperties = true;
     private final String context;
     private final Collection<Object> injects = new LinkedList<>();
 
@@ -64,6 +66,11 @@ public class TomEEEmbeddedRule implements TestRule {
         return this;
     }
 
+    public TomEEEmbeddedRule resetSystemPropertiesAfter(final boolean value) {
+        resetSystemProperties = value;
+        return this;
+    }
+
     public TomEEEmbeddedRule stopInjectionOn(final Object instance) {
         this.injects.remove(instance);
         return this;
@@ -85,12 +92,22 @@ public class TomEEEmbeddedRule implements TestRule {
         return new Statement() {
             @Override
             public void evaluate() throws Throwable {
+                final Properties properties = new Properties();
+                if (resetSystemProperties) {
+                    properties.putAll(System.getProperties());
+                }
+
                 try (final Container container = new Container(configuration)
                                      .deployClasspathAsWebApp(context, docBase, toCallers()))
{
                     for (final Object o : injects) {
                         container.inject(o);
                     }
                     statement.evaluate();
+                } finally {
+                    if (resetSystemProperties) { // issue is we set System Properties like
default loader which breaks other tests
+                        System.getProperties().clear();
+                        System.getProperties().putAll(properties);
+                    }
                 }
             }
         };


Mime
View raw message