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()));
}
Aggregations