Search in sources :

Example 71 with Environment

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

the class JGitEnvironmentRepositoryIntegrationTests method testVersionUpdate.

@Test
public void testVersionUpdate() throws Exception {
    JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(TestConfiguration.class);
    // get our starting versions
    String startingLocalVersion = getCommitID(testData.getClonedGit().getGit(), "master");
    String startingRemoteVersion = getCommitID(testData.getServerGit().getGit(), "master");
    // make sure we get the right version out of the gate
    Environment environment = testData.getRepository().findOne("bar", "staging", "master");
    // make sure the environments version is the same as the remote repo
    // version
    assertEquals(environment.getVersion(), startingRemoteVersion);
    // update the remote repo
    FileOutputStream out = new FileOutputStream(new File(testData.getServerGit().getGitWorkingDirectory(), "bar.properties"));
    StreamUtils.copy("foo: foo", Charset.defaultCharset(), out);
    testData.getServerGit().getGit().add().addFilepattern("bar.properties").call();
    testData.getServerGit().getGit().commit().setMessage("Updated for pull").call();
    // pull the environment again which should update the local repo from
    // the just updated remote repo
    environment = testData.getRepository().findOne("bar", "staging", "master");
    // do some more check outs to get updated version numbers
    String updatedLocalVersion = getCommitID(testData.getClonedGit().getGit(), "master");
    String updatedRemoteVersion = getCommitID(testData.getClonedGit().getGit(), "master");
    // make sure our versions have been updated
    assertEquals(updatedRemoteVersion, updatedLocalVersion);
    assertNotEquals(updatedRemoteVersion, startingRemoteVersion);
    assertNotEquals(updatedLocalVersion, startingLocalVersion);
    // make sure our environment also reflects the updated version
    // this used to have a bug
    assertEquals(environment.getVersion(), updatedRemoteVersion);
}
Also used : FileOutputStream(java.io.FileOutputStream) Environment(org.springframework.cloud.config.environment.Environment) File(java.io.File) Test(org.junit.Test)

Example 72 with Environment

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

the class JGitEnvironmentRepositoryIntegrationTests method pullMissingRepo.

@Test
public void pullMissingRepo() throws Exception {
    pull();
    JGitEnvironmentRepository repository = this.context.getBean(JGitEnvironmentRepository.class);
    new File(repository.getUri().replaceAll("file:", ""), ".git/index.lock").createNewFile();
    repository.findOne("bar", "staging", "master");
    Environment environment = repository.findOne("bar", "staging", "master");
    assertEquals("foo", environment.getPropertySources().get(0).getSource().get("foo"));
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) File(java.io.File) Test(org.junit.Test)

Example 73 with Environment

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

the class JGitEnvironmentRepositoryTests method tag.

@Test
public void tag() {
    this.repository.setBasedir(this.basedir);
    Environment environment = this.repository.findOne("bar", "staging", "foo");
    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 74 with Environment

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

the class ConfigClientOffIntegrationTests method contextLoads.

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

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

the class SubversionConfigServerIntegrationTests method contextLoads.

@Test
public void contextLoads() {
    Environment environment = new TestRestTemplate().getForObject("http://localhost:" + this.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)

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