use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.
the class PipelineServiceTriangleDependencyTest method shouldChooseTheRevisionFromThirdWhenBothThirdAndSecondAreModified.
@Test
public void shouldChooseTheRevisionFromThirdWhenBothThirdAndSecondAreModified() throws Exception {
// Third* <- Second*
// | /
// | /
// Last
//
// * indicates changed
Date date = new Date();
MaterialRevisionBuilder builder = new MaterialRevisionBuilder(pipelineDao, materialRepository);
PipelineConfigDependencyGraph graph = builder.depInstance("last", 1, date, builder.depInstance("third", 3, date, builder.depInstance("second", 2, date, builder.svnInstance("1", date))), builder.depInstance("second", 4, date, builder.svnInstance("2", date))).getGraph();
MaterialRevisions actual = new MaterialRevisions();
actual.addRevision(builder.lookingAtDep("third", 3, date).markAsChanged().revision());
actual.addRevision(builder.lookingAtDep("second", 4, date).markAsChanged().revision());
MaterialRevisions expected = new MaterialRevisions();
expected.addRevision(builder.depInstance("third", 3, date).getRevision());
expected.addRevision(builder.depInstance("second", 2, date).getRevision());
MaterialRevisions finalRevisions = service.getRevisionsBasedOnDependencies(graph, actual);
assertThat(finalRevisions, is(expected));
for (int i = 0; i < expected.numberOfRevisions(); i++) {
assertTrue(finalRevisions.getMaterialRevision(i) == actual.getMaterialRevision(i));
}
}
use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.
the class PipelineServiceTriangleDependencyTest method shouldGetTheRevisionsFromTheUpStreamPipelineThatUsesTheSameMaterial.
@Test
public void shouldGetTheRevisionsFromTheUpStreamPipelineThatUsesTheSameMaterial() throws Exception {
MaterialRevisions expected = new MaterialRevisions();
MaterialRevision up1Revision = dependencyMaterialRevision("up1", 1, "label", "stage", 1, new Date());
up1Revision.markAsChanged();
expected.addRevision(up1Revision);
expected.addAll(createHgMaterialWithMultipleRevisions(1L, first));
expected.addAll(createSvnMaterialWithMultipleRevisions(2L, third));
MaterialRevisions actual = new MaterialRevisions();
actual.addRevision(up1Revision);
actual.addAll(createHgMaterialWithMultipleRevisions(1L, third));
actual.addAll(createSvnMaterialWithMultipleRevisions(2L, third));
PipelineConfig current = createPipelineConfigWithMaterialConfig("current", new DependencyMaterialConfig(new CaseInsensitiveString("up1"), new CaseInsensitiveString("first")), actual.getMaterials().get(0).config());
PipelineConfig up1 = createPipelineConfigWithMaterialConfig("up1", expected.getMaterials().get(1).config(), expected.getMaterials().get(2).config());
Pipeline pipeline = PipelineMother.passedPipelineInstance("up1", "stage", "job");
pipeline.setId(10);
when(pipelineDao.findPipelineByNameAndCounter("up1", 1)).thenReturn(pipeline);
when(materialRepository.findMaterialRevisionsForPipeline(10)).thenReturn(expected);
PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(current, new PipelineConfigDependencyGraph(up1));
assertThat(service.getRevisionsBasedOnDependencies(dependencyGraph, actual), is(expected));
}
use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.
the class PipelineServiceTriangleDependencyTest method shouldGetTheRevisionsFromTheUpStreamPipelineThatUsesTheSameMaterialEvenIfItIsNotADirectMaterial.
@Test
public void shouldGetTheRevisionsFromTheUpStreamPipelineThatUsesTheSameMaterialEvenIfItIsNotADirectMaterial() throws Exception {
MaterialRevisions uppestRevision = createHgMaterialWithMultipleRevisions(1L, first);
MaterialRevisions upRevision = new MaterialRevisions(dependencyMaterialRevision("up0", 2, "label", "stage", 1, new Date()));
MaterialRevisions expected = new MaterialRevisions(uppestRevision.getMaterialRevision(0));
MaterialRevision up1Revision = dependencyMaterialRevision("up1", 1, "label", "stage", 1, new Date());
up1Revision.markAsChanged();
expected.addRevision(up1Revision);
MaterialRevisions actual = createHgMaterialWithMultipleRevisions(1L, third);
actual.addRevision(up1Revision);
PipelineConfig current = createPipelineConfigWithMaterialConfig("current", actual.getMaterials().get(0).config(), new DependencyMaterialConfig(new CaseInsensitiveString("up1"), new CaseInsensitiveString("stage")));
PipelineConfig up1 = createPipelineConfigWithMaterialConfig("up1", upRevision.getMaterials().get(0).config());
PipelineConfig up0 = createPipelineConfigWithMaterialConfig("up0", uppestRevision.getMaterials().get(0).config());
Pipeline pipeline = PipelineMother.passedPipelineInstance("up1", "stage", "job");
pipeline.setId(10);
Pipeline uppestPipeline = PipelineMother.passedPipelineInstance("up0", "stage", "job");
uppestPipeline.setId(5);
when(pipelineDao.findPipelineByNameAndCounter("up1", 1)).thenReturn(pipeline);
when(materialRepository.findMaterialRevisionsForPipeline(10)).thenReturn(upRevision);
when(pipelineDao.findPipelineByNameAndCounter("up0", 2)).thenReturn(uppestPipeline);
when(materialRepository.findMaterialRevisionsForPipeline(5)).thenReturn(uppestRevision);
PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(current, new PipelineConfigDependencyGraph(up1, new PipelineConfigDependencyGraph(up0)));
assertThat(service.getRevisionsBasedOnDependencies(dependencyGraph, actual), is(expected));
}
use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.
the class PipelineServiceTriangleDependencyTest method shouldCopyMissingRevisionsForSameMaterialThatsUsedMoreThanOnce.
@Test
public void shouldCopyMissingRevisionsForSameMaterialThatsUsedMoreThanOnce() throws Exception {
PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("last");
pipelineConfig.materialConfigs().clear();
HgMaterialConfig onDirOne = MaterialConfigsMother.hgMaterialConfig("google.com", "dirOne");
HgMaterialConfig onDirTwo = MaterialConfigsMother.hgMaterialConfig("google.com", "dirTwo");
pipelineConfig.addMaterialConfig(onDirOne);
pipelineConfig.addMaterialConfig(onDirTwo);
HashMap<Material, String> materialToCommit = new HashMap<>();
materialToCommit.put(new MaterialConfigConverter().toMaterial(onDirOne), "abc");
materialToCommit.put(new MaterialConfigConverter().toMaterial(onDirTwo), "abc");
MaterialRevisions revs = ModificationsMother.getMaterialRevisions(materialToCommit);
MaterialRevisions finalRevisions = service.getRevisionsBasedOnDependencies(new PipelineConfigDependencyGraph(pipelineConfig), revs);
assertThat(finalRevisions.getRevisions(), is(revs.getRevisions()));
}
use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.
the class PipelineServiceTriangleDependencyTest method shouldChooseTheRevisionFromThirdWhenSecondIsNotModified.
@Test
public void shouldChooseTheRevisionFromThirdWhenSecondIsNotModified() throws Exception {
// Third* <- Second
// | /
// | /
// Last
//
// * indicates changed
Date date = new Date();
MaterialRevisionBuilder builder = new MaterialRevisionBuilder(pipelineDao, materialRepository);
PipelineConfigDependencyGraph graph = builder.depInstance("last", 1, date, builder.depInstance("third", 3, date, builder.depInstance("second", 2, date, builder.svnInstance("1", date))), builder.depInstance("second", 4, date, builder.svnInstance("2", date))).getGraph();
MaterialRevisions actual = new MaterialRevisions();
actual.addRevision(builder.lookingAtDep("third", 3, date).markAsChanged().revision());
actual.addRevision(builder.lookingAtDep("second", 4, date).revision());
MaterialRevisions expected = new MaterialRevisions();
expected.addRevision(builder.depInstance("third", 3, date).getRevision());
expected.addRevision(builder.depInstance("second", 2, date).getRevision());
MaterialRevisions finalRevisions = service.getRevisionsBasedOnDependencies(graph, actual);
assertThat(finalRevisions, is(expected));
for (int i = 0; i < expected.numberOfRevisions(); i++) {
assertTrue(finalRevisions.getMaterialRevision(i) == actual.getMaterialRevision(i));
}
}
Aggregations