Search in sources :

Example 16 with Environment

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

the class MultipleJGitEnvironmentLabelPlaceholderRepositoryTests method defaultRepo.

@Test
public void defaultRepo() {
    Environment environment = this.repository.findOne("bar", "staging", "master");
    assertEquals(1, environment.getPropertySources().size());
    assertEquals(this.defaultUri + "application.yml", 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 17 with Environment

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

the class MultipleJGitEnvironmentRepositoryIntegrationTests method mappingRepoWithProfiles.

@Test
public void mappingRepoWithProfiles() throws IOException {
    String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
    String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo");
    Map<String, Object> repoMapping = new LinkedHashMap<String, Object>();
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[0]", "*/staging,*");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[1]", "*/*,staging");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern[2]", "*/staging");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].uri", test1RepoUri);
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).properties(repoMapping).run();
    EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
    repository.findOne("test1-svc", "staging", "master");
    Environment environment = repository.findOne("test1-svc", "cloud,staging", "master");
    assertEquals(2, environment.getPropertySources().size());
    environment = repository.findOne("test1-svc", "staging,cloud", "master");
    assertEquals(2, environment.getPropertySources().size());
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Environment(org.springframework.cloud.config.environment.Environment) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 18 with Environment

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

the class MultipleJGitEnvironmentRepositoryIntegrationTests method mappingRepo.

@Test
public void mappingRepo() throws IOException {
    String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
    String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo");
    Map<String, Object> repoMapping = new LinkedHashMap<String, Object>();
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern", "*test1*");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].uri", test1RepoUri);
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).properties(repoMapping).run();
    EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
    repository.findOne("test1-svc", "staging", "master");
    Environment environment = repository.findOne("test1-svc", "staging", "master");
    assertEquals(2, environment.getPropertySources().size());
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Environment(org.springframework.cloud.config.environment.Environment) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 19 with Environment

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

the class MultipleJGitEnvironmentRepositoryIntegrationTests method mappingRepoWithProfile.

@Test
public void mappingRepoWithProfile() throws IOException {
    String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
    String test1RepoUri = ConfigServerTestUtils.prepareLocalRepo("test1-config-repo");
    Map<String, Object> repoMapping = new LinkedHashMap<String, Object>();
    repoMapping.put("spring.cloud.config.server.git.repos[test1].pattern", "*/staging");
    repoMapping.put("spring.cloud.config.server.git.repos[test1].uri", test1RepoUri);
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties("spring.cloud.config.server.git.uri:" + defaultRepoUri).properties(repoMapping).run();
    EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
    repository.findOne("test1-svc", "staging", "master");
    Environment environment = repository.findOne("test1-svc", "staging", "master");
    assertEquals(2, environment.getPropertySources().size());
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Environment(org.springframework.cloud.config.environment.Environment) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 20 with Environment

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

the class NativeEnvironmentRepositoryTests method labelled.

@Test
public void labelled() {
    this.repository.setSearchLocations("classpath:/test");
    Environment environment = this.repository.findOne("foo", "development", "dev");
    assertEquals(3, environment.getPropertySources().size());
    // position 1 because it has higher precedence than anything except the
    // foo-development.properties
    assertEquals("dev_bar", environment.getPropertySources().get(1).getSource().get("foo"));
    assertEquals("version was wrong", "myversion", environment.getVersion());
}
Also used : 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