use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldNotCacheWhenTheStageIsNull.
@Test
public void findStageWithIdentifier_shouldNotCacheWhenTheStageIsNull() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("findStageWithJobsByIdentifier"), any())).thenReturn(null);
Stage actual = stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
assertThat(actual, is(new NullStage("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 JobInstanceSqlMapDaoTest method shouldCacheJobIdentifierForGivenAttributes.
@Test
public void shouldCacheJobIdentifierForGivenAttributes() throws Exception {
SqlMapClientTemplate template = mock(SqlMapClientTemplate.class);
jobInstanceDao.setSqlMapClientTemplate(template);
Map attrs = m("pipelineName", PIPELINE_NAME, "pipelineCounter", null, "pipelineLabel", savedPipeline.getLabel(), "stageName", STAGE_NAME, "stageCounter", counter, "jobName", JOB_NAME_IN_DIFFERENT_CASE);
JobIdentifier jobIdentifier = new JobIdentifier(PIPELINE_NAME, savedPipeline.getCounter(), savedPipeline.getLabel(), STAGE_NAME, String.valueOf(counter), JOB_NAME);
when(template.queryForObject("findJobId", attrs)).thenReturn(jobIdentifier);
assertThat(jobInstanceDao.findOriginalJobIdentifier(new StageIdentifier(PIPELINE_NAME, null, savedPipeline.getLabel(), STAGE_NAME, String.valueOf(counter)), JOB_NAME_IN_DIFFERENT_CASE), is(jobIdentifier));
verify(template).queryForObject("findJobId", attrs);
assertThat(jobInstanceDao.findOriginalJobIdentifier(new StageIdentifier(PIPELINE_NAME, null, savedPipeline.getLabel(), STAGE_NAME, String.valueOf(counter)), JOB_NAME_IN_DIFFERENT_CASE), not(sameInstance(jobIdentifier)));
assertThat(jobInstanceDao.findOriginalJobIdentifier(new StageIdentifier(PIPELINE_NAME, null, savedPipeline.getLabel(), STAGE_NAME, String.valueOf(counter)), JOB_NAME), is(jobIdentifier));
verifyNoMoreInteractions(template);
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class PipelineSqlMapDaoIntegrationTest method loadHistoryByIds_shouldLoadHistoryByIdWhenOnlyASingleIdIsNeedeSoThatItUsesTheExistingCacheForEnvironmentsPage.
@Test
public void loadHistoryByIds_shouldLoadHistoryByIdWhenOnlyASingleIdIsNeedeSoThatItUsesTheExistingCacheForEnvironmentsPage() throws Exception {
SqlMapClientTemplate origTemplate = pipelineDao.getSqlMapClientTemplate();
try {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
when(mockTemplate.queryForList(eq("getPipelineRange"), any())).thenReturn(Arrays.asList(2L));
pipelineDao.setSqlMapClientTemplate(mockTemplate);
PipelineInstanceModels pipelineHistories = pipelineDao.loadHistory("pipelineName", 1, 0);
verify(mockTemplate, never()).queryForList(eq("getPipelineHistoryByName"), any());
verify(mockTemplate, times(1)).queryForList(eq("getPipelineRange"), any());
} finally {
pipelineDao.setSqlMapClientTemplate(origTemplate);
}
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method isStageActive_shouldMakeIsActiveFalseWhenTheStageCompletes.
@Test
public void isStageActive_shouldMakeIsActiveFalseWhenTheStageCompletes() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("isStageActive"), any())).thenReturn(1).thenReturn(0);
boolean stageActive = stageDao.isStageActive(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name()));
assertThat(stageActive, is(true));
Stage stage = StageMother.completedFailedStageInstance(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name()), "job");
//The cached 'true' should now be removed
stageDao.stageStatusChanged(stage);
assertThat(stageDao.isStageActive(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name())), is(false));
verify(mockTemplate, times(2)).queryForObject(eq("isStageActive"), any());
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findStageHistoryPage_shouldCacheStageHistoryPage.
@Test
public void findStageHistoryPage_shouldCacheStageHistoryPage() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage stage = StageMother.passedStageInstance("dev", "java", "pipeline-name");
stage.setApprovedBy("admin");
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);
StageHistoryPage stageHistoryPageInNextQuery = stageDao.findStageHistoryPage(stage, 10);
assertThat(stageHistoryPage.getStages(), is(stageList));
assertThat(stageHistoryPage.getPagination(), is(Pagination.pageFor(10, 20, 10)));
assertThat(stageHistoryPageInNextQuery.getStages(), is(stageList));
assertThat(stageHistoryPageInNextQuery.getPagination(), is(Pagination.pageFor(10, 20, 10)));
stageHistoryPage.getStages().get(0).setState(StageState.Failing);
assertThat(stageHistoryPageInNextQuery.getStages().get(0).getState(), is(StageState.Passed));
verify(mockTemplate, times(1)).queryForList(eq("findStageHistoryPage"), any());
}
Aggregations