use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldPaginateBasedOnOffset.
@Test
public void shouldPaginateBasedOnOffset() throws Exception {
HgMaterial hg = new HgMaterial("url", null);
String[] hg_revs = { "h1", "h2", "h3" };
scheduleUtil.checkinInOrder(hg, hg_revs);
String pipelineName = "p1";
String stageName = "stage_name";
ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
String run1 = scheduleUtil.runAndPass(p1, "h1");
String run2 = scheduleUtil.runAndPass(p1, "h2");
String run3 = scheduleUtil.runAndPass(p1, "h3");
String run4 = scheduleUtil.runAndPass(p1, "h1", "h2");
String run5 = scheduleUtil.runAndPass(p1, "h2", "h3");
String run6 = scheduleUtil.runAndPass(p1, "h3", "h1");
String run7 = scheduleUtil.runAndPass(p1, "h1", "h2", "h3");
Pagination pagination = Pagination.pageStartingAt(0, 7, 3);
StageInstanceModels stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertStageModels(stageInstanceModels, run7, run6, run5);
pagination = Pagination.pageStartingAt(1, 7, 3);
stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertStageModels(stageInstanceModels, run6, run5, run4);
pagination = Pagination.pageStartingAt(2, 7, 3);
stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertStageModels(stageInstanceModels, run5, run4, run3);
pagination = Pagination.pageStartingAt(3, 7, 3);
stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertStageModels(stageInstanceModels, run4, run3, run2);
pagination = Pagination.pageStartingAt(4, 7, 3);
stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertStageModels(stageInstanceModels, run3, run2, run1);
pagination = Pagination.pageStartingAt(5, 7, 3);
stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertStageModels(stageInstanceModels, run2, run1);
pagination = Pagination.pageStartingAt(6, 7, 3);
stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertStageModels(stageInstanceModels, run1);
pagination = Pagination.pageStartingAt(7, 7, 3);
stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertThat("Expected no models. Found: " + stageInstanceModels, stageInstanceModels.size(), is(0));
pagination = Pagination.pageStartingAt(20, 7, 3);
stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertThat("Expected no models. Found: " + stageInstanceModels, stageInstanceModels.size(), is(0));
pagination = Pagination.pageStartingAt(1, 7, 4);
stageInstanceModels = stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
assertStageModels(stageInstanceModels, run6, run5, run4, run3);
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class StageServiceTest method shouldPopulateErrorWhenUnauthorized_findDetailedStageHistoryByOffset.
@Test
public void shouldPopulateErrorWhenUnauthorized_findDetailedStageHistoryByOffset() {
when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipeline"))).thenReturn(true);
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(securityService.hasViewPermissionForPipeline(Username.valueOf("looser"), "pipeline")).thenReturn(false);
final StageService stageService = new StageService(stageDao, jobInstanceService, mock(StageStatusTopic.class), mock(StageStatusCache.class), securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
Pagination pagination = Pagination.pageStartingAt(1, 1, 1);
HttpOperationResult result = new HttpOperationResult();
StageInstanceModels stageInstanceModels = stageService.findDetailedStageHistoryByOffset("pipeline", "stage", pagination, "looser", result);
assertThat(stageInstanceModels, is(Matchers.nullValue()));
assertThat(result.httpCode(), is(401));
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class StageServiceTest method shouldPopulateErrorWhenPipelineNotFound_findDetailedStageHistoryByOffset.
@Test
public void shouldPopulateErrorWhenPipelineNotFound_findDetailedStageHistoryByOffset() {
when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipeline"))).thenReturn(false);
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(securityService.hasViewPermissionForPipeline(Username.valueOf("looser"), "pipeline")).thenReturn(true);
final StageService stageService = new StageService(stageDao, jobInstanceService, mock(StageStatusTopic.class), mock(StageStatusCache.class), securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
Pagination pagination = Pagination.pageStartingAt(1, 1, 1);
HttpOperationResult result = new HttpOperationResult();
StageInstanceModels stageInstanceModels = stageService.findDetailedStageHistoryByOffset("pipeline", "stage", pagination, "looser", result);
assertThat(stageInstanceModels, is(Matchers.nullValue()));
assertThat(result.httpCode(), is(404));
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class StageServiceTest method shouldDelegateToDAO_findDetailedStageHistoryByOffset.
@Test
public void shouldDelegateToDAO_findDetailedStageHistoryByOffset() {
when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipeline"))).thenReturn(true);
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(securityService.hasViewPermissionForPipeline(Username.valueOf("looser"), "pipeline")).thenReturn(true);
final StageService stageService = new StageService(stageDao, jobInstanceService, mock(StageStatusTopic.class), mock(StageStatusCache.class), securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
Pagination pagination = Pagination.pageStartingAt(1, 1, 1);
stageService.findDetailedStageHistoryByOffset("pipeline", "stage", pagination, "looser", new HttpOperationResult());
verify(stageDao).findDetailedStageHistoryByOffset("pipeline", "stage", pagination);
}
Aggregations