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