use of com.thoughtworks.go.config.materials.ScmMaterial in project gocd by gocd.
the class SCMDependencyNodeTest method revisionsShouldFetchRevisionsFromMaterialRevisionSorted.
@Test
public void revisionsShouldFetchRevisionsFromMaterialRevisionSorted() {
ScmMaterial gitMaterial = MaterialsMother.gitMaterial("/url/for/repo");
Modification twoDaysAgo = ModificationsMother.oneModifiedFile("rev1", new DateTime().minusDays(2).toDate());
Modification yesterday = ModificationsMother.oneModifiedFile("rev2", new DateTime().minusDays(1).toDate());
Modification today = ModificationsMother.oneModifiedFile("rev3", new Date());
SCMDependencyNode node = new SCMDependencyNode("nodeID", "nodeName", "GIT");
node.addMaterialRevision(new MaterialRevision(gitMaterial, false, twoDaysAgo));
node.addMaterialRevision(new MaterialRevision(gitMaterial, false, yesterday));
node.addMaterialRevision(new MaterialRevision(gitMaterial, false, today));
assertThat(node.revisions().size(), is(3));
assertThat(node.revisions().get(0).getRevisionString(), is(today.getRevision()));
assertThat(node.revisions().get(1).getRevisionString(), is(yesterday.getRevision()));
assertThat(node.revisions().get(2).getRevisionString(), is(twoDaysAgo.getRevision()));
}
use of com.thoughtworks.go.config.materials.ScmMaterial in project gocd by gocd.
the class SCMDependencyNodeTest method shouldBeAbleToAddMaterialRevisions.
@Test
public void shouldBeAbleToAddMaterialRevisions() {
ScmMaterial gitMaterial = MaterialsMother.gitMaterial("/url/for/repo");
List<Modification> modifications = ModificationsMother.multipleModificationList();
SCMDependencyNode node = new SCMDependencyNode("nodeID", "nodeName", "GIT");
node.addMaterialRevision(new MaterialRevision(null, modifications));
node.addMaterialRevision(new MaterialRevision(gitMaterial, modifications));
assertThat(node.getMaterialRevisions().size(), is(2));
}
use of com.thoughtworks.go.config.materials.ScmMaterial in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldFindlatestModificationRunByPipeline.
@Test
public void shouldFindlatestModificationRunByPipeline() {
ScmMaterial material = material();
repo.saveOrUpdate(material.createMaterialInstance());
MaterialRevision first = saveOneScmModification("40c95a3c41f54b5fb3107982cf2acd08783f102a", material, "pavan", "meet_you_in_hell.txt", "comment");
MaterialRevision second = saveOneScmModification("c30c471137f31a4bf735f653f888e799f6deec04", material, "turn_her", "of_course_he_will_be_there_first.txt", "comment");
Pipeline pipeline = createPipeline();
savePMR(first, pipeline);
savePMR(second, pipeline);
Long latestModId = repo.latestModificationRunByPipeline(new CaseInsensitiveString(pipeline.getName()), material);
assertThat(latestModId, is(second.getLatestModification().getId()));
}
use of com.thoughtworks.go.config.materials.ScmMaterial in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldCachePaginatedModificationsForMaterialCorrectly.
@Test
public void shouldCachePaginatedModificationsForMaterialCorrectly() throws Exception {
final ScmMaterial material = material();
MaterialInstance materialInstance = material.createMaterialInstance();
repo.saveOrUpdate(materialInstance);
MaterialRevision first = saveOneScmModification("1", material, "user1", "1.txt", "comment1");
MaterialRevision second = saveOneScmModification("2", material, "user2", "2.txt", "comment2");
MaterialRevision third = saveOneScmModification("3", material, "user3", "3.txt", "comment3");
MaterialRevision fourth = saveOneScmModification("4", material, "user4", "4.txt", "comment4");
MaterialRevision fifth = saveOneScmModification("5", material, "user5", "5.txt", "comment5");
Pagination page = Pagination.pageStartingAt(0, 5, 3);
repo.getModificationsFor(materialInstance, page);
Modifications modificationsFromCache = (Modifications) goCache.get(repo.materialModificationsWithPaginationKey(materialInstance), repo.materialModificationsWithPaginationSubKey(page));
assertThat(modificationsFromCache.size(), is(3));
assertThat(modificationsFromCache.get(0).getRevision(), is(fifth.getLatestRevisionString()));
assertThat(modificationsFromCache.get(1).getRevision(), is(fourth.getLatestRevisionString()));
assertThat(modificationsFromCache.get(2).getRevision(), is(third.getLatestRevisionString()));
page = Pagination.pageStartingAt(1, 5, 3);
repo.getModificationsFor(materialInstance, page);
modificationsFromCache = (Modifications) goCache.get(repo.materialModificationsWithPaginationKey(materialInstance), repo.materialModificationsWithPaginationSubKey(page));
assertThat(modificationsFromCache.size(), is(3));
assertThat(modificationsFromCache.get(0).getRevision(), is(fourth.getLatestRevisionString()));
assertThat(modificationsFromCache.get(1).getRevision(), is(third.getLatestRevisionString()));
assertThat(modificationsFromCache.get(2).getRevision(), is(second.getLatestRevisionString()));
page = Pagination.pageStartingAt(3, 5, 3);
repo.getModificationsFor(materialInstance, page);
modificationsFromCache = (Modifications) goCache.get(repo.materialModificationsWithPaginationKey(materialInstance), repo.materialModificationsWithPaginationSubKey(page));
assertThat(modificationsFromCache.size(), is(2));
assertThat(modificationsFromCache.get(0).getRevision(), is(second.getLatestRevisionString()));
assertThat(modificationsFromCache.get(1).getRevision(), is(first.getLatestRevisionString()));
final Modification modOne = new Modification("user", "comment", "email@gmail.com", new Date(), "123");
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
MaterialInstance foo = repo.findOrCreateFrom(material);
repo.saveModifications(foo, asList(modOne));
}
});
modificationsFromCache = (Modifications) goCache.get(repo.materialModificationsWithPaginationKey(materialInstance), repo.materialModificationsWithPaginationSubKey(Pagination.pageStartingAt(0, 5, 3)));
assertThat(modificationsFromCache, is(nullValue()));
modificationsFromCache = (Modifications) goCache.get(repo.materialModificationsWithPaginationKey(materialInstance), repo.materialModificationsWithPaginationSubKey(Pagination.pageStartingAt(3, 5, 3)));
assertThat(modificationsFromCache, is(nullValue()));
}
use of com.thoughtworks.go.config.materials.ScmMaterial in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldReturnMatchedRevisionsForAGivenSearchString.
@Test
public void shouldReturnMatchedRevisionsForAGivenSearchString() throws Exception {
ScmMaterial material = material();
repo.saveOrUpdate(material.createMaterialInstance());
MaterialRevision materialRevision = saveOneScmModification("40c95a3c41f54b5fb3107982cf2acd08783f102a", material, "pavan", "meet_you_in_hell.txt", "comment");
saveOneScmModification(material, "turn_her", "of_course_he_will_be_there_first.txt");
List<MatchedRevision> revisions = repo.findRevisionsMatching(material.config(), "pavan");
assertThat(revisions.size(), is(1));
assertMatchedRevision(revisions.get(0), materialRevision.getLatestShortRevision(), materialRevision.getLatestRevisionString(), "pavan", materialRevision.getDateOfLatestModification(), "comment");
}
Aggregations