Search in sources :

Example 76 with Environment

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

the class EnvironmentController method labelledJsonProperties.

@RequestMapping("/{label}/{name}-{profiles}.json")
public ResponseEntity<String> labelledJsonProperties(@PathVariable String name, @PathVariable String profiles, @PathVariable String label, @RequestParam(defaultValue = "true") boolean resolvePlaceholders) throws Exception {
    validateProfiles(profiles);
    Environment environment = labelled(name, profiles, label);
    Map<String, Object> properties = convertToMap(environment);
    String json = this.objectMapper.writeValueAsString(properties);
    if (resolvePlaceholders) {
        json = resolvePlaceholders(prepareEnvironment(environment), json);
    }
    return getSuccess(json, MediaType.APPLICATION_JSON);
}
Also used : EnvironmentPropertySource.prepareEnvironment(org.springframework.cloud.config.server.support.EnvironmentPropertySource.prepareEnvironment) Environment(org.springframework.cloud.config.environment.Environment) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 77 with Environment

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

the class EnvironmentController method labelledYaml.

@RequestMapping({ "/{label}/{name}-{profiles}.yml", "/{label}/{name}-{profiles}.yaml" })
public ResponseEntity<String> labelledYaml(@PathVariable String name, @PathVariable String profiles, @PathVariable String label, @RequestParam(defaultValue = "true") boolean resolvePlaceholders) throws Exception {
    validateProfiles(profiles);
    Environment environment = labelled(name, profiles, label);
    Map<String, Object> result = convertToMap(environment);
    if (this.stripDocument && result.size() == 1 && result.keySet().iterator().next().equals("document")) {
        Object value = result.get("document");
        if (value instanceof Collection) {
            return getSuccess(new Yaml().dumpAs(value, Tag.SEQ, FlowStyle.BLOCK));
        } else {
            return getSuccess(new Yaml().dumpAs(value, Tag.STR, FlowStyle.BLOCK));
        }
    }
    String yaml = new Yaml().dumpAsMap(result);
    if (resolvePlaceholders) {
        yaml = resolvePlaceholders(prepareEnvironment(environment), yaml);
    }
    return getSuccess(yaml);
}
Also used : EnvironmentPropertySource.prepareEnvironment(org.springframework.cloud.config.server.support.EnvironmentPropertySource.prepareEnvironment) Environment(org.springframework.cloud.config.environment.Environment) Collection(java.util.Collection) Yaml(org.yaml.snakeyaml.Yaml) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 78 with Environment

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

the class BootstrapConfigServerIntegrationTests method contextLoads.

@Test
public void contextLoads() {
    Environment environment = new TestRestTemplate().getForObject("http://localhost:" + port + "/foo/development/", Environment.class);
    assertFalse(environment.getPropertySources().isEmpty());
    assertEquals("bar", environment.getPropertySources().get(0).getSource().get("info.foo"));
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 79 with Environment

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

the class ConfigClientOnIntegrationTests method contextLoads.

@Test
public void contextLoads() {
    Environment environment = new TestRestTemplate().getForObject("http://localhost:" + this.port + "/foo/development/", Environment.class);
    assertTrue(environment.getPropertySources().isEmpty());
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) WebEnvironment(org.springframework.boot.test.context.SpringBootTest.WebEnvironment) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 80 with Environment

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

the class NativeConfigServerIntegrationTests method contextLoads.

@Test
public void contextLoads() {
    Environment environment = new TestRestTemplate().getForObject("http://localhost:" + port + "/foo/development/", Environment.class);
    assertFalse(environment.getPropertySources().isEmpty());
    assertEquals("overrides", environment.getPropertySources().get(0).getName());
    assertEquals("{spring.cloud.config.enabled=true}", environment.getPropertySources().get(0).getSource().toString());
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Environment (org.springframework.cloud.config.environment.Environment)118 Test (org.junit.Test)104 StandardEnvironment (org.springframework.core.env.StandardEnvironment)37 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)20 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)19 PropertySource (org.springframework.cloud.config.environment.PropertySource)12 LinkedHashMap (java.util.LinkedHashMap)9 File (java.io.File)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)7 FileOutputStream (java.io.FileOutputStream)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)4 EnvironmentPropertySource.prepareEnvironment (org.springframework.cloud.config.server.support.EnvironmentPropertySource.prepareEnvironment)4 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)4 HttpEntity (org.springframework.http.HttpEntity)4 RestTemplate (org.springframework.web.client.RestTemplate)4 Git (org.eclipse.jgit.api.Git)3 Matchers.anyString (org.mockito.Matchers.anyString)3