use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class ValueStreamMapServiceIntegrationTest method shouldPopulateInstanceDetailsForUpstreamAndDownstreamPipelines.
@Test
public void shouldPopulateInstanceDetailsForUpstreamAndDownstreamPipelines() 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.saveConfigWith("p1", u.m(g1));
ScheduleTestUtil.AddedPipeline p = u.saveConfigWith("p", u.m(g2), u.m(p1));
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("p2", u.m(p));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", u.m(p));
ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("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);
configHelper.addStageToPipeline("p2", "unrun_stage");
ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap("p", 1, username, result);
List<List<Node>> allLevels = graph.getNodesAtEachLevel();
int CURRENT_PIPELINE_LEVEL = 2;
Node currentNode = allLevels.get(CURRENT_PIPELINE_LEVEL).get(0);
assertEquals(currentNode.revisions().get(0), new PipelineRevision(currentNode.getName(), 1, "1"));
Node p1_node = allLevels.get(CURRENT_PIPELINE_LEVEL - 1).get(1);
assertInstances(p1_node, "p1", 1);
assertStageDetails(p1_node, 1, "s", 1, StageState.Passed);
assertInstances(allLevels.get(CURRENT_PIPELINE_LEVEL + 1).get(0), "p3", 1);
Node p2_node = allLevels.get(CURRENT_PIPELINE_LEVEL + 1).get(1);
assertInstances(p2_node, "p2", 1, 2);
assertStageDetails(p2_node, 1, "s", 1, StageState.Passed);
assertStageDetails(p2_node, 2, "s", 1, StageState.Passed);
assertStageDetails(p2_node, 1, "unrun_stage", 0, StageState.Unknown);
assertStageDetails(p2_node, 2, "unrun_stage", 0, StageState.Unknown);
assertInstances(allLevels.get(CURRENT_PIPELINE_LEVEL + 2).get(0), "p4", 1);
}
use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class ValueStreamMapServiceIntegrationTest method shouldReturnEmptyRevisionsOfPipelineWhenViewUserDoesNotHaveViewPermissionForSomeUpstreamPipelines.
@Test
public void shouldReturnEmptyRevisionsOfPipelineWhenViewUserDoesNotHaveViewPermissionForSomeUpstreamPipelines() 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 viewOnlyUser = new Username(new CaseInsensitiveString("pg2-view"));
configHelper.setViewPermissionForGroup("g1", "pg1-view");
configHelper.setViewPermissionForGroup("g2", "pg2-view");
ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap("p", 1, viewOnlyUser, 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(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.config.materials.git.GitMaterial in project gocd by gocd.
the class ValueStreamMapServiceIntegrationTest method shouldIncludeNewerDownstreamDependenciesIfConfigWasChangedAfterPipelineRun.
// Scenario: #7181
@Test
public void shouldIncludeNewerDownstreamDependenciesIfConfigWasChangedAfterPipelineRun() {
/*
* -----------Before --------------
* g1-----+
* |
* +---------P1------> P2
* |
* g2-----+
* *
* -----After config change ------
*
* g1-----+
* |
* g3-----+---------P1----->P3-------> P2
* |
* g2-----+
* */
int i = 0;
GitMaterial g1 = u.wf(new GitMaterial("git-1"), "folder3");
u.checkinInOrder(g1, u.d(i++), "g1-1");
GitMaterial g2 = u.wf(new GitMaterial("git-2"), "folder4");
u.checkinInOrder(g2, u.d(i++), "g2-1");
GitMaterial g3 = u.wf(new GitMaterial("git-3"), "folder5");
u.checkinInOrder(g3, u.d(i++), "g3-1");
ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("P1", u.m(g1), u.m(g2));
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("P2", u.m(p1));
String p1_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, u.d(i++), "g1-1", "g2-1");
String p2_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), p1_1);
// PDG for P1/1
ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap(pipelineName(p1), 1, username, result);
List<List<Node>> nodesAtEachLevel = graph.getNodesAtEachLevel();
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(2), 0, pipelineName(p2));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(1), 0, pipelineName(p1));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(0), 0, g1.getFingerprint(), g2.getFingerprint());
// PDG for P2/1
nodesAtEachLevel = valueStreamMapService.getValueStreamMap(pipelineName(p2), 1, username, result).getNodesAtEachLevel();
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(2), 0, pipelineName(p2));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(1), 0, pipelineName(p1));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(0), 0, g1.getFingerprint(), g2.getFingerprint());
// add g3 to p1, and add P3 dependent on p1
u.addMaterialToPipeline(p1, u.m(g3));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("P3", u.m(p1));
p2 = u.addMaterialToPipeline(p2, u.m(p3));
p2 = u.removeMaterialFromPipeline(p2, u.m(p1));
// PDG for P1/1 after config change, newly added material does not show up
nodesAtEachLevel = valueStreamMapService.getValueStreamMap(pipelineName(p1), 1, username, result).getNodesAtEachLevel();
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(3), 0, pipelineName(p2));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(2), 0, pipelineName(p3));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(1), 0, pipelineName(p1));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(0), 0, g1.getFingerprint(), g2.getFingerprint());
// PDG for P2/1, remains same after config change
nodesAtEachLevel = valueStreamMapService.getValueStreamMap(pipelineName(p2), 1, username, result).getNodesAtEachLevel();
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(2), 0, pipelineName(p2));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(1), 0, pipelineName(p1));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(0), 0, g1.getFingerprint(), g2.getFingerprint());
String p1_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, u.d(i++), "g1-1", "g2-1", "g3-1");
String p3_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p3, u.d(i++), p1_2);
String p2_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), p3_1);
// PDG for P2/2, with updated dependencies
nodesAtEachLevel = valueStreamMapService.getValueStreamMap(pipelineName(p2), 2, username, result).getNodesAtEachLevel();
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(3), 0, pipelineName(p2));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(2), 0, pipelineName(p3));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(1), 0, pipelineName(p1));
VSMTestHelper.assertThatLevelHasNodes(nodesAtEachLevel.get(0), 0, g1.getFingerprint(), g2.getFingerprint());
}
use of com.thoughtworks.go.config.materials.git.GitMaterial in project gocd by gocd.
the class ValueStreamMapServiceIntegrationTest method shouldDetectCycleWhenDependenciesAreInverted.
@Test
public void shouldDetectCycleWhenDependenciesAreInverted() {
/*
* git2 ----->
* |---->P1 ----> P2
* git1 ----->
*
* run pipelines once, config changes to :
*
* git1 -> P2 ----->P1
* ^
* git2 ---|
* */
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), u.m(g2));
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWithGroup("g1", "p2", u.m(p1));
String p1_1 = u.runAndPass(p1, "g1-1", "g2-1");
String p2_1 = u.runAndPass(p2, p1_1);
p2 = u.addMaterialToPipeline(p2, u.m(g1));
p2 = u.removeMaterialFromPipeline(p2, u.m(p1));
p1 = u.addMaterialToPipeline(p1, u.m(p2));
p1 = u.removeMaterialFromPipeline(p1, u.m(g1));
String p1_2 = u.runAndPass(p1, "g2-1", p2_1);
valueStreamMapService.getValueStreamMap("p1", 2, username, result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.httpCode(), is(SC_NOT_IMPLEMENTED));
assertThat(result.message(localizer), is(String.format("Value Stream Map of Pipeline 'p1' with counter '2' can not be rendered. Changes to the configuration have introduced complex dependencies for this instance which are not supported currently.", "p1", 2)));
}
use of com.thoughtworks.go.config.materials.git.GitMaterial 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));
}
Aggregations