Strip "document" prefix from YAML by default
It's pretty uncommon for Spring apps, but sometimes YAML is not a map, but more naturally a String or Collection. In these cases Spring puts a "document" prefix in the Map it creates, so we can strip that off if the user prefers it. Fixes gh-143
This commit is contained in:
@@ -91,6 +91,38 @@ public class EnvironmentControllerTests {
|
||||
assertEquals("a:\n b:\n - c\n - d\n", yaml);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void textAtTopLevelInYaml() throws Exception {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
map.put("document", "blah");
|
||||
environment.add(new PropertySource("one", map));
|
||||
Mockito.when(repository.findOne("foo", "bar", "master")).thenReturn(environment);
|
||||
String yaml = controller.yaml("foo", "bar").getBody();
|
||||
assertEquals("blah\n", yaml);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arrayAtTopLevelInYaml() throws Exception {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
map.put("document[0]", "c");
|
||||
map.put("document[1]", "d");
|
||||
environment.add(new PropertySource("one", map));
|
||||
Mockito.when(repository.findOne("foo", "bar", "master")).thenReturn(environment);
|
||||
String yaml = controller.yaml("foo", "bar").getBody();
|
||||
assertEquals("- c\n- d\n", yaml);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arrayObObjectAtTopLevelInYaml() throws Exception {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
map.put("document[0].a", "c");
|
||||
map.put("document[1].a", "d");
|
||||
environment.add(new PropertySource("one", map));
|
||||
Mockito.when(repository.findOne("foo", "bar", "master")).thenReturn(environment);
|
||||
String yaml = controller.yaml("foo", "bar").getBody();
|
||||
assertEquals("- a: c\n- a: d\n", yaml);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void arrayOfObjectInYaml() throws Exception {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
|
||||
Reference in New Issue
Block a user