use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry 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.presentation.pipelinehistory.StageHistoryEntry 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 Supplier<Pagination>() {
@Override
public Pagination get() {
return Pagination.pageByNumber(1, 1, 10);
}
});
StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
assertThat(bottomOfFirstPage).isNull();
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry 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 Supplier<Pagination>() {
@Override
public Pagination get() {
return Pagination.pageByNumber(2, 2, 10);
}
});
StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
assertThat(bottomOfFirstPage.getId()).isEqualTo(topOfSecondPage.getId() + 2);
assertThat(bottomOfFirstPage.getIdentifier().getPipelineName()).isEqualTo(pipelineName);
assertThat(bottomOfFirstPage.getIdentifier().getStageName()).isEqualTo(stageName);
assertThat(bottomOfFirstPage.getIdentifier().getPipelineCounter()).isEqualTo(2);
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry 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 Supplier<Pagination>() {
@Override
public Pagination get() {
return Pagination.pageByNumber(2, 2, 10);
}
});
StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
assertThat(bottomOfFirstPage.getId()).isEqualTo(topOfSecondPage.getId() + 1);
assertThat(bottomOfFirstPage.getIdentifier().getPipelineName()).isEqualTo(pipelineName);
assertThat(bottomOfFirstPage.getIdentifier().getStageName()).isEqualTo(stageName);
assertThat(bottomOfFirstPage.getIdentifier().getPipelineCounter()).isEqualTo(2);
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry in project gocd by gocd.
the class StageSqlMapDaoTest method shouldLoadStageHistoryEntryForAStageRunAfterTheLatestRunThatIsRetrievedForStageHistory.
@Test
void shouldLoadStageHistoryEntryForAStageRunAfterTheLatestRunThatIsRetrievedForStageHistory() {
String pipelineName = "some_pipeline_name";
String stageName = "some_stage_name";
Supplier function = mock(Supplier.class);
Pagination pagination = mock(Pagination.class);
when(pagination.getCurrentPage()).thenReturn(3);
when(pagination.getPageSize()).thenReturn(10);
when(function.get()).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