Search in sources :

Example 46 with Environment

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

the class JGitEnvironmentRepositoryIntegrationTests method vanilla.

@Test
public void vanilla() throws IOException {
    String uri = ConfigServerTestUtils.prepareLocalRepo();
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties("spring.cloud.config.server.git.uri:" + uri).run();
    EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
    repository.findOne("bar", "staging", "master");
    Environment environment = repository.findOne("bar", "staging", "master");
    assertEquals(2, environment.getPropertySources().size());
    assertEquals("bar", environment.getName());
    assertArrayEquals(new String[] { "staging" }, environment.getProfiles());
    assertEquals("master", environment.getLabel());
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Example 47 with Environment

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

the class JGitEnvironmentRepositoryTests method basedir.

@Test
public void basedir() {
    this.repository.setBasedir(this.basedir);
    this.repository.findOne("bar", "staging", "master");
    Environment environment = this.repository.findOne("bar", "staging", "master");
    assertEquals(2, environment.getPropertySources().size());
    assertEquals(this.repository.getUri() + "/bar.properties", environment.getPropertySources().get(0).getName());
    assertVersion(environment);
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Example 48 with Environment

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

the class JGitEnvironmentRepositoryTests method nested.

@Test
public void nested() throws IOException {
    String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
    this.repository.setUri(uri);
    this.repository.setSearchPaths(new String[] { "sub" });
    this.repository.findOne("bar", "staging", "master");
    Environment environment = this.repository.findOne("bar", "staging", "master");
    assertEquals(2, environment.getPropertySources().size());
    assertEquals(this.repository.getUri() + "/sub/application.yml", environment.getPropertySources().get(0).getName());
    assertVersion(environment);
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.cloud.config.environment.Environment) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 49 with Environment

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

the class JGitEnvironmentRepositoryTests method nestedPattern.

@Test
public void nestedPattern() throws IOException {
    String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
    this.repository.setUri(uri);
    this.repository.setSearchPaths(new String[] { "sub*" });
    this.repository.findOne("bar", "staging", "master");
    Environment environment = this.repository.findOne("bar", "staging", "master");
    assertEquals(2, environment.getPropertySources().size());
    assertEquals(this.repository.getUri() + "/sub/application.yml", environment.getPropertySources().get(0).getName());
    assertVersion(environment);
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.cloud.config.environment.Environment) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 50 with Environment

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

the class CipherEnvironmentEncryptorTests method shouldDecryptEnvironment.

@Test
public void shouldDecryptEnvironment() {
    // 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}" + 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)

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