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:
Dave Syer
2015-05-19 10:53:51 +01:00
parent 641d5b40e8
commit e94b4039a6
4 changed files with 71 additions and 1 deletions

View File

@@ -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>();