Search in sources :

Example 16 with ScmMaterial

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()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.junit.Test)

Example 17 with ScmMaterial

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));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.Test)

Example 18 with ScmMaterial

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()));
}
Also used : ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 19 with ScmMaterial

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()));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance) SvnMaterialInstance(com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance) Date(java.util.Date) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Example 20 with ScmMaterial

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");
}
Also used : ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) Test(org.junit.Test)

Aggregations

ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)26 Test (org.junit.Test)24 Modification (com.thoughtworks.go.domain.materials.Modification)6 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)5 MaterialUpdateMessageMatcher.matchMaterialUpdateMessage (com.thoughtworks.go.helper.MaterialUpdateMessageMatcher.matchMaterialUpdateMessage)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 PackageMaterialInstance (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance)4 PluggableSCMMaterialInstance (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance)4 SvnMaterialInstance (com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance)4 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)3 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 RunIf (com.googlecode.junit.ext.RunIf)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)2 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)2 PipelineLabel (com.thoughtworks.go.domain.label.PipelineLabel)2 Material (com.thoughtworks.go.domain.materials.Material)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2