use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method getAllRunsOfStageForPipelineInstance_shouldClearCacheOnJobStateChange.
@Test
public void getAllRunsOfStageForPipelineInstance_shouldClearCacheOnJobStateChange() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage first = StageMother.passedStageInstance("pipeline", "stage", 1, "job", new Date());
Stage second = StageMother.passedStageInstance("pipeline", "stage", 2, "job", new Date());
Stage third = StageMother.passedStageInstance("pipeline", "stage", 3, "job", new Date());
List<Stage> expected = asList(third, second, first);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForList(eq("getAllRunsOfStageForPipelineInstance"), any())).thenReturn(expected);
assertThat(stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage"), is(expected));
stageDao.jobStatusChanged(first.getFirstJob());
assertThat(stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage"), is(expected));
stageDao.jobStatusChanged(second.getFirstJob());
assertThat(stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage"), is(expected));
verify(mockTemplate, times(3)).queryForList(eq("getAllRunsOfStageForPipelineInstance"), any());
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldClearCacheWhenJobStateChanges.
@Test
public void findStageWithIdentifier_shouldClearCacheWhenJobStateChanges() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage stage = StageMother.passedStageInstance("pipeline", "stage", "job", new Date());
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("findStageWithJobsByIdentifier"), any())).thenReturn(stage);
assertEquals(stage, stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1")));
stageDao.jobStatusChanged(stage.getFirstJob());
assertEquals(stage, stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1")));
verify(mockTemplate, times(2)).queryForObject(eq("findStageWithJobsByIdentifier"), any());
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldInvalidateCachedAllStagesForAPipelineInstanceWhenTheStatusOfAStageOfThisPipelineInstanceIsChanged.
@Test
public void shouldInvalidateCachedAllStagesForAPipelineInstanceWhenTheStatusOfAStageOfThisPipelineInstanceIsChanged() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
Stage stage1 = StageMother.passedStageInstance("first", "job", "pipeline");
Stage stage2 = StageMother.passedStageInstance("second", "job", "pipeline");
List<Stage> stages = asList(stage1, stage2);
when(mockTemplate.queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap())).thenReturn(stages);
Stages actual = stageDao.findAllStagesFor("pipeline", 1);
assertThat(actual, is(new Stages(stages)));
//Should invalidate the cached stages
stageDao.stageStatusChanged(StageMother.scheduledStage("pipeline", 1, "first", 2, "job"));
actual = stageDao.findAllStagesFor("pipeline", 1);
assertThat(actual, is(new Stages(stages)));
verify(mockTemplate, times(2)).queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap());
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldRemoveFromTheCacheOnStageStatusChange.
@Test
public void findStageWithIdentifier_shouldRemoveFromTheCacheOnStageStatusChange() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage stage = StageMother.passedStageInstance("pipeline", "stage", "job", new Date());
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("findStageWithJobsByIdentifier"), any())).thenReturn(stage);
Stage actual = stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
assertEquals(stage, actual);
assertFalse("Make sure the cached object is cloned", stage == actual);
updateResultInTransaction(actual, StageResult.Passed);
stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
verify(mockTemplate, times(2)).queryForObject(eq("findStageWithJobsByIdentifier"), any());
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findStageHistoryPage_shouldReturnStageHistoryEntryWithConfigVersion.
@Test
public void findStageHistoryPage_shouldReturnStageHistoryEntryWithConfigVersion() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage stage = StageMother.passedStageInstance("dev", "java", "pipeline-name");
stage.setApprovedBy("admin");
stage.setConfigVersion("md5-test");
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("getStageHistoryCount"), any())).thenReturn(20);
when(mockTemplate.queryForObject(eq("findOffsetForStage"), any())).thenReturn(10);
List<StageHistoryEntry> stageList = asList(new StageHistoryEntry(stage, 1, 10));
when(mockTemplate.queryForList(eq("findStageHistoryPage"), any())).thenReturn(stageList);
StageHistoryPage stageHistoryPage = stageDao.findStageHistoryPage(stage, 10);
assertThat(stageHistoryPage.getStages().get(0).getConfigVersion(), is("md5-test"));
}
Aggregations