Search in sources :

Example 61 with Environment

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

the class EnvironmentControllerIntegrationTests method environmentWithLabelContainingSlash.

@Test
public void environmentWithLabelContainingSlash() throws Exception {
    Mockito.when(this.repository.findOne("foo", "default", "feature/puff")).thenReturn(new Environment("foo", "default"));
    this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/feature(_)puff")).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"propertySources\":")));
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 62 with Environment

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

the class EnvironmentControllerIntegrationTests method environmentWithApplicationContainingSlash.

@Test
public void environmentWithApplicationContainingSlash() throws Exception {
    Mockito.when(this.repository.findOne("foo/app", "default", null)).thenReturn(new Environment("foo/app", "default"));
    this.mvc.perform(MockMvcRequestBuilders.get("/foo(_)app/default")).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().string(Matchers.containsString("\"propertySources\":")));
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 63 with Environment

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

the class EnvironmentControllerIntegrationTests method environmentWithLabelContainingPeriod.

@Test
public void environmentWithLabelContainingPeriod() throws Exception {
    Mockito.when(this.repository.findOne("foo", "default", "1.0.0")).thenReturn(new Environment("foo", "default"));
    this.mvc.perform(MockMvcRequestBuilders.get("/foo/default/1.0.0")).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 64 with Environment

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

the class JGitEnvironmentRepositoryConcurrencyTests method vanilla.

@Test
public void vanilla() throws Exception {
    String uri = ConfigServerTestUtils.prepareLocalRepo();
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties("spring.cloud.config.server.git.uri:" + uri).run();
    final EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
    ExecutorService threads = Executors.newFixedThreadPool(4);
    List<Future<Boolean>> tasks = new ArrayList<Future<Boolean>>();
    for (int i = 0; i < 30; i++) {
        tasks.add(threads.submit(new Runnable() {

            @Override
            public void run() {
                repository.findOne("bar", "staging", "master");
            }
        }, true));
    }
    for (Future<Boolean> future : tasks) {
        future.get();
    }
    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) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Example 65 with Environment

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

the class JGitEnvironmentRepositoryIntegrationTests method findOne_CloneOnStartTrue_FindOneSuccess.

@Test
public void findOne_CloneOnStartTrue_FindOneSuccess() throws Exception {
    ConfigServerTestUtils.prepareLocalRepo();
    String uri = ConfigServerTestUtils.copyLocalRepo("config-copy");
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.cloneOnStart=true");
    EnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class);
    assertTrue(((JGitEnvironmentRepository) repository).isCloneOnStart());
    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)

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