use of com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel in project gocd by gocd.
the class ValueStreamMapServiceIntegrationTest method shouldEmptyRevisionsOfPipelineWhenUserDoesNotHaveViewPermissionForThePipeline.
@Test
public void shouldEmptyRevisionsOfPipelineWhenUserDoesNotHaveViewPermissionForThePipeline() throws Exception {
/*
g1 --> p1 --> p --> p2 --> p4
/ \
g2 +-> p3
*/
GitMaterial g1 = u.wf(new GitMaterial("g1"), "f1");
u.checkinInOrder(g1, "g1-1");
GitMaterial g2 = u.wf(new GitMaterial("g2"), "f2");
u.checkinInOrder(g2, "g2-1");
ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWithGroup("g1", "p1", u.m(g1));
ScheduleTestUtil.AddedPipeline p = u.saveConfigWithGroup("g2", "p", u.m(g2), u.m(p1));
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWithGroup("g2", "p2", u.m(p));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWithGroup("g2", "p3", u.m(p));
ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWithGroup("g1", "p4", u.m(p2));
String p1_1 = u.runAndPass(p1, "g1-1");
String p_1 = u.runAndPass(p, "g2-1", p1_1);
String p2_1 = u.runAndPass(p2, p_1);
String p2_2 = u.runAndPass(p2, p_1);
String p3_1 = u.runAndPass(p3, p_1);
String p4_1 = u.runAndPass(p4, p2_1);
Username groupAdmin = new Username(new CaseInsensitiveString("pg2-admin"));
configHelper.addAuthorizedUserForPipelineGroup("pg1-admin", "g1");
configHelper.addAuthorizedUserForPipelineGroup("pg2-admin", "g2");
ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap("p", 1, groupAdmin, result);
List<List<Node>> allLevels = graph.getNodesAtEachLevel();
int CURRENT_PIPELINE_LEVEL = 2;
PipelineDependencyNode p1_node = (PipelineDependencyNode) allLevels.get(CURRENT_PIPELINE_LEVEL - 1).get(1);
assertThat(p1_node.revisions().toString(), p1_node.revisions().isEmpty(), is(true));
assertThat(ReflectionUtil.getField((p1_node.getMessage()), "key"), is("VSM_PIPELINE_UNAUTHORIZED"));
assertThat(p1_node.getViewType(), Is.is(VSMViewType.NO_PERMISSION));
PipelineDependencyNode currentNode = (PipelineDependencyNode) allLevels.get(CURRENT_PIPELINE_LEVEL).get(0);
assertThat(currentNode.revisions().toString(), currentNode.revisions().isEmpty(), is(false));
PipelineDependencyNode p2_node = (PipelineDependencyNode) allLevels.get(CURRENT_PIPELINE_LEVEL + 1).get(0);
assertThat(p2_node.revisions().toString(), p2_node.revisions().isEmpty(), is(false));
PipelineDependencyNode p3_node = (PipelineDependencyNode) allLevels.get(CURRENT_PIPELINE_LEVEL + 1).get(1);
assertThat(p3_node.revisions().toString(), p3_node.revisions().isEmpty(), is(false));
PipelineDependencyNode p4_node = (PipelineDependencyNode) allLevels.get(CURRENT_PIPELINE_LEVEL + 2).get(0);
assertThat(p4_node.revisions().toString(), p4_node.revisions().isEmpty(), is(true));
assertThat(ReflectionUtil.getField((p4_node.getMessage()), "key"), is("VSM_PIPELINE_UNAUTHORIZED"));
assertThat(p1_node.getViewType(), is(VSMViewType.NO_PERMISSION));
}
use of com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel in project gocd by gocd.
the class ValueStreamMapServiceTest method currentPipelineShouldNotHaveWarningsIfBuiltFromMultipleRevisionsWithSameLatestRevision.
@Test
public void currentPipelineShouldNotHaveWarningsIfBuiltFromMultipleRevisionsWithSameLatestRevision() {
/*
/-> P1 -- \
git -> p3
\-> P2 -- /
*/
GitMaterial git = new GitMaterial("git");
MaterialConfig gitConfig = git.config();
Modification rev1 = ModificationsMother.oneModifiedFile("rev1");
Modification rev2 = ModificationsMother.oneModifiedFile("rev2");
Modification rev3 = ModificationsMother.oneModifiedFile("rev3");
BuildCause p1buildCause = createBuildCauseForRevisions(new ArrayList<>(), asList(git), Arrays.asList(rev3, rev2, rev1));
BuildCause p2buildCause = createBuildCauseForRevisions(new ArrayList<>(), asList(git), Arrays.asList(rev3));
BuildCause p3buildCause = createBuildCauseForRevisions(asList(dependencyMaterial("p1", 1), dependencyMaterial("p2", 1)), new ArrayList<>(), new ArrayList<>());
when(pipelineService.buildCauseFor("p3", 1)).thenReturn(p3buildCause);
when(pipelineService.buildCauseFor("p1", 1)).thenReturn(p1buildCause);
when(pipelineService.buildCauseFor("p2", 1)).thenReturn(p2buildCause);
PipelineConfig p1Config = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(gitConfig));
PipelineConfig p2Config = PipelineConfigMother.pipelineConfig("p2", new MaterialConfigs(gitConfig));
PipelineConfig p3Config = PipelineConfigMother.pipelineConfig("p3", new MaterialConfigs(new DependencyMaterialConfig(p1Config.name(), p1Config.getFirstStageConfig().name()), new DependencyMaterialConfig(p2Config.name(), p2Config.getFirstStageConfig().name())));
CruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs(p1Config, p2Config, p3Config));
when(pipelineService.findPipelineByCounterOrLabel("p3", "1")).thenReturn(new Pipeline("p3", "LABEL-P3", p3buildCause));
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap("p3", 1, user, result);
assertNull(graph.getCurrentPipeline().getViewType());
}
use of com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel in project gocd by gocd.
the class ValueStreamMapServiceTest method shouldPopulateRevisionsForUpstreamPipelines.
@Test
public void shouldPopulateRevisionsForUpstreamPipelines() {
/*
* git---> p1 ---> p3
* | v ^
* +---> p2 -----+
* **/
GitMaterial git = new GitMaterial("git");
MaterialConfig gitConfig = git.config();
BuildCause p3buildCause = createBuildCause(asList("p1", "p2"), new ArrayList<>());
BuildCause p2buildCause = createBuildCauseForRevisions(asList(dependencyMaterial("p1", 2)), asList(git), ModificationsMother.multipleModificationList(0));
BuildCause p1buildCause = createBuildCause(new ArrayList<>(), asList(git));
Modifications modifications = p1buildCause.getMaterialRevisions().getMaterialRevision(0).getModifications();
when(pipelineService.buildCauseFor("p3", 1)).thenReturn(p3buildCause);
when(pipelineService.buildCauseFor("p2", 1)).thenReturn(p2buildCause);
when(pipelineService.buildCauseFor("p1", 1)).thenReturn(p1buildCause);
when(pipelineService.buildCauseFor("p1", 2)).thenReturn(p1buildCause);
PipelineConfig p1Config = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(gitConfig));
PipelineConfig p2Config = PipelineConfigMother.pipelineConfig("p2", new MaterialConfigs(gitConfig));
PipelineConfig p3Config = PipelineConfigMother.pipelineConfig("p3", new MaterialConfigs(new DependencyMaterialConfig(p1Config.name(), p1Config.getFirstStageConfig().name()), new DependencyMaterialConfig(p2Config.name(), p2Config.getFirstStageConfig().name())));
CruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs(p1Config, p2Config, p3Config));
when(pipelineService.findPipelineByCounterOrLabel("p3", "1")).thenReturn(new Pipeline("p3", "LABEL-P3", p3buildCause));
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap("p3", 1, user, result);
VSMTestHelper.assertNodeHasRevisions(graph, "p1", new PipelineRevision("p1", 1, "LABEL-p1-1"), new PipelineRevision("p1", 2, "LABEL-p1-2"));
VSMTestHelper.assertNodeHasRevisions(graph, "p2", new PipelineRevision("p2", 1, "LABEL-p2-1"));
VSMTestHelper.assertNodeHasRevisions(graph, "p3", new PipelineRevision("p3", 1, "LABEL-P3"));
VSMTestHelper.assertSCMNodeHasMaterialRevisions(graph, git.getFingerprint(), new MaterialRevision(git, false, modifications));
verify(runStagesPopulator).apply(any(ValueStreamMap.class));
}
use of com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel in project gocd by gocd.
the class ValueStreamMapServiceTest method shouldMoveNodeAndIntroduceDummyNodesWhenCurrentLevelIsDeeperThanExistingNodeLevel.
@Test
public void shouldMoveNodeAndIntroduceDummyNodesWhenCurrentLevelIsDeeperThanExistingNodeLevel() throws Exception {
/*
* +-------------+
* | v
* g---->p1---->p2 ---> p3
* | ^
* -------------+
*
* */
GitMaterial git = new GitMaterial("git");
MaterialConfig gitConfig = git.config();
String p1 = "p1";
String p2 = "p2";
String p3 = "p3";
BuildCause p3buildCause = createBuildCause(asList(p1, p2), new ArrayList<>());
BuildCause p2buildCause = createBuildCause(asList(p1), asList(git));
BuildCause p1buildCause = createBuildCause(new ArrayList<>(), asList(git));
when(pipelineService.buildCauseFor(p3, 1)).thenReturn(p3buildCause);
when(pipelineService.buildCauseFor(p2, 1)).thenReturn(p2buildCause);
when(pipelineService.buildCauseFor(p1, 1)).thenReturn(p1buildCause);
PipelineConfig p1Config = PipelineConfigMother.pipelineConfig(p1, new MaterialConfigs(gitConfig));
PipelineConfig p2Config = PipelineConfigMother.pipelineConfig(p2, new MaterialConfigs(gitConfig, new DependencyMaterialConfig(p1Config.name(), p1Config.getFirstStageConfig().name())));
PipelineConfig p3Config = PipelineConfigMother.pipelineConfig(p3, new MaterialConfigs(new DependencyMaterialConfig(p1Config.name(), p1Config.getFirstStageConfig().name()), new DependencyMaterialConfig(p2Config.name(), p2Config.getFirstStageConfig().name())));
CruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs(p1Config, p2Config, p3Config));
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(pipelineService.findPipelineByCounterOrLabel("p3", "1")).thenReturn(new Pipeline("p3", "p3-label", p3buildCause));
ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap(p3, 1, user, result);
List<List<Node>> nodesAtEachLevel = graph.getNodesAtEachLevel();
assertThat(graph.getCurrentPipeline().getName(), is(p3));
assertThat(nodesAtEachLevel.size(), is(4));
List<Node> firstLevel = nodesAtEachLevel.get(0);
assertThat(firstLevel.size(), is(1));
assertLayerHasNode(firstLevel, git.getDisplayName(), git.getFingerprint(), p1);
List<Node> secondLevel = nodesAtEachLevel.get(1);
assertThat(secondLevel.size(), is(2));
assertLayerHasNode(secondLevel, p1, p1, p2);
assertLayerHasDummyNodeWithDependents(secondLevel, p2);
List<Node> thirdLevel = nodesAtEachLevel.get(2);
assertThat(thirdLevel.size(), is(2));
assertLayerHasNode(thirdLevel, p2, p2, p3);
assertLayerHasDummyNodeWithDependents(thirdLevel, p3);
List<Node> fourthLevel = nodesAtEachLevel.get(3);
assertThat(fourthLevel.size(), is(1));
assertLayerHasNode(fourthLevel, p3, p3);
}
use of com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel in project gocd by gocd.
the class ValueStreamMapServiceTest method shouldGetPipelineDependencyGraphForAPipelineWithNoCrossLevelDependencies.
@Test
public void shouldGetPipelineDependencyGraphForAPipelineWithNoCrossLevelDependencies() {
/*
* svn => P1
* */
String pipeline = "P1";
int counter = 1;
BuildCause buildCause = PipelineMother.pipeline(pipeline, new Stage()).getBuildCause();
MaterialConfig material = buildCause.getMaterialRevisions().getMaterialRevision(0).getMaterial().config();
when(pipelineService.buildCauseFor(pipeline, counter)).thenReturn(buildCause);
PipelineConfig p1Config = PipelineConfigMother.pipelineConfig(pipeline, new MaterialConfigs(material));
when(goConfigService.currentCruiseConfig()).thenReturn(new BasicCruiseConfig(new BasicPipelineConfigs(p1Config)));
when(pipelineService.findPipelineByCounterOrLabel(pipeline, "1")).thenReturn(new Pipeline(pipeline, "p1-label", buildCause));
ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap(pipeline, counter, user, result);
List<List<Node>> nodesAtEachLevel = graph.getNodesAtEachLevel();
assertThat(graph.getCurrentPipeline().getName(), is(pipeline));
assertThat(nodesAtEachLevel.size(), is(2));
List<Node> firstLevel = nodesAtEachLevel.get(0);
assertThat(firstLevel.size(), is(1));
assertNode(-1, firstLevel.get(0), material.getDisplayName(), material.getFingerprint(), 0, pipeline);
List<Node> secondLevel = nodesAtEachLevel.get(1);
assertThat(secondLevel.size(), is(1));
assertNode(0, secondLevel.get(0), pipeline, pipeline, 0);
}
Aggregations