@Test
 public void shouldCreateGroupForCurrentConfigIfItHasChanged() throws Exception {
   PipelineHistoryGroups historyGroups = preparePipelineHistoryGroups(pipelineConfig);
   PipelineConfig newConfig =
       PipelineConfigMother.createPipelineConfigWithStages("mingle", "stage1", "stage2");
   presenter =
       new PipelineHistoryJsonPresentationModel(
           pipelinePauseInfo,
           historyGroups,
           newConfig,
           pagination(),
           CAN_FORCE,
           hasForceBuildCause,
           hasModification,
           true);
   JsonTester jsonTester = new JsonTester(presenter.toJson());
   jsonTester.shouldContain(
       "{    'groups' : [ {"
           + "     'config' : {"
           + "         'stages' : [ "
           + "             {'name' : 'stage1', isAutoApproved : 'true'},"
           + "             {'name' : 'stage2', isAutoApproved : 'true'}"
           + "          ]"
           + "      }"
           + "    }, {"
           + "     'config' : {"
           + "         'stages' : [ "
           + "             {'name' : 'dev', isAutoApproved : 'true'},"
           + "             {'name' : 'ft', isAutoApproved : 'false'}"
           + "          ]"
           + "      }"
           + "    } ]"
           + "}");
 }
 @Test
 public void shouldContainPipelineCounterOrLabel() throws Exception {
   JsonMap jsonMap = presenter.toJson();
   JsonValue jsonValue = JsonUtils.from(jsonMap);
   JsonValue pipeline = jsonValue.getObject("groups", 0, "history", 0);
   assertThat(pipeline.getString("counterOrLabel"), is("1"));
 }
 @Test
 public void shouldShowFirstStageApproverNameInBuildCauseBy() throws Exception {
   JsonMap jsonMap = presenter.toJson();
   JsonValue jsonValue = JsonUtils.from(jsonMap);
   String revision = jsonValue.getString("groups", 0, "history", 0, "buildCauseBy");
   assertThat(revision, is("Triggered by " + GoConstants.DEFAULT_APPROVED_BY));
 }
 @Test
 public void needsApprovalInJsonShouldBeFalseWhenPipelineIsPaused() throws Exception {
   pipelinePauseInfo.setPaused(true);
   JsonTester jsonTester = new JsonTester(presenter.toJson());
   jsonTester.shouldContain("{ 'paused' : 'true' }");
   jsonTester.shouldNotContain("{ 'needsApproval' : 'true' }");
 }
 @Test
 public void shouldContainPipelineHistory() throws Exception {
   JsonMap json = presenter.toJson();
   JsonTester jsonTester = new JsonTester(json);
   jsonTester.shouldContain(
       "{    'groups' : [ {"
           + "      'history' : ["
           + "         { 'pipelineId' : '1',"
           + "           'scheduled_date' : 'less than a minute ago',"
           + "           'stages' : ["
           + "             { 'stageStatus' : 'Passed', 'stageName':'dev', 'stageId':'0',"
           + "               'approvedBy' : '"
           + DEFAULT_APPROVED_BY
           + "', "
           + "               'getCanRun' : 'false' , 'scheduled' : 'true' },"
           + "             { 'stageStatus' : 'Passed', 'stageName':'ft', 'stageId':'0',"
           + "               'approvedBy' : '"
           + APPROVED_BY
           + "', "
           + "               'getCanRun' : 'false', 'getCanCancel' : 'false',  'scheduled' : 'true'  }]"
           + "         }"
           + "       ]"
           + "    } ] "
           + "}");
 }
 @Test
 public void shouldEncodeStageLocator() {
   PipelineConfig pipelineConfig1 =
       PipelineConfigMother.createPipelineConfigWithStages("mingle-%", "stage1-%", "stage2");
   PipelineHistoryJsonPresentationModel presenter =
       new PipelineHistoryJsonPresentationModel(
           pipelinePauseInfo,
           preparePipelineHistoryGroups(pipelineConfig1),
           pipelineConfig1,
           pagination(),
           CAN_FORCE,
           hasForceBuildCause,
           hasModification,
           true);
   JsonValue json = JsonUtils.from(presenter.toJson());
   String stageLocator = json.getString("groups", 0, "history", 0, "stages", 0, "stageLocator");
   assertThat(stageLocator, is("mingle-%25/1/stage1-%25/1"));
 }
 @Test
 public void shouldContainMaterialRevisions() throws Exception {
   JsonMap jsonMap = presenter.toJson();
   JsonValue jsonValue = JsonUtils.from(jsonMap);
   JsonValue revision = jsonValue.getObject("groups", 0, "history", 0, "materialRevisions", 0);
   assertThat(revision.getString("revision"), is("svn.100"));
   assertThat(revision.getString("user"), is("user"));
   assertThat(revision.getString("date"), is(DateUtils.formatISO8601(modificationDate)));
 }
 @Test
 public void shouldContainPipelinePauseInfo() throws Exception {
   pipelinePauseInfo.setPaused(true);
   pipelinePauseInfo.setPauseCause("pauseCause");
   pipelinePauseInfo.setPauseBy("pauseBy");
   JsonTester jsonTester = new JsonTester(presenter.toJson());
   jsonTester.shouldContain("{ 'paused' : 'true' }");
   jsonTester.shouldContain("{ 'pauseCause' : 'pauseCause' }");
   jsonTester.shouldContain("{ 'pauseBy' : 'pauseBy' }");
 }
 @Test
 public void shouldContainPipelineConfig() throws Exception {
   JsonTester jsonTester = new JsonTester(presenter.toJson());
   jsonTester.shouldContain(
       "{    'groups' : [ {"
           + "     'config' : {"
           + "         'stages' : [ "
           + "             {'name' : 'dev', isAutoApproved : 'true'},"
           + "             {'name' : 'ft', isAutoApproved : 'false'}"
           + "          ]"
           + "      }"
           + "    } ] "
           + "}");
 }
 @Test
 public void shouldContainPipelinePageInfo() throws Exception {
   JsonTester jsonTester = new JsonTester(presenter.toJson());
   jsonTester.shouldContain(
       "{ 'pipelineName' : 'mingle',"
           + "   'count' : '"
           + COUNT
           + "',"
           + "   'canForce' : '"
           + (CAN_FORCE ? "true" : "false")
           + "',"
           + "   'start' : '"
           + START
           + "',"
           + "   'perPage' : '"
           + PER_PAGE
           + "',"
           + "}");
 }