@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"));
 }
예제 #2
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 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)));
  }