use of com.thoughtworks.go.server.transaction.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((List) stageList);
StageHistoryPage stageHistoryPage = stageDao.findStageHistoryPage(stage, 10);
StageHistoryPage stageHistoryPageInNextQuery = stageDao.findStageHistoryPage(stage, 10);
assertThat(stageHistoryPage.getStages()).isEqualTo(stageList);
assertThat(stageHistoryPage.getPagination()).isEqualTo(Pagination.pageFor(10, 20, 10));
assertThat(stageHistoryPageInNextQuery.getStages()).isEqualTo(stageList);
assertThat(stageHistoryPageInNextQuery.getPagination()).isEqualTo(Pagination.pageFor(10, 20, 10));
stageHistoryPage.getStages().get(0).setState(StageState.Failing);
assertThat(stageHistoryPageInNextQuery.getStages().get(0).getState()).isEqualTo(StageState.Passed);
verify(mockTemplate, times(1)).queryForList(eq("findStageHistoryPage"), any());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldServeStageByIdLookupFromCache.
@Test
public void shouldServeStageByIdLookupFromCache() throws Exception {
Pipeline[] pipelines = pipelineWithOnePassedAndOneCurrentlyRunning(mingleConfig);
Stage stage = pipelines[1].getStages().get(0);
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject("getStageById", stage.getId())).thenReturn(stage);
assertThat(stageDao.stageById(stage.getId())).isEqualTo(stage);
assertThat(stageDao.stageById(stage.getId())).isNotSameAs(stageDao.stageById(stage.getId()));
stageDao.jobStatusChanged(stage.getFirstJob());
assertThat(stageDao.stageById(stage.getId())).isEqualTo(stage);
verify(mockTemplate, times(2)).queryForObject("getStageById", stage.getId());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method getAllRunsOfStageForPipelineInstance_shouldRemoveFromCacheOnStageStatusChange.
@Test
public void getAllRunsOfStageForPipelineInstance_shouldRemoveFromCacheOnStageStatusChange() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage newStage = StageMother.passedStageInstance("pipeline", "stage", 2, "job", new Date());
Stage first = StageMother.passedStageInstance("pipeline", "stage", 1, "job", new Date());
List<Stage> expected = asList(first);
List<Stage> expectedSecondTime = asList(first, newStage);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForList(eq("getAllRunsOfStageForPipelineInstance"), any())).thenReturn((List) expected, (List) expectedSecondTime);
stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage");
Pipeline pipeline = PipelineMother.pipeline("pipeline");
pipeline.setCounter(1);
updateResultInTransaction(newStage, StageResult.Passed);
Stages actual = stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage");
assertThat(actual.size()).isEqualTo(2);
assertThat(actual).contains(newStage);
assertThat(actual).contains(first);
verify(mockTemplate, times(2)).queryForList(eq("getAllRunsOfStageForPipelineInstance"), any());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldCacheAllStagesForAPipelineInstance.
@Test
public void shouldCacheAllStagesForAPipelineInstance() {
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((List) stages);
Stages actual = stageDao.findAllStagesFor("pipeline", 1);
assertThat(actual).isEqualTo(new Stages(stages));
// Should return from cache
actual = stageDao.findAllStagesFor("pipeline", 1);
assertThat(actual).isEqualTo(new Stages(stages));
verify(mockTemplate, times(1)).queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method mostRecentId_shouldCacheResults.
@Test
public void mostRecentId_shouldCacheResults() throws Exception {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("getMostRecentId"), any())).thenReturn(20L);
stageDao.mostRecentId(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.get(0).name()));
Long id = stageDao.mostRecentId(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.get(0).name()));
assertThat(id).isEqualTo(20L);
verify(mockTemplate, times(1)).queryForObject(eq("getMostRecentId"), any());
}
Aggregations