@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 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 shouldEncodeStageLocator() throws Exception {
   Stage stage1 =
       new Stage(
           "stage-c%d",
           new JobInstances(), GoConstants.DEFAULT_APPROVED_BY, "manual", new TimeProvider());
   stage1.setIdentifier(new StageIdentifier("pipeline-a%b", 1, "label-1", "stage-c%d", "1"));
   StageJsonPresentationModel presenter =
       new StageJsonPresentationModel(pipeline, stage1, null, new Agents());
   Map json = presenter.toJson();
   assertThat(
       JsonUtils.from(json).getString("stageLocator"), is("pipeline-a%25b/1/stage-c%25d/1"));
 }
 @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 shouldReturnErrorMessageWhenPostOfJobContainsDotForExecWorkingDir() throws Exception {
   configHelper.addPipeline("pipeline", "stage", "build1", "build2");
   String badXml =
       "<job name=\"build3\" >"
           + "<tasks>"
           + "<exec command=\"ant\" workingdir=\".\"/>"
           + "</tasks>"
           + "</job>";
   String md5 = goConfigDao.md5OfConfigFile();
   ModelAndView mav =
       controller.postBuildAsXmlPartial("pipeline", "stage", 0, badXml, md5, response);
   assertThat(response.getStatus(), is(SC_CONFLICT));
   assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON));
   Map json = (Map) mav.getModel().get("json");
   JsonValue jsonValue = JsonUtils.from(json);
   assertThat(unescapeJavaScript(jsonValue.getString("originalContent")), is(badXml));
   assertThat(
       unescapeJavaScript(jsonValue.getString("result")), containsString("File path is invalid"));
 }
  @Test
  public void shouldReturnJsonWithModifications() throws Exception {
    StageJsonPresentationModel presenter =
        new StageJsonPresentationModel(pipeline, stage, null, new Agents());
    Map json = presenter.toJson();

    JsonValue jsonValue = JsonUtils.from(json);
    JsonValue revision = jsonValue.getObject("materialRevisions", 0);
    // TODO: TRAINWRECK! WE should fix this when we re-do the JSON. We don't think this test will
    // last long in the new UI
    String expected =
        modifications
            .getMaterialRevisions()
            .getMaterialRevision(0)
            .getModifications()
            .get(0)
            .getRevision();
    assertThat(revision.getString("revision"), is(expected));
    assertThat(revision.getString("user"), is(ModificationsMother.MOD_USER_WITH_HTML_CHAR));
    assertThat(
        revision.getString("date"), is(DateUtils.formatISO8601(ModificationsMother.TODAY_CHECKIN)));
  }