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:
@@ -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);
|
||||
|
||||
@@ -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>();
|
||||
|
||||
Reference in New Issue
Block a user