Search in sources :

Example 41 with Environment

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

the class JGitEnvironmentRepositoryIntegrationTests method nestedWithProfilePlaceholders.

@Test
public void nestedWithProfilePlaceholders() throws IOException {
    String uri = ConfigServerTestUtils.prepareLocalRepo("nested-repo");
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths={profile}");
    EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
    repository.findOne("foo,bar", "staging", "master");
    Environment environment = repository.findOne("staging", "foo,bar", "master");
    assertEquals(3, environment.getPropertySources().size());
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Example 42 with Environment

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

the class JGitEnvironmentRepositoryIntegrationTests method testShouldFailIfRemoteBranchWasDeleted.

@Test(expected = NoSuchLabelException.class)
public void testShouldFailIfRemoteBranchWasDeleted() throws Exception {
    JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(Collections.singleton("spring.cloud.config.server.git.deleteUntrackedBranches=true"), TestConfiguration.class);
    String branchToDelete = "branchToDelete";
    testData.getServerGit().getGit().branchCreate().setName(branchToDelete).call();
    // checkout and simulate regular flow
    Environment environment = testData.getRepository().findOne("bar", "staging", "branchToDelete");
    assertNotNull(environment);
    // remove branch
    testData.getServerGit().getGit().branchDelete().setBranchNames(branchToDelete).call();
    // test
    testData.getRepository().findOne("bar", "staging", "branchToDelete");
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Example 43 with Environment

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

the class JGitEnvironmentRepositoryIntegrationTests method nestedWithApplicationPlaceholders.

@Test
public void nestedWithApplicationPlaceholders() throws IOException {
    String uri = ConfigServerTestUtils.prepareLocalRepo("nested-repo");
    this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths={application}");
    EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
    repository.findOne("foo,bar", "staging", "master");
    Environment environment = repository.findOne("foo,bar", "staging", "master");
    assertEquals(3, environment.getPropertySources().size());
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Example 44 with Environment

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

the class JGitEnvironmentRepositoryIntegrationTests method testNewCommitID.

@Test
public void testNewCommitID() throws Exception {
    JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(TestConfiguration.class);
    // get our starting versions
    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");
    assertEquals(environment.getVersion(), startingRemoteVersion);
    // update the remote repo
    FileOutputStream out = new FileOutputStream(new File(testData.getServerGit().getGitWorkingDirectory(), "bar.properties"));
    StreamUtils.copy("foo: barNewCommit", Charset.defaultCharset(), out);
    testData.getServerGit().getGit().add().addFilepattern("bar.properties").call();
    testData.getServerGit().getGit().commit().setMessage("Updated for pull").call();
    String updatedRemoteVersion = getCommitID(testData.getServerGit().getGit(), "master");
    // do a normal request and verify we get the new version
    environment = testData.getRepository().findOne("bar", "staging", "master");
    assertEquals(environment.getVersion(), updatedRemoteVersion);
    Object fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo");
    assertEquals(fooProperty, "barNewCommit");
    // request the prior commit ID and make sure we get it
    environment = testData.getRepository().findOne("bar", "staging", startingRemoteVersion);
    assertEquals(environment.getVersion(), startingRemoteVersion);
    fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo");
    assertEquals(fooProperty, "bar");
}
Also used : FileOutputStream(java.io.FileOutputStream) Environment(org.springframework.cloud.config.environment.Environment) File(java.io.File) Test(org.junit.Test)

Example 45 with Environment

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

the class JGitEnvironmentRepositoryIntegrationTests method testNewRemoteBranch.

@Test
public void testNewRemoteBranch() throws Exception {
    JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(TestConfiguration.class);
    Environment environment = testData.getRepository().findOne("bar", "staging", "master");
    Object fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo");
    assertEquals(fooProperty, "bar");
    testData.getServerGit().getGit().branchCreate().setName("testNewRemoteBranch").call();
    testData.getServerGit().getGit().checkout().setName("testNewRemoteBranch").call();
    // update the remote repo
    FileOutputStream out = new FileOutputStream(new File(testData.getServerGit().getGitWorkingDirectory(), "/bar.properties"));
    StreamUtils.copy("foo: branchBar", Charset.defaultCharset(), out);
    testData.getServerGit().getGit().add().addFilepattern("bar.properties").call();
    testData.getServerGit().getGit().commit().setMessage("Updated for branch test").call();
    environment = testData.getRepository().findOne("bar", "staging", "testNewRemoteBranch");
    fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo");
    assertEquals(fooProperty, "branchBar");
}
Also used : FileOutputStream(java.io.FileOutputStream) Environment(org.springframework.cloud.config.environment.Environment) File(java.io.File) 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