Search in sources :

Example 21 with PropertySource

use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.

the class EnvironmentControllerTests method arrayAtTopLevelInYaml.

@Test
public void arrayAtTopLevelInYaml() throws Exception {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("document[0]", "c");
    map.put("document[1]", "d");
    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("- c\n- d\n", yaml);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 22 with PropertySource

use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.

the class EnvironmentControllerTests method vanillaYaml.

@Test
public void vanillaYaml() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("a.b.c", "d");
    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("a:\n  b:\n    c: d\n", yaml);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 23 with PropertySource

use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.

the class EnvironmentControllerTests method arrayOfObjectInYaml.

@Test
public void arrayOfObjectInYaml() throws Exception {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("a.b[0].c", "d");
    map.put("a.b[0].d", "e");
    map.put("a.b[1].c", "d");
    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();
    assertTrue("Wrong output: " + yaml, "a:\n  b:\n  - d: e\n    c: d\n  - c: d\n".equals(yaml) || "a:\n  b:\n  - c: d\n    d: e\n  - c: d\n".equals(yaml));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 24 with PropertySource

use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.

the class EnvironmentControllerTests method nestedArraysOfObjectInYaml.

@Test
public void nestedArraysOfObjectInYaml() throws Exception {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("a.b[0].c", "x");
    map.put("a.b[2].e[0].d", "z");
    map.put("a.b[0].d[2]", "yy");
    map.put("a.b[0].d[0]", "xx");
    map.put("a.b[2].c", "y");
    map.put("a.b[3][0]", "r");
    map.put("a.b[3][1]", "s");
    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();
    // @formatter:off
    String expected = "a:\n" + "  b:\n" + "  - c: x\n" + "    d:\n" + "    - xx\n" + "    - null\n" + "    - yy\n" + "  - null\n" + "  - c: y\n" + "    e:\n" + "    - d: z\n" + "  - - r\n" + "    - s\n";
    // @formatter:on
    assertThat("Wrong output: " + yaml, yaml, is(expected));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 25 with PropertySource

use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.

the class EnvironmentControllerTests method arrayOfObjectAtTopLevelInYaml.

@Test
public void arrayOfObjectAtTopLevelInYaml() throws Exception {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("b[0].c", "d");
    map.put("b[1].c", "d");
    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("b:\n- c: d\n- c: d\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