Search in sources :

Example 21 with Pagination

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);
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) Test(org.junit.Test)

Example 22 with Pagination

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));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) Test(org.junit.Test)

Example 23 with Pagination

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));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) Test(org.junit.Test)

Example 24 with Pagination

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);
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) Test(org.junit.Test)

Aggregations

Pagination (com.thoughtworks.go.server.util.Pagination)24 Test (org.junit.Test)16 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)7 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)7 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 StageHistoryEntry (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)5 StageHistoryPage (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage)5 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)4 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)3 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)3 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 Method (java.lang.reflect.Method)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 PipelineNotFoundException (com.thoughtworks.go.config.PipelineNotFoundException)1 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 PipelinePauseInfo (com.thoughtworks.go.domain.PipelinePauseInfo)1 GitMaterialInstance (com.thoughtworks.go.domain.materials.git.GitMaterialInstance)1