From f8f2d87d0d8767964cf68b1b2671c509c862f6b7 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Fri, 15 Jan 2016 15:33:14 -0700 Subject: [PATCH] Make sure non-string properties work. fixes gh-128 --- .../cloud/consul/config/ConsulPropertySource.java | 4 ++-- .../consul/config/ConsulPropertySourceTests.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java index a29c6c2e..033cf273 100644 --- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java +++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java @@ -118,8 +118,8 @@ public class ConsulPropertySource extends EnumerablePropertySource final String value = getDecoded(getValue.getValue()); final Properties props = generateProperties(value, format); - for (String propKey : props.stringPropertyNames()) { - properties.put(propKey, props.getProperty(propKey)); + for (Map.Entry entry : props.entrySet()) { + properties.put(entry.getKey().toString(), entry.getValue().toString()); } } } diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceTests.java index aaa4fdf7..f5886c8e 100644 --- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceTests.java +++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceTests.java @@ -57,11 +57,11 @@ public class ConsulPropertySourceTests { // key value properties kvContext = prefix + "/kv"; client.setKVValue(kvContext + "/fooprop", "fookvval"); - client.setKVValue(prefix+"/kv"+"/bar/prop", "barkvval"); + client.setKVValue(prefix+"/kv"+"/bar/prop", "8080"); ConsulPropertySource source = getConsulPropertySource(new ConsulConfigProperties(), kvContext); - assertProperties(source, "fookvval", "barkvval"); + assertProperties(source, "fookvval", "8080"); } private void assertProperties(ConsulPropertySource source, String fooval, String barval) { @@ -73,26 +73,26 @@ public class ConsulPropertySourceTests { public void testProperties() { // properties file property propertiesContext = prefix + "/properties"; - client.setKVValue(propertiesContext+"/data", "fooprop=foopropval\nbar.prop=barpropval"); + client.setKVValue(propertiesContext+"/data", "fooprop=foopropval\nbar.prop=8080"); ConsulConfigProperties configProperties = new ConsulConfigProperties(); configProperties.setFormat(ConsulConfigProperties.Format.PROPERTIES); ConsulPropertySource source = getConsulPropertySource(configProperties, propertiesContext); - assertProperties(source, "foopropval", "barpropval"); + assertProperties(source, "foopropval", "8080"); } @Test public void testYaml() { // yaml file property String yamlContext = prefix + "/yaml"; - client.setKVValue(yamlContext+"/data", "fooprop: fooymlval\nbar:\n prop: barymlval"); + client.setKVValue(yamlContext+"/data", "fooprop: fooymlval\nbar:\n prop: 8080"); ConsulConfigProperties configProperties = new ConsulConfigProperties(); configProperties.setFormat(ConsulConfigProperties.Format.YAML); ConsulPropertySource source = getConsulPropertySource(configProperties, yamlContext); - assertProperties(source, "fooymlval", "barymlval"); + assertProperties(source, "fooymlval", "8080"); } private ConsulPropertySource getConsulPropertySource(ConsulConfigProperties configProperties, String context) {