use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntryEvenThoughOtherStageInstanceAreInBetween.
@Test
public void shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntryEvenThoughOtherStageInstanceAreInBetween() throws Exception {
HgMaterial hg = new HgMaterial("url", null);
String[] hg_revs = { "h1" };
scheduleUtil.checkinInOrder(hg, hg_revs);
String pipelineName = "p1";
String anotherPipeline = "p2";
String stageName = "stage_name";
String anotherStage = "another_stage_name";
ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
ScheduleTestUtil.AddedPipeline p2 = scheduleUtil.saveConfigWith(anotherPipeline, anotherStage, scheduleUtil.m(hg));
for (int i = 0; i < 11; i++) {
scheduleUtil.runAndPass(p1, "h1");
scheduleUtil.runAndPass(p2, "h1");
}
StageHistoryPage historyPage = stageDao.findStageHistoryPage(pipelineName, stageName, new FuncVarArg<Pagination, Object>() {
@Override
public Pagination call(Object... args) {
return Pagination.pageByNumber(2, 2, 10);
}
});
StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
assertThat(bottomOfFirstPage.getId(), is(topOfSecondPage.getId() + 2));
assertThat(bottomOfFirstPage.getIdentifier().getPipelineName(), is(pipelineName));
assertThat(bottomOfFirstPage.getIdentifier().getStageName(), is(stageName));
assertThat(bottomOfFirstPage.getIdentifier().getPipelineCounter(), is(2));
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldReturnNullStageHistoryEntryWhenGettingHistoryForPage1.
@Test
public void shouldReturnNullStageHistoryEntryWhenGettingHistoryForPage1() throws Exception {
HgMaterial hg = new HgMaterial("url", null);
String[] hg_revs = { "h1" };
scheduleUtil.checkinInOrder(hg, hg_revs);
String pipelineName = "p1";
String stageName = "stage_name";
ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
for (int i = 0; i < 10; i++) {
scheduleUtil.runAndPass(p1, "h1");
}
StageHistoryPage historyPage = stageDao.findStageHistoryPage(pipelineName, stageName, new FuncVarArg<Pagination, Object>() {
@Override
public Pagination call(Object... args) {
return Pagination.pageByNumber(1, 1, 10);
}
});
StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
assertThat(bottomOfFirstPage, is(Matchers.nullValue()));
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage 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());
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry.
@Test
public void shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry() throws Exception {
HgMaterial hg = new HgMaterial("url", null);
String[] hg_revs = { "h1" };
scheduleUtil.checkinInOrder(hg, hg_revs);
String pipelineName = "p1";
String stageName = "stage_name";
ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
for (int i = 0; i < 11; i++) {
scheduleUtil.runAndPass(p1, "h1");
}
StageHistoryPage historyPage = stageDao.findStageHistoryPage(pipelineName, stageName, new FuncVarArg<Pagination, Object>() {
@Override
public Pagination call(Object... args) {
return Pagination.pageByNumber(2, 2, 10);
}
});
StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
assertThat(bottomOfFirstPage.getId(), is(topOfSecondPage.getId() + 1));
assertThat(bottomOfFirstPage.getIdentifier().getPipelineName(), is(pipelineName));
assertThat(bottomOfFirstPage.getIdentifier().getStageName(), is(stageName));
assertThat(bottomOfFirstPage.getIdentifier().getPipelineCounter(), is(2));
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage in project gocd by gocd.
the class StageSqlMapDaoTest method shouldLoadStageHistoryEntryForAStageRunAfterTheLatestRunThatIsRetrievedForStageHistory.
@Test
public void shouldLoadStageHistoryEntryForAStageRunAfterTheLatestRunThatIsRetrievedForStageHistory() throws Exception {
String pipelineName = "some_pipeline_name";
String stageName = "some_stage_name";
FuncVarArg function = mock(FuncVarArg.class);
Pagination pagination = mock(Pagination.class);
when(pagination.getCurrentPage()).thenReturn(3);
when(pagination.getPageSize()).thenReturn(10);
when(function.call()).thenReturn(pagination);
StageSqlMapDao spy = spy(stageSqlMapDao);
List<StageHistoryEntry> expectedStageHistoryEntriesList = mock(ArrayList.class);
StageHistoryEntry topOfThisPage = mock(StageHistoryEntry.class);
when(expectedStageHistoryEntriesList.get(0)).thenReturn(topOfThisPage);
StageHistoryEntry bottomOfLastPage = mock(StageHistoryEntry.class);
doReturn(expectedStageHistoryEntriesList).when(spy).findStages(pagination, pipelineName, stageName);
doReturn(bottomOfLastPage).when(spy).findImmediateChronologicallyForwardStageHistoryEntry(topOfThisPage);
StageHistoryPage stageHistoryPage = spy.findStageHistoryPage(pipelineName, stageName, function);
assertThat(stageHistoryPage.getStages(), is(expectedStageHistoryEntriesList));
assertThat(stageHistoryPage.getImmediateChronologicallyForwardStageHistoryEntry(), is(bottomOfLastPage));
verify(spy, times(1)).findStages(pagination, pipelineName, stageName);
verify(spy, times(1)).findImmediateChronologicallyForwardStageHistoryEntry(expectedStageHistoryEntriesList.get(0));
}
Aggregations