use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class JGitEnvironmentRepositoryIntegrationTests method findOne_FileAddedToRepo_FindOneSuccess.
@Test
public void findOne_FileAddedToRepo_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(EnvironmentRepository.class);
repository.findOne("bar", "staging", "master");
Environment environment = repository.findOne("bar", "staging", "master");
assertEquals("bar", environment.getPropertySources().get(0).getSource().get("foo"));
Git git = Git.open(ResourceUtils.getFile(uri).getAbsoluteFile());
git.checkout().setName("master").call();
StreamUtils.copy("foo: foo", Charset.defaultCharset(), new FileOutputStream(ResourceUtils.getFile(uri + "/bar.properties")));
git.add().addFilepattern("bar.properties").call();
git.commit().setMessage("Updated for pull").call();
environment = repository.findOne("bar", "staging", "master");
assertEquals("foo", environment.getPropertySources().get(0).getSource().get("foo"));
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class JGitEnvironmentRepositoryIntegrationTests method testShouldReturnEnvironmentFromLocalBranchInCaseRemoteDeleted.
@Test
public void testShouldReturnEnvironmentFromLocalBranchInCaseRemoteDeleted() throws Exception {
JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(TestConfiguration.class);
String branchToDelete = "branchToDelete";
testData.getServerGit().getGit().branchCreate().setName(branchToDelete).call();
Environment environment = testData.getRepository().findOne("bar", "staging", "branchToDelete");
assertNotNull(environment);
testData.getServerGit().getGit().branchDelete().setBranchNames(branchToDelete).call();
testData.getRepository().findOne("bar", "staging", "branchToDelete");
assertNotNull(environment);
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class JGitEnvironmentRepositoryIntegrationTests method findOne_NestedSearchPath_FindOneSuccess.
@Test
public void findOne_NestedSearchPath_FindOneSuccess() throws IOException {
String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).run("--spring.cloud.config.server.git.uri=" + uri, "--spring.cloud.config.server.git.searchPaths=sub", "--spring.cloud.config.server.git.cloneOnStart=true");
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "master");
Environment environment = repository.findOne("bar", "staging", "master");
assertEquals(2, environment.getPropertySources().size());
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class JGitEnvironmentRepositoryIntegrationTests method pull.
@Test
public void pull() 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);
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "master");
Environment environment = repository.findOne("bar", "staging", "master");
assertEquals("bar", environment.getPropertySources().get(0).getSource().get("foo"));
Git git = Git.open(ResourceUtils.getFile(uri).getAbsoluteFile());
git.checkout().setName("master").call();
StreamUtils.copy("foo: foo", Charset.defaultCharset(), new FileOutputStream(ResourceUtils.getFile(uri + "/bar.properties")));
git.add().addFilepattern("bar.properties").call();
git.commit().setMessage("Updated for pull").call();
environment = repository.findOne("bar", "staging", "master");
assertEquals("foo", environment.getPropertySources().get(0).getSource().get("foo"));
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class JGitEnvironmentRepositoryIntegrationTests method testNewRemoteTag.
@Test
public void testNewRemoteTag() throws Exception {
JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(TestConfiguration.class);
Git serverGit = testData.getServerGit().getGit();
Environment environment = testData.getRepository().findOne("bar", "staging", "master");
Object fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo");
assertEquals(fooProperty, "bar");
serverGit.checkout().setName("master").call();
// create a new tag
serverGit.tag().setName("testTag").setMessage("Testing a tag").call();
// update the remote repo
FileOutputStream out = new FileOutputStream(new File(testData.getServerGit().getGitWorkingDirectory(), "/bar.properties"));
StreamUtils.copy("foo: testAfterTag", 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", "master");
fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo");
assertEquals(fooProperty, "testAfterTag");
environment = testData.getRepository().findOne("bar", "staging", "testTag");
fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo");
assertEquals(fooProperty, "bar");
// now move the tag and test again
serverGit.tag().setName("testTag").setForceUpdate(true).setMessage("Testing a moved tag").call();
environment = testData.getRepository().findOne("bar", "staging", "testTag");
fooProperty = ConfigServerTestUtils.getProperty(environment, "bar.properties", "foo");
assertEquals(fooProperty, "testAfterTag");
}
Aggregations