tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [10/11] incubator-tamaya-extensions git commit: TAMAYA-235: Added tests for section method. Fixed invalid key mapping.
Date Sun, 26 Feb 2017 23:05:23 GMT
TAMAYA-235: Added tests for section method. Fixed invalid key mapping.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/d763fa04
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/d763fa04
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/d763fa04

Branch: refs/heads/master
Commit: d763fa0422fbe9f66f261c810dbbd3bdc1092654
Parents: 6805cba
Author: anatole <anatole@apache.org>
Authored: Sun Feb 26 23:47:40 2017 +0100
Committer: anatole <anatole@apache.org>
Committed: Mon Feb 27 00:05:00 2017 +0100

----------------------------------------------------------------------
 .../functions/ConfigurationFunctions.java       |  2 +-
 .../functions/ConfigurationFunctionsTest.java   | 46 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/d763fa04/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
index 97934f6..ccb6396 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
@@ -240,7 +240,7 @@ public final class ConfigurationFunctions {
                             if(key.startsWith(areaKey)) {
                                 return key.substring(areaKey.length());
                             }
-                            return null;
+                            return areaKey + key;
                         }
                     }, "stripped");
                 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/d763fa04/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
b/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
index 93a7da9..5aa6995 100644
--- a/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
+++ b/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
@@ -19,8 +19,16 @@
 package org.apache.tamaya.functions;
 
 import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.core.propertysource.EnvironmentPropertySource;
+import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
 import org.junit.Test;
 
+import java.io.PrintStream;
+import java.util.Map;
+import java.util.TreeMap;
+
 import static org.junit.Assert.*;
 
 /**
@@ -140,4 +148,42 @@ public class ConfigurationFunctionsTest {
         assertNotNull(ps.getProperties());
         assertTrue(ps.getProperties().isEmpty());
     }
+
+    /**
+     * See https://issues.apache.org/jira/browse/TAMAYA-235
+     */
+    @Test
+    public void testSection_StripKeys() {
+        testSection(true);
+    }
+
+    /**
+     * See https://issues.apache.org/jira/browse/TAMAYA-235
+     */
+    @Test
+    public void testSection_NoStripKeys() {
+        testSection(false);
+    }
+
+    private void testSection(boolean stripKeys){
+        ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder();
+        b.addPropertySources(new EnvironmentPropertySource(), new SystemPropertySource());
+        Configuration cfg = ConfigurationProvider.createConfiguration(b.build()).with(
+                ConfigurationFunctions.section("java.", stripKeys));
+        System.out.println("*****************************************************");
+        System.out.println("stripKeys: " + stripKeys);
+        System.out.println("*****************************************************");
+        dump(cfg.getProperties(), System.out);
+        System.out.println();
+        System.out.println("Example Metadata:");
+        System.out.println("\tjava.version         :  " + cfg.get("java.version"));
+        System.out.println("\tversion                 :  " + cfg.get("version"));
+    }
+
+    private void dump(Map<String, String> properties, PrintStream stream) {
+        stream.println("FULL DUMP:");
+        for (Map.Entry<String, String> en : new TreeMap<>(properties).entrySet())
{
+            stream.println("\t" + en.getKey() + " = " + en.getValue());
+        }
+    }
 }
\ No newline at end of file


Mime
View raw message