Search in sources :

Example 16 with ValueStreamMapPresentationModel

use of com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel in project gocd by gocd.

the class ValueStreamMapServiceTest method shouldPopulateErrorWhenUpstreamPipelineDoesNotExistInCurrentConfig.

@Test
public void shouldPopulateErrorWhenUpstreamPipelineDoesNotExistInCurrentConfig() throws Exception {
    /*
       * g --> p1 --> p3
        */
    GitMaterial git = new GitMaterial("git");
    BuildCause p3buildCause = createBuildCause(asList("p1"), new ArrayList<>());
    BuildCause p1buildCause = createBuildCause(new ArrayList<>(), asList(git));
    when(pipelineService.buildCauseFor("p3", 1)).thenReturn(p3buildCause);
    when(pipelineService.buildCauseFor("p1", 1)).thenReturn(p1buildCause);
    PipelineConfig p3Config = PipelineConfigMother.pipelineConfig("p3", new MaterialConfigs(new GitMaterialConfig("test")));
    CruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs(p3Config));
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(goConfigService.hasPipelineNamed(new CaseInsensitiveString("p1"))).thenReturn(false);
    when(pipelineService.findPipelineByCounterOrLabel("p3", "1")).thenReturn(new Pipeline("p3", "p3-label", p3buildCause));
    ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap("p3", 1, user, result);
    PipelineDependencyNode node = (PipelineDependencyNode) graph.getNodesAtEachLevel().get(1).get(0);
    assertThat(node.revisions().toString(), node.revisions().isEmpty(), is(true));
    assertThat(node.getViewType(), is(VSMViewType.DELETED));
    assertThat(ReflectionUtil.getField((node.getMessage()), "key"), is("VSM_PIPELINE_DELETED"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) ValueStreamMapPresentationModel(com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel) Test(org.junit.Test)

Example 17 with ValueStreamMapPresentationModel

use of com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel in project gocd by gocd.

the class ValueStreamMapServiceTest method shouldGetPipelineDependencyGraphForAPipelineWithDiamondDependency.

@Test
public void shouldGetPipelineDependencyGraphForAPipelineWithDiamondDependency() {
    /*
        * |----> P1----->
        * g             |_> p3
        * |             |
        * ---- > P2----->
        *
        * */
    GitMaterial git = new GitMaterial("git");
    BuildCause p3buildCause = createBuildCause(asList("p1", "p2"), new ArrayList<>());
    BuildCause p2buildCause = createBuildCause(new ArrayList<>(), 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(git.config()));
    PipelineConfig p2Config = PipelineConfigMother.pipelineConfig("p2", new MaterialConfigs(git.config()));
    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(3));
    List<Node> firstLevel = nodesAtEachLevel.get(0);
    assertThat(firstLevel.size(), is(1));
    assertNode(-2, firstLevel.get(0), git.getDisplayName(), git.getFingerprint(), 0, "p1", "p2");
    List<Node> secondLevel = nodesAtEachLevel.get(1);
    assertThat(secondLevel.size(), is(2));
    assertNode(-1, secondLevel.get(0), "p1", "p1", 0, "p3");
    assertNode(-1, secondLevel.get(1), "p2", "p2", 0, "p3");
    List<Node> thirdLevel = nodesAtEachLevel.get(2);
    assertThat(thirdLevel.size(), is(1));
    assertNode(0, thirdLevel.get(0), "p3", "p3", 0);
}
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) ValueStreamMapPresentationModel(com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 18 with ValueStreamMapPresentationModel

use of com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel in project gocd by gocd.

the class ValueStreamMapServiceTest method shouldBeCaseInsensitiveWhenGettingPipelineDependencyGraphForAPipeline.

@Test
public void shouldBeCaseInsensitiveWhenGettingPipelineDependencyGraphForAPipeline() {
    /*
        * svn => P1
        * */
    String pipelineName = "myPipeline";
    int counter = 1;
    BuildCause buildCause = PipelineMother.pipeline(pipelineName, new Stage()).getBuildCause();
    MaterialConfig materialConfig = buildCause.getMaterialRevisions().getMaterialRevision(0).getMaterial().config();
    PipelineConfig p1Config = PipelineConfigMother.pipelineConfig(pipelineName, new MaterialConfigs(materialConfig));
    when(pipelineService.buildCauseFor(pipelineName, counter)).thenReturn(buildCause);
    when(goConfigService.currentCruiseConfig()).thenReturn(new BasicCruiseConfig(new BasicPipelineConfigs(p1Config)));
    when(pipelineService.findPipelineByCounterOrLabel(pipelineName, "1")).thenReturn(new Pipeline("MYPIPELINE", "p1-label", buildCause));
    ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap("MYPIPELINE", counter, user, result);
    assertThat(graph.getCurrentPipeline().getName(), is(pipelineName));
    List<List<Node>> nodesAtEachLevel = graph.getNodesAtEachLevel();
    assertThat(nodesAtEachLevel.size(), is(2));
    List<Node> firstLevel = nodesAtEachLevel.get(0);
    assertThat(firstLevel.size(), is(1));
    assertNode(-1, firstLevel.get(0), materialConfig.getDisplayName(), materialConfig.getFingerprint(), 0, pipelineName);
    List<Node> secondLevel = nodesAtEachLevel.get(1);
    assertThat(secondLevel.size(), is(1));
    assertNode(0, secondLevel.get(0), pipelineName, pipelineName, 0);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Arrays.asList(java.util.Arrays.asList) ValueStreamMapPresentationModel(com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel) Test(org.junit.Test)

Example 19 with ValueStreamMapPresentationModel

use of com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel in project gocd by gocd.

the class ValueStreamMapServiceTest method shouldDrawDependenciesIncludingDownstreamBasedOnConfig.

@Test
public void shouldDrawDependenciesIncludingDownstreamBasedOnConfig() {
    /*
       * These are all the pipelines in the config.
       *
       * |----> p1----->
       * g             |_> p3
       * |             |
       * ---- > p2----->
       *
       * We are drawing a graph for 'p1' : g -> p1 -> p3
       * */
    CruiseConfig cruiseConfig = GoConfigMother.simpleDiamond();
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    String currentPipeline = "p1";
    String p3 = "p3";
    GitMaterial git = new GitMaterial("git");
    BuildCause p1buildCause = createBuildCause(new ArrayList<>(), asList(git));
    when(pipelineService.buildCauseFor(currentPipeline, 1)).thenReturn(p1buildCause);
    when(pipelineService.findPipelineByCounterOrLabel(currentPipeline, "1")).thenReturn(new Pipeline(currentPipeline, "p1-label", p1buildCause));
    ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap(currentPipeline, 1, user, result);
    List<List<Node>> nodesAtEachLevel = graph.getNodesAtEachLevel();
    assertThat(graph.getCurrentPipeline().getName(), is(currentPipeline));
    assertThat(nodesAtEachLevel.size(), is(3));
    assertLayerHasNode(nodesAtEachLevel.get(0), git.getDisplayName(), git.getFingerprint(), currentPipeline);
    assertLayerHasNode(nodesAtEachLevel.get(1), currentPipeline, currentPipeline, p3);
    assertLayerHasNode(nodesAtEachLevel.get(2), p3, p3);
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) Arrays.asList(java.util.Arrays.asList) ValueStreamMapPresentationModel(com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 20 with ValueStreamMapPresentationModel

use of com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel 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

ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)25 Test (org.junit.Test)24 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)20 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)16 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)16 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)12 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)11 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)9 Arrays.asList (java.util.Arrays.asList)8 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)6 List (java.util.List)5 Modification (com.thoughtworks.go.domain.materials.Modification)3 Modifications (com.thoughtworks.go.domain.materials.Modifications)3 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)2 Username (com.thoughtworks.go.server.domain.Username)2 RunIf (com.googlecode.junit.ext.RunIf)1 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)1 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)1 GitMaterialInstance (com.thoughtworks.go.domain.materials.git.GitMaterialInstance)1 DefaultLocalizedOperationResult (com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult)1