Make sure non-string properties work.

fixes gh-128
This commit is contained in:
Spencer Gibb
2016-01-15 15:33:14 -07:00
parent 6a48795833
commit f8f2d87d0d
2 changed files with 8 additions and 8 deletions

View File

@@ -118,8 +118,8 @@ public class ConsulPropertySource extends EnumerablePropertySource<ConsulClient>
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());
}
}
}

View File

@@ -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) {