Fix YAML endpoints when there are multiple property sources

Also affects properties endpoints. The order of property sources
should be reversed when creating the properties to mimic accurately
the behaviuour of Spring's Environment.

Fixes gh-71
This commit is contained in:
Dave Syer
2015-01-28 14:11:20 +00:00
parent e5e4cb0348
commit 8c2560b113
2 changed files with 14 additions and 1 deletions

View File

@@ -180,7 +180,9 @@ public class EnvironmentController {
private Properties convertToProperties(Environment profiles) {
Properties map = new Properties();
for (PropertySource source : profiles.getPropertySources()) {
List<PropertySource> sources = new ArrayList<PropertySource>(profiles.getPropertySources());
Collections.reverse(sources);
for (PropertySource source : sources) {
@SuppressWarnings("unchecked")
Map<String, String> value = (Map<String, String>) source.getSource();
map.putAll(value);

View File

@@ -60,6 +60,17 @@ public class EnvironmentControllerTests {
assertEquals("a:\n b:\n c: d\n", yaml);
}
@Test
public void propertyOverrideInYaml() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("a.b.c", "d");
environment.add(new PropertySource("one", map));
environment.addFirst(new PropertySource("two", Collections.singletonMap("a.b.c", "e")));
Mockito.when(repository.findOne("foo", "bar", "master")).thenReturn(environment);
String yaml = controller.yaml("foo", "bar").getBody();
assertEquals("a:\n b:\n c: e\n", yaml);
}
@Test
public void arrayInYaml() throws Exception {
Map<String, Object> map = new LinkedHashMap<String, Object>();