@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));
 }
Exemplo n.º 3
0
  @Test
  public void shouldFindTheLatestJobWhenJobStatusIsRequested() throws Exception {
    JobInstance job =
        JobInstanceMother.buildEndingWithState(JobState.Rescheduled, JobResult.Unknown, "config");
    job.assign("agent", new Date());

    JobInstance newJob =
        JobInstanceMother.buildEndingWithState(
            JobState.Building, JobResult.Unknown, "another_config");
    newJob.setId(2);
    newJob.assign("another_agent", new Date());

    String pipelineName = job.getPipelineName();
    String stageName = job.getStageName();

    when(jobInstanceService.buildByIdWithTransitions(job.getId())).thenReturn(job);
    when(jobDetailService.findMostRecentBuild(job.getIdentifier())).thenReturn(newJob);
    when(stageService.getBuildDuration(pipelineName, stageName, newJob))
        .thenReturn(new DurationBean(newJob.getId(), 5l));

    ModelAndView modelAndView =
        jobController.handleRequest(pipelineName, stageName, job.getId(), response);

    verify(jobInstanceService).buildByIdWithTransitions(job.getId());
    verify(jobDetailService).findMostRecentBuild(job.getIdentifier());
    verify(stageService).getBuildDuration(pipelineName, stageName, newJob);

    JsonValue json = from(((JsonList) modelAndView.getModel().get("json")).getJsonMap(0));

    JsonValue buildingInfo = json.getObject("building_info");

    assertThat(buildingInfo.getString("id"), is("2"));
    assertThat(buildingInfo.getString("last_build_duration"), is("5"));
  }
 @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() {
   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)));
  }