Search in sources :

Example 96 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class ValueStreamMapServiceTest method shouldAddDummyNodesUpstreamAndDownstreamInDependencyGraph.

@Test
public void shouldAddDummyNodesUpstreamAndDownstreamInDependencyGraph() {
    /*
        * +------------+
        * |             v
        * g---->p1---->p2 ---> p3
        *        |             ^
        *        --------------+
        *
        * Drawing graph for p2, expected graph:
        *
        * +------X1------+
        * |             v
        * g---->p1---->p2 ---> p3
        * */
    String p1 = "p1";
    String p2 = "p2";
    String p3 = "p3";
    GitMaterial git = new GitMaterial("git");
    PipelineConfig p1Config = PipelineConfigMother.pipelineConfig(p1, new MaterialConfigs(git.config()));
    DependencyMaterial dependencyMaterialP1 = new DependencyMaterial(new CaseInsensitiveString(p1), p1Config.getFirstStageConfig().name());
    PipelineConfig p2Config = PipelineConfigMother.pipelineConfig(p2, new MaterialConfigs(git.config(), dependencyMaterialP1.config()));
    DependencyMaterial dependencyMaterialP2 = new DependencyMaterial(new CaseInsensitiveString(p2), p2Config.getFirstStageConfig().name());
    PipelineConfig p3Config = PipelineConfigMother.pipelineConfig(p3, new MaterialConfigs(dependencyMaterialP1.config(), dependencyMaterialP2.config()));
    CruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs(p1Config, p2Config, p3Config));
    BuildCause p1buildCause = createBuildCause(new ArrayList<>(), asList(git));
    BuildCause p2buildCause = createBuildCause(asList(p1), asList(git));
    when(pipelineService.buildCauseFor(p1, 1)).thenReturn(p1buildCause);
    when(pipelineService.buildCauseFor(p2, 1)).thenReturn(p2buildCause);
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(pipelineService.findPipelineByCounterOrLabel(p2, "1")).thenReturn(new Pipeline(p2, "label-p2", p2buildCause));
    ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap(p2, 1, user, result);
    List<List<Node>> nodesAtEachLevel = graph.getNodesAtEachLevel();
    assertThat(graph.getCurrentPipeline().getName(), is(p2));
    assertThat(nodesAtEachLevel.size(), is(4));
    assertThatLevelHasNodes(nodesAtEachLevel.get(0), 0, git.getFingerprint());
    Node gitNode = nodesAtEachLevel.get(0).get(0);
    assertNode(-2, gitNode, git.getDisplayName(), git.getFingerprint(), 1, p1);
    VSMTestHelper.assertThatNodeHasParents(gitNode, 0);
    assertThatLevelHasNodes(nodesAtEachLevel.get(1), 1, p1);
    assertLayerHasDummyNodeWithDependents(nodesAtEachLevel.get(1), p2);
    Node p1Node = nodesAtEachLevel.get(1).get(0);
    assertNode(-1, p1Node, p1, p1, 0, p2);
    VSMTestHelper.assertThatNodeHasParents(p1Node, 0, git.getFingerprint());
    assertThatLevelHasNodes(nodesAtEachLevel.get(2), 0, p2);
    Node p2Node = nodesAtEachLevel.get(2).get(0);
    assertNode(0, p2Node, p2, p2, 0, p3);
    VSMTestHelper.assertThatNodeHasParents(p2Node, 1, p1);
    assertThatLevelHasNodes(nodesAtEachLevel.get(3), 0, p3);
    Node p3Node = nodesAtEachLevel.get(3).get(0);
    assertNode(1, p3Node, p3, p3, 0);
    VSMTestHelper.assertThatNodeHasParents(p3Node, 0, p2);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Arrays.asList(java.util.Arrays.asList) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) ValueStreamMapPresentationModel(com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel) Test(org.junit.Test)

Aggregations

DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)96 Test (org.junit.Test)75 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)65 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)30 Modification (com.thoughtworks.go.domain.materials.Modification)30 Date (java.util.Date)24 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)19 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)18 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)16 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)15 Stage (com.thoughtworks.go.domain.Stage)14 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)13 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)13 Materials (com.thoughtworks.go.config.materials.Materials)12 Username (com.thoughtworks.go.server.domain.Username)12 Pipeline (com.thoughtworks.go.domain.Pipeline)11 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)11 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)10 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)9