Search in sources :

Example 1 with PipelineMaterialRevision

use of com.thoughtworks.go.domain.PipelineMaterialRevision in project gocd by gocd.

the class ChangesetServiceIntegrationTest method shouldPopulateActualFromRevisionId.

@Test
public void shouldPopulateActualFromRevisionId() {
    PipelineConfig upstreamPipeline = configHelper.addPipeline("upstream", "stage", git.config(), "job");
    DependencyMaterial dependencyMaterial = MaterialsMother.dependencyMaterial("upstream", "stage");
    PipelineConfig downstreamConfig = configHelper.addPipeline("downstream", "stage", dependencyMaterial.config(), "build");
    Username username = new Username(new CaseInsensitiveString("user1"));
    // By default the pmr's actualFromRevisionId should be the fromRevisionId
    List<MaterialRevision> revisionsForUpstream1 = new ArrayList<>();
    addRevisionWith2Mods(revisionsForUpstream1, git);
    Pipeline upstream1 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream1);
    assertPipelineMaterialRevisions(upstream1);
    // First downstream pipeline's actualFromRevisionId should also be it's fromRevisionId
    List<MaterialRevision> revisionsForDownstream1 = new ArrayList<>();
    dbHelper.addDependencyRevisionModification(revisionsForDownstream1, dependencyMaterial, upstream1);
    Pipeline downstream1 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), downstreamConfig, revisionsForDownstream1);
    assertPipelineMaterialRevisions(downstream1);
    // When downstream is triggered with a range of upstream modifications it's actualFromRevisionId should be 1 more than the last one that was built
    List<MaterialRevision> revisionsForUpstream2 = new ArrayList<>();
    addRevisionWith2Mods(revisionsForUpstream2, git);
    Pipeline upstream2 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream2);
    assertPipelineMaterialRevisions(upstream2);
    List<MaterialRevision> revisionsForUpstream3 = new ArrayList<>();
    addRevisionWith2Mods(revisionsForUpstream3, git);
    Pipeline upstream3 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream3);
    assertPipelineMaterialRevisions(upstream3);
    List<MaterialRevision> revisionsForUpstream4 = new ArrayList<>();
    addRevisionWith2Mods(revisionsForUpstream4, git);
    Pipeline upstream4 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream4);
    assertPipelineMaterialRevisions(upstream4);
    List<MaterialRevision> depMaterialRevision = new ArrayList<>();
    dbHelper.addDependencyRevisionModification(depMaterialRevision, dependencyMaterial, upstream2);
    Modification expectedMod = depMaterialRevision.get(0).getLatestModification();
    MaterialInstance dep = materialRepository.findOrCreateFrom(dependencyMaterial);
    saveRev(expectedMod, dep);
    dbHelper.addDependencyRevisionModification(depMaterialRevision, dependencyMaterial, upstream3);
    saveRev(depMaterialRevision.get(0).getLatestModification(), dep);
    List<MaterialRevision> revisionsForDownstream2 = new ArrayList<>();
    dbHelper.addDependencyRevisionModification(revisionsForDownstream2, dependencyMaterial, upstream4);
    Pipeline downstream2 = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), downstreamConfig, revisionsForDownstream2);
    List<PipelineMaterialRevision> pmrs = materialRepository.findPipelineMaterialRevisions(downstream2.getId());
    assertThat(pmrs.size(), is(1));
    assertThat(pmrs.get(0).getActualFromRevisionId(), is(expectedMod.getId()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PipelineMaterialRevision(com.thoughtworks.go.domain.PipelineMaterialRevision) Pipeline(com.thoughtworks.go.domain.Pipeline) Username(com.thoughtworks.go.server.domain.Username) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) PipelineMaterialRevision(com.thoughtworks.go.domain.PipelineMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) SvnMaterialInstance(com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance) Test(org.junit.Test)

Aggregations

DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)1 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)1 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)1 Pipeline (com.thoughtworks.go.domain.Pipeline)1 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)1 Modification (com.thoughtworks.go.domain.materials.Modification)1 SvnMaterialInstance (com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance)1 Username (com.thoughtworks.go.server.domain.Username)1 Test (org.junit.Test)1