コード例 #1
0
  @Test
  public void buildByIdWithTransitions_shouldCacheWhenQueriedFor() {
    jobInstanceDao.setSqlMapClientTemplate(mockTemplate);

    JobInstance job = JobInstanceMother.assigned("job");
    job.setId(1L);
    when(mockTemplate.queryForObject("buildByIdWithTransitions", 1L)).thenReturn(job);

    JobInstance actual = jobInstanceDao.buildByIdWithTransitions(1L);
    assertThat(actual, is(job));
    assertThat(actual == job, is(false));

    jobInstanceDao.buildByIdWithTransitions(1L);
    verify(mockTemplate, times(1)).queryForObject("buildByIdWithTransitions", 1L);
  }
コード例 #2
0
  @Test
  public void buildByIdWithTransitions_shouldClearFromCacheOnUpdateStatusOfJob() {
    jobInstanceDao.setSqlMapClientTemplate(mockTemplate);

    JobInstance job = JobInstanceMother.assigned("job");
    job.setId(1L);
    when(mockTemplate.queryForObject("buildByIdWithTransitions", 1L)).thenReturn(job);

    JobInstance actual = jobInstanceDao.buildByIdWithTransitions(1L);
    assertThat(actual, is(job));
    assertThat(actual == job, is(false));

    jobInstanceDao.updateStateAndResult(job); // Must clear cahced job instance

    jobInstanceDao.buildByIdWithTransitions(1L);
    verify(mockTemplate, times(2)).queryForObject("buildByIdWithTransitions", 1L);
  }
コード例 #3
0
 @Test
 public void shouldEncodeBuildLocator() throws Exception {
   JobInstance job = JobInstanceMother.assigned("job-%");
   Stage stage1 =
       new Stage(
           "stage-c%d",
           new JobInstances(job), GoConstants.DEFAULT_APPROVED_BY, "manual", new TimeProvider());
   stage1.setIdentifier(new StageIdentifier("pipeline-a%b", 1, "label-1", "stage-c%d", "1"));
   job.setIdentifier(
       new JobIdentifier("pipeline-a%b", 1, "label-1", "stage-c%d", "1", "job-%", 0L));
   StageJsonPresentationModel presenter =
       new StageJsonPresentationModel(pipeline, stage1, null, new Agents());
   Map json = presenter.toJson();
   assertThat(
       JsonUtils.from(json).getString("builds", 0, "buildLocator"),
       is("pipeline-a%25b/1/stage-c%25d/1/job-%25"));
 }