Search in sources :

Example 36 with PipelineConfigDependencyGraph

use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.

the class PipelineServiceTriangleDependencyTest method shouldGetTheRevisionsForDependencyMaterial_WithSharedParentInMiddleOfTheTree.

@Test
public void shouldGetTheRevisionsForDependencyMaterial_WithSharedParentInMiddleOfTheTree() throws Exception {
    Date modifiedTime = new Date();
    MaterialRevisions expected = new MaterialRevisions();
    expected.addRevision(dependencyMaterialRevision("up1", 1, "label", "stage", 1, modifiedTime));
    expected.addRevision(dependencyMaterialRevision("common", 3, "label", "first", 1, modifiedTime));
    MaterialRevisions actual = new MaterialRevisions();
    actual.addRevision(changedDependencyMaterialRevision("up1", 1, "label", "stage", 1, modifiedTime));
    actual.addRevision(changedDependencyMaterialRevision("common", 4, "label", "first", 1, modifiedTime));
    PipelineConfig current = createPipelineConfigWithMaterialConfig("current", new DependencyMaterialConfig(new CaseInsensitiveString("common"), new CaseInsensitiveString("first")), new DependencyMaterialConfig(new CaseInsensitiveString("up1"), new CaseInsensitiveString("first")));
    PipelineConfig up1 = createPipelineConfigWithMaterialConfig("up1", new DependencyMaterialConfig(new CaseInsensitiveString("common"), new CaseInsensitiveString("first")));
    PipelineConfig common = createPipelineConfigWithMaterialConfig("common", new DependencyMaterialConfig(new CaseInsensitiveString("commonsParent"), new CaseInsensitiveString("first")));
    PipelineConfig commonsParent = createPipelineConfigWithMaterialConfig("commonsParent", MaterialConfigsMother.hgMaterialConfig());
    Pipeline pipeline = PipelineMother.passedPipelineInstance("up1", "stage", "job");
    pipeline.setId(10);
    when(pipelineDao.findPipelineByNameAndCounter("up1", 1)).thenReturn(pipeline);
    MaterialRevisions upStreamPipelinesRevisions = new MaterialRevisions();
    upStreamPipelinesRevisions.addRevision(dependencyMaterialRevision("common", 3, "label", "first", 1, modifiedTime));
    when(materialRepository.findMaterialRevisionsForPipeline(10)).thenReturn(upStreamPipelinesRevisions);
    Pipeline commonPipeline = PipelineMother.passedPipelineInstance("common", "first", "job");
    commonPipeline.setId(5);
    when(pipelineDao.findPipelineByNameAndCounter("common", 3)).thenReturn(commonPipeline);
    MaterialRevisions commonPipelinesRevisions = new MaterialRevisions();
    upStreamPipelinesRevisions.addRevision(dependencyMaterialRevision("commonsParent", 2, "label-2", "first", 1, modifiedTime));
    when(materialRepository.findMaterialRevisionsForPipeline(5)).thenReturn(commonPipelinesRevisions);
    PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(current, new PipelineConfigDependencyGraph(up1, new PipelineConfigDependencyGraph(common, new PipelineConfigDependencyGraph(commonsParent))), new PipelineConfigDependencyGraph(common, new PipelineConfigDependencyGraph(commonsParent)));
    MaterialRevisions finalRevisions = service.getRevisionsBasedOnDependencies(dependencyGraph, actual);
    assertThat(finalRevisions, is(expected));
    for (int i = 0; i < expected.numberOfRevisions(); i++) {
        assertTrue(finalRevisions.getMaterialRevision(i) == actual.getMaterialRevision(i));
    }
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 37 with PipelineConfigDependencyGraph

use of com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph in project gocd by gocd.

the class GoConfigServiceTest method shouldReturnUpstreamDependencyGraphForAGivenPipeline.

@Test
public void shouldReturnUpstreamDependencyGraphForAGivenPipeline() throws Exception {
    PipelineConfig current = GoConfigMother.createPipelineConfigWithMaterialConfig("current", new DependencyMaterialConfig(new CaseInsensitiveString("up1"), new CaseInsensitiveString("first")), new DependencyMaterialConfig(new CaseInsensitiveString("up2"), new CaseInsensitiveString("first")));
    PipelineConfig up1 = GoConfigMother.createPipelineConfigWithMaterialConfig("up1", new DependencyMaterialConfig(new CaseInsensitiveString("uppest"), new CaseInsensitiveString("first")));
    PipelineConfig up2 = GoConfigMother.createPipelineConfigWithMaterialConfig("up2", new DependencyMaterialConfig(new CaseInsensitiveString("uppest"), new CaseInsensitiveString("first")));
    PipelineConfig uppest = GoConfigMother.createPipelineConfigWithMaterialConfig("uppest", MaterialConfigsMother.hgMaterialConfig());
    when(goConfigDao.load()).thenReturn(configWith(current, up1, up2, uppest));
    assertThat(goConfigService.upstreamDependencyGraphOf("current"), is(new PipelineConfigDependencyGraph(current, new PipelineConfigDependencyGraph(up1, new PipelineConfigDependencyGraph(uppest)), new PipelineConfigDependencyGraph(up2, new PipelineConfigDependencyGraph(uppest)))));
/*
                         uppest
                        /     \
                       up1   up2
                        \     /
                        current
        */
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Aggregations

PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)37 Test (org.junit.Test)32 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)31 Date (java.util.Date)28 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)21 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)16 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)12 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)11 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)8 Pipeline (com.thoughtworks.go.domain.Pipeline)7 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)7 ModificationsMother.changedDependencyMaterialRevision (com.thoughtworks.go.helper.ModificationsMother.changedDependencyMaterialRevision)7 ModificationsMother.dependencyMaterialRevision (com.thoughtworks.go.helper.ModificationsMother.dependencyMaterialRevision)7 MaterialRevisionBuilder (com.thoughtworks.go.server.functional.helpers.MaterialRevisionBuilder)6 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)3 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)3 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)3 Modification (com.thoughtworks.go.domain.materials.Modification)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 Materials (com.thoughtworks.go.config.materials.Materials)2