Search in sources :

Example 11 with Environment

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

the class MultipleJGitEnvironmentRepositoryTests method defaultRepoTwice.

@Test
public void defaultRepoTwice() {
    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 12 with Environment

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

the class MultipleJGitEnvironmentRepositoryTests method defaultRepoNested.

@Test
public void defaultRepoNested() 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) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 13 with Environment

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

the class JdbcEnvironmentRepositoryTests method basicProperties.

@Test
public void basicProperties() {
    Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(dataSource), new JdbcEnvironmentProperties()).findOne("foo", "bar", "");
    assertThat(env.getName()).isEqualTo("foo");
    assertThat(env.getProfiles()).isEqualTo(new String[] { "default", "bar" });
    assertThat(env.getLabel()).isEqualTo("master");
    assertThat(env.getPropertySources()).isNotEmpty();
    assertThat(env.getPropertySources().get(0).getName()).isEqualTo("foo-bar");
    assertThat(env.getPropertySources().get(0).getSource().get("a.b.c")).isEqualTo("x");
    assertThat(env.getPropertySources().get(1).getName()).isEqualTo("application-default");
    assertThat(env.getPropertySources().get(1).getSource().get("a.b")).isEqualTo("y");
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with Environment

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

the class JdbcEnvironmentRepositoryTests method defaults.

@Test
public void defaults() {
    Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(dataSource), new JdbcEnvironmentProperties()).findOne("application", "", "");
    assertThat(env.getName()).isEqualTo("application");
    assertThat(env.getProfiles()).isEqualTo(new String[] { "default" });
    assertThat(env.getLabel()).isEqualTo("master");
    assertThat(env.getPropertySources()).isNotEmpty();
    assertThat(env.getPropertySources().get(0).getSource().get("a.b")).isEqualTo("y");
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with Environment

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

the class MultipleJGitEnvironmentLabelPlaceholderRepositoryTests method defaultLabelRepo.

@Test
public void defaultLabelRepo() {
    Environment environment = this.repository.findOne("bar", "staging", null);
    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)

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