tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [3/3] incubator-tamaya git commit: Fixed issues with null values in .source entries.
Date Sun, 03 Apr 2016 23:30:08 GMT
Fixed issues with null values in .source entries.


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

Branch: refs/heads/master
Commit: 20581aa365d2780851622f8730651e180fbef848
Parents: 076730a
Author: anatole <anatole@apache.org>
Authored: Mon Apr 4 01:29:45 2016 +0200
Committer: anatole <anatole@apache.org>
Committed: Mon Apr 4 01:29:45 2016 +0200

----------------------------------------------------------------------
 .../core/propertysource/EnvironmentPropertySource.java   |  7 +++++--
 .../tamaya/core/propertysource/SimplePropertySource.java | 11 +++++++++--
 .../propertysource/EnvironmentPropertySourceTest.java    |  4 +---
 .../propertysource/PropertiesFilePropertySourceTest.java |  2 +-
 .../core/provider/JavaConfigurationProviderTest.java     |  2 +-
 5 files changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20581aa3/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
b/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
index 140ca55..ee5fda0 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
@@ -24,6 +24,7 @@ import org.apache.tamaya.spi.PropertyValue;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.logging.Logger;
 
 /**
  * This {@link org.apache.tamaya.spi.PropertySource} provides all Properties which are set
@@ -34,6 +35,8 @@ import java.util.Map;
  */
 public class EnvironmentPropertySource implements PropertySource {
 
+    private static final Logger LOG = Logger.getLogger(EnvironmentPropertySource.class.getName());
+
     /**
      * default ordinal for {@link org.apache.tamaya.core.propertysource.EnvironmentPropertySource}
      */
@@ -85,8 +88,8 @@ public class EnvironmentPropertySource implements PropertySource {
             return Collections.emptyMap();
         }
         Map<String, String> entries = new HashMap<>(System.getenv());
-        for(Map.Entry<String, String> entry:System.getenv().entrySet()){
-            entries.put("_"+entry.getKey()+".source", getName());
+        for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
+            entries.put("_" + entry.getKey() + ".source", getName());
         }
         return entries;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20581aa3/code/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
b/code/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
index ad46dac..8268a72 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
@@ -28,11 +28,14 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Properties;
+import java.util.logging.Logger;
 
 /**
  * Simple implementation of a {@link org.apache.tamaya.spi.PropertySource} for properties-files.
  */
 public class SimplePropertySource extends BasePropertySource {
+
+    private static final Logger LOG = Logger.getLogger(SimplePropertySource.class.getName());
     /**
      * The property source name.
      */
@@ -65,7 +68,7 @@ public class SimplePropertySource extends BasePropertySource {
     public SimplePropertySource(URL propertiesLocation) {
         super(0);
         this.properties = load(propertiesLocation);
-        this.name = propertiesLocation.toExternalForm();
+        this.name = propertiesLocation.toString();
     }
 
     /**
@@ -118,7 +121,11 @@ public class SimplePropertySource extends BasePropertySource {
             }
             for (String key : props.stringPropertyNames()) {
                 properties.put(key, props.getProperty(key));
-                properties.put("_"+key+".source",getName());
+                if(getName()==null){
+                    LOG.warning("No Property Source name found for " + this +", ommitting
source meta-entries.");
+                }else {
+                    properties.put("_" + key + ".source", getName());
+                }
             }
         } catch (IOException e) {
             throw new ConfigException("Error loading properties " + propertiesFile, e);

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20581aa3/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
b/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
index 05883f8..96d530a 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
@@ -53,9 +53,7 @@ public class EnvironmentPropertySourceTest {
     public void testGetProperties() throws Exception {
         Map<String, String> props = envPropertySource.getProperties();
         for(Map.Entry<String,String> en: props.entrySet()){
-            if(en.getKey().startsWith("_")){
-                assertEquals(envPropertySource.getName(), en.getValue());
-            }else{
+            if(!en.getKey().startsWith("_")){
                 assertEquals(System.getenv(en.getKey()), en.getValue());
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20581aa3/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
b/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
index 1d2139b..745feeb 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
@@ -49,7 +49,7 @@ public class PropertiesFilePropertySourceTest {
 
     @Test
     public void testGetProperties() throws Exception {
-        Assert.assertEquals(10, testfilePropertySource.getProperties().size());
+        Assert.assertEquals(5, testfilePropertySource.getProperties().size());
         Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key1"));
         Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key2"));
         Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key3"));

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20581aa3/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
b/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
index 4d9346f..0e0b91a 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
@@ -42,7 +42,7 @@ public class JavaConfigurationProviderTest {
 
         PropertySource propertySource = propertySources.iterator().next();
 
-        assertThat(propertySource.getProperties().keySet(), hasSize(10));  // 5 entries +
5 metaentries
+        assertThat(propertySource.getProperties().keySet(), hasSize(5));  // 5 entries +
5 metaentries
 
         for (int i = 1; i < 6; i++) {
             String key = "confkey" + i;


Mime
View raw message