You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2018/11/20 07:07:40 UTC

[2/2] incubator-tamaya-extensions git commit: TAMAYA-350 Fixed handling of null values in yaml.

TAMAYA-350 Fixed handling of null values in yaml.


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/ee00d2ef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/ee00d2ef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/ee00d2ef

Branch: refs/heads/master
Commit: ee00d2ef21d9f14fe7021a771b43eb910712a4fd
Parents: d1364a4
Author: Anatole Tresch <at...@gmail.com>
Authored: Tue Nov 20 08:07:10 2018 +0100
Committer: Anatole Tresch <at...@gmail.com>
Committed: Tue Nov 20 08:07:10 2018 +0100

----------------------------------------------------------------------
 .../java/org/apache/tamaya/yaml/YAMLFormat.java |  6 ++++-
 .../org/apache/tamaya/yaml/YAMLFormatTest.java  | 25 +++++++++++++++++---
 .../test/resources/configs/valid/contact.yaml   |  3 ++-
 3 files changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee00d2ef/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLFormat.java b/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLFormat.java
index d8b59bd..4c50573 100644
--- a/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLFormat.java
+++ b/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLFormat.java
@@ -98,7 +98,11 @@ public class YAMLFormat implements ConfigurationFormat {
                 ObjectValue object = dataNode.setFieldObject(en.getKey());
                 addObject((Map) en.getValue(), object);
             } else{
-                dataNode.setField(en.getKey(), String.valueOf(en.getValue()));
+                if (en.getValue() == null) {
+                    dataNode.setField(en.getKey(), null);
+                }else {
+                    dataNode.setField(en.getKey(), String.valueOf(en.getValue()));
+                }
             }
         });
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee00d2ef/modules/formats/yaml/src/test/java/org/apache/tamaya/yaml/YAMLFormatTest.java
----------------------------------------------------------------------
diff --git a/modules/formats/yaml/src/test/java/org/apache/tamaya/yaml/YAMLFormatTest.java b/modules/formats/yaml/src/test/java/org/apache/tamaya/yaml/YAMLFormatTest.java
index 52f7149..098520f 100644
--- a/modules/formats/yaml/src/test/java/org/apache/tamaya/yaml/YAMLFormatTest.java
+++ b/modules/formats/yaml/src/test/java/org/apache/tamaya/yaml/YAMLFormatTest.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.yaml;
 
 
 import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.spi.PropertyValue;
 import org.junit.Test;
 
 import java.io.IOException;
@@ -27,9 +28,7 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Map;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 public class YAMLFormatTest {
     private final YAMLFormat format = new YAMLFormat();
@@ -65,4 +64,24 @@ public class YAMLFormatTest {
         }
     }
 
+    @Test
+    public void testRead_nullValues() throws IOException {
+    	URL configURL = getContactYaml();
+        ConfigurationData data = loadConfigurationData(configURL);
+        for(PropertyValue val:data.getData()){
+            if(val.getKey().equals("summary")){
+                fail("Contains null yaml value");
+            }
+        }
+    }
+
+	private ConfigurationData loadConfigurationData(URL configURL) throws IOException {
+		return format.readConfiguration(configURL.toString(), configURL.openStream());
+	}
+
+	private URL getContactYaml() {
+		URL configURL = YAMLPropertySourceTest.class.getResource("/configs/valid/contact.yaml");
+		return configURL;
+	}
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee00d2ef/modules/formats/yaml/src/test/resources/configs/valid/contact.yaml
----------------------------------------------------------------------
diff --git a/modules/formats/yaml/src/test/resources/configs/valid/contact.yaml b/modules/formats/yaml/src/test/resources/configs/valid/contact.yaml
index 0cd332c..ddba38a 100644
--- a/modules/formats/yaml/src/test/resources/configs/valid/contact.yaml
+++ b/modules/formats/yaml/src/test/resources/configs/valid/contact.yaml
@@ -46,4 +46,5 @@ total: 4443.52
 comments: >
     Late afternoon is best.
     Backup contact is Nancy
-    Billsmer @ 338-4338.
\ No newline at end of file
+    Billsmer @ 338-4338.
+summary:
\ No newline at end of file