use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerTests method arrayOverridenInYaml.
@Test
public void arrayOverridenInYaml() throws Exception {
// Add original values first source
Map<String, Object> oneMap = new LinkedHashMap<String, Object>();
oneMap.put("a.b[0]", "c");
oneMap.put("a.b[1]", "d");
oneMap.put("a.b[2]", "z");
this.environment.add(new PropertySource("one", oneMap));
// Add overridden values in second source
Map<String, Object> twoMap = new LinkedHashMap<String, Object>();
twoMap.put("a.b[0]", "f");
twoMap.put("a.b[1]", "h");
this.environment.addFirst(new PropertySource("two", twoMap));
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
// Result will not contain original, extra values from oneMap
assertEquals("a:\n b:\n - f\n - h\n", yaml);
}
use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerTests method arrayOverridenInEnvironment.
@Test
public void arrayOverridenInEnvironment() throws Exception {
// Add original values first source
Map<String, Object> oneMap = new LinkedHashMap<String, Object>();
oneMap.put("a.b[0]", "c");
oneMap.put("a.b[1]", "d");
oneMap.put("a.b[2]", "z");
this.environment.add(new PropertySource("one", oneMap));
// Add overridden values in second source
Map<String, Object> twoMap = new LinkedHashMap<String, Object>();
twoMap.put("a.b[0]", "f");
twoMap.put("a.b[1]", "h");
this.environment.addFirst(new PropertySource("two", twoMap));
Mockito.when(this.repository.findOne("foo", "bar", "two")).thenReturn(this.environment);
Environment environment = this.controller.labelled("foo", "bar", "two");
assertThat(environment, not(nullValue()));
assertThat(environment.getName(), equalTo("foo"));
assertThat(environment.getProfiles(), equalTo(new String[] { "master" }));
assertThat(environment.getLabel(), equalTo("master"));
assertThat(environment.getVersion(), nullValue());
assertThat(environment.getPropertySources(), hasSize(2));
assertThat(environment.getPropertySources().get(0).getName(), equalTo("two"));
assertThat(environment.getPropertySources().get(0).getSource().entrySet(), hasSize(2));
assertThat(environment.getPropertySources().get(1).getName(), equalTo("one"));
assertThat(environment.getPropertySources().get(1).getSource().entrySet(), hasSize(3));
}
use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerTests method textAtTopLevelInYaml.
@Test
public void textAtTopLevelInYaml() throws Exception {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("document", "blah");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertEquals("blah\n", yaml);
}
use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerTests method nestedArraysOfObjectInJson.
@Test
public void nestedArraysOfObjectInJson() throws Exception {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("a.b[0].c", "x");
map.put("a.b[0].d[0]", "xx");
map.put("a.b[0].d[1]", "yy");
map.put("a.b[1].c", "y");
map.put("a.b[1].e[0].d", "z");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String json = this.controller.jsonProperties("foo", "bar", false).getBody();
assertThat("Wrong output: " + json, json, is("{\"a\":{\"b\":[{\"c\":\"x\",\"d\":[\"xx\",\"yy\"]},{\"c\":\"y\",\"e\":[{\"d\":\"z\"}]}]}}"));
}
use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerTests method propertyOverrideInYaml.
@Test
public void propertyOverrideInYaml() throws Exception {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("a.b.c", "d");
this.environment.add(new PropertySource("one", map));
this.environment.addFirst(new PropertySource("two", Collections.singletonMap("a.b.c", "e")));
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertEquals("a:\n b:\n c: e\n", yaml);
}
Aggregations