Search in sources :

Example 51 with Environment

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

the class CipherEnvironmentEncryptorTests method shouldDecryptEnvironmentWithKey.

@Test
public void shouldDecryptEnvironmentWithKey() {
    // given
    String secret = randomUUID().toString();
    // when
    Environment environment = new Environment("name", "profile", "label");
    environment.add(new PropertySource("a", Collections.<Object, Object>singletonMap(environment.getName(), "{cipher}{key:test}" + this.textEncryptor.encrypt(secret))));
    // then
    assertEquals(secret, this.encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()));
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) PropertySource(org.springframework.cloud.config.environment.PropertySource) Test(org.junit.Test)

Example 52 with Environment

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

the class VanillaConfigServerIntegrationTests 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)

Example 53 with Environment

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

the class CustomEnvironmentRepositoryTests method contextLoads.

@Test
public void contextLoads() {
    Environment environment = new TestRestTemplate().getForObject("http://localhost:" + port + "/foo/development/", Environment.class);
    assertFalse(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 54 with Environment

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

the class ConfigServicePropertySourceLocator method getRemoteEnvironment.

private Environment getRemoteEnvironment(RestTemplate restTemplate, ConfigClientProperties properties, String label, String state) {
    String path = "/{name}/{profile}";
    String name = properties.getName();
    String profile = properties.getProfile();
    String token = properties.getToken();
    String uri = properties.getRawUri();
    Object[] args = new String[] { name, profile };
    if (StringUtils.hasText(label)) {
        args = new String[] { name, profile, label };
        path = path + "/{label}";
    }
    ResponseEntity<Environment> response = null;
    try {
        HttpHeaders headers = new HttpHeaders();
        if (StringUtils.hasText(token)) {
            headers.add(TOKEN_HEADER, token);
        }
        if (StringUtils.hasText(state)) {
            // TODO: opt in to sending state?
            headers.add(STATE_HEADER, state);
        }
        final HttpEntity<Void> entity = new HttpEntity<>((Void) null, headers);
        response = restTemplate.exchange(uri + path, HttpMethod.GET, entity, Environment.class, args);
    } catch (HttpClientErrorException e) {
        if (e.getStatusCode() != HttpStatus.NOT_FOUND) {
            throw e;
        }
    }
    if (response == null || response.getStatusCode() != HttpStatus.OK) {
        return null;
    }
    Environment result = response.getBody();
    return result;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpEntity(org.springframework.http.HttpEntity) Environment(org.springframework.cloud.config.environment.Environment)

Example 55 with Environment

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

the class ConfigServicePropertySourceLocatorTests method sunnyDay.

@Test
public void sunnyDay() {
    Environment body = new Environment("app", "master");
    mockRequestResponseWithoutLabel(new ResponseEntity<>(body, HttpStatus.OK));
    this.locator.setRestTemplate(this.restTemplate);
    assertNotNull(this.locator.locate(this.environment));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

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