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-1147 try to make TypedResolver behave the same way like ConfigResolver
Date Tue, 17 May 2016 16:58:58 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 138eec616 -> c25a89f1d


DELTASPIKE-1147 try to make TypedResolver behave the same way like ConfigResolver


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

Branch: refs/heads/master
Commit: c25a89f1dd0ab8654396acedb60e1e1975386a41
Parents: 138eec6
Author: Mark Struberg <struberg@apache.org>
Authored: Tue May 17 18:57:06 2016 +0200
Committer: Mark Struberg <struberg@apache.org>
Committed: Tue May 17 18:58:02 2016 +0200

----------------------------------------------------------------------
 .../deltaspike/core/api/config/ConfigResolver.java       | 11 +++++++++--
 .../deltaspike/test/api/config/ConfigResolverTest.java   |  7 ++++++-
 .../deltaspike/test/api/config/TestConfigSource.java     |  2 ++
 3 files changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c25a89f1/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
index a2b8ed6..778614b 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
@@ -171,6 +171,7 @@ public final class ConfigResolver
         return getPropertyValue(key, defaultValue, true);
     }
 
+
     public static String getPropertyValue(String key, String defaultValue, boolean evaluateVariables)
     {
         String value = getPropertyValue(key, evaluateVariables);
@@ -759,6 +760,7 @@ public final class ConfigResolver
 
         private Class<?> configEntryType = String.class;
 
+        private boolean withDefault = false;
         private T defaultValue;
 
         private boolean projectStageAware = true;
@@ -810,6 +812,7 @@ public final class ConfigResolver
         public TypedResolver<T> withDefault(T value)
         {
             defaultValue = value;
+            withDefault = true;
             return this;
         }
 
@@ -823,6 +826,7 @@ public final class ConfigResolver
             }
 
             defaultValue = convert(value);
+            withDefault = true;
             return this;
         }
 
@@ -898,7 +902,10 @@ public final class ConfigResolver
             String valueStr = resolveStringValue();
             T value = convert(valueStr);
 
-            value = fallbackToDefaultIfEmpty(keyResolved, value, defaultValue);
+            if (withDefault)
+            {
+                value = fallbackToDefaultIfEmpty(keyResolved, value, defaultValue);
+            }
 
             if (logChanges && (value != null && !value.equals(lastValue)
|| (value == null && lastValue != null)) )
             {
@@ -969,7 +976,7 @@ public final class ConfigResolver
             }
 
             // make initial resolution of longest key
-            value = getPropertyValue(keyResolved, null, evaluateVariables);
+            value = getPropertyValue(keyResolved, evaluateVariables);
 
             // try fallbacks if not strictly
             if (value == null && !strictly)

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c25a89f1/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
index 6afdce7..66c288a 100644
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/ConfigResolverTest.java
@@ -28,7 +28,6 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.util.List;
-import java.util.concurrent.TimeUnit;
 
 public class ConfigResolverTest
 {
@@ -82,6 +81,12 @@ public class ConfigResolverTest
         Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey3", null));
         Assert.assertEquals("", ConfigResolver.getProjectStageAwarePropertyValue("testkey3"));
         Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.getProjectStageAwarePropertyValue("testkey3",
DEFAULT_VALUE));
+
+        Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.getProjectStageAwarePropertyValue("deltaspike.test.projectstagefallback",
DEFAULT_VALUE));
+        Assert.assertEquals("", ConfigResolver.getProjectStageAwarePropertyValue("deltaspike.test.projectstagefallback"));
+
+        Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.resolve("deltaspike.test.projectstagefallback").as(String.class).withDefault(DEFAULT_VALUE).withCurrentProjectStage(true).getValue());
+        Assert.assertEquals("", ConfigResolver.resolve("deltaspike.test.projectstagefallback").as(String.class).withCurrentProjectStage(true).getValue());
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/c25a89f1/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
index c0f34c7..e5e4e28 100644
--- a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/config/TestConfigSource.java
@@ -89,6 +89,8 @@ public class TestConfigSource implements ConfigSource
         props.put("deltaspike.test.recursive.variable2", "pre-${deltaspike.test.recursive.variable3}-post");
         props.put("deltaspike.test.recursive.variable3", "crazy");
 
+        props.put("deltaspike.test.projectstagefallback.UnitTest", "");
+        props.put("deltaspike.test.projectstagefallback", "Value without ProjectStage");
     }
 
     @Override


Mime
View raw message