Search in sources :

Example 6 with PropertySource

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 7 with PropertySource

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));
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 8 with PropertySource

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 9 with PropertySource

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\"}]}]}}"));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 10 with PropertySource

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Aggregations

PropertySource (org.springframework.cloud.config.environment.PropertySource)33 Test (org.junit.Test)20 LinkedHashMap (java.util.LinkedHashMap)19 Environment (org.springframework.cloud.config.environment.Environment)12 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 MapPropertySource (org.springframework.core.env.MapPropertySource)4 CompositePropertySource (org.springframework.core.env.CompositePropertySource)3 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)1 File (java.io.File)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 YamlPropertiesFactoryBean (org.springframework.beans.factory.config.YamlPropertiesFactoryBean)1 EnvironmentRepository (org.springframework.cloud.config.server.environment.EnvironmentRepository)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 StandardEnvironment (org.springframework.core.env.StandardEnvironment)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1