Search in sources :

Example 11 with Pagination

use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.

the class JobInstanceServiceTest method shouldPopulateErrorWhenPipelineNotFound_findJobHistoryPage.

@Test
public void shouldPopulateErrorWhenPipelineNotFound_findJobHistoryPage() {
    when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipeline"))).thenReturn(false);
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(securityService.hasViewPermissionForPipeline(Username.valueOf("looser"), "pipeline")).thenReturn(true);
    final JobInstanceService jobService = new JobInstanceService(jobInstanceDao, buildPropertiesService, topic, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, securityService, pluginManager, serverHealthService);
    Pagination pagination = Pagination.pageStartingAt(1, 1, 1);
    HttpOperationResult result = new HttpOperationResult();
    JobInstances jobHistoryPage = jobService.findJobHistoryPage("pipeline", "stage", "job", pagination, "looser", result);
    assertThat(jobHistoryPage, is(nullValue()));
    assertThat(result.httpCode(), is(404));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 12 with Pagination

use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.

the class JobInstanceServiceTest method shouldPopulateErrorWhenUnauthorized_findJobHistoryPage.

@Test
public void shouldPopulateErrorWhenUnauthorized_findJobHistoryPage() {
    when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipeline"))).thenReturn(true);
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(securityService.hasViewPermissionForPipeline(Username.valueOf("looser"), "pipeline")).thenReturn(false);
    final JobInstanceService jobService = new JobInstanceService(jobInstanceDao, buildPropertiesService, topic, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, securityService, pluginManager, serverHealthService);
    Pagination pagination = Pagination.pageStartingAt(1, 1, 1);
    HttpOperationResult result = new HttpOperationResult();
    JobInstances jobHistoryPage = jobService.findJobHistoryPage("pipeline", "stage", "job", pagination, "looser", result);
    assertThat(jobHistoryPage, is(nullValue()));
    assertThat(result.canContinue(), is(false));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 13 with Pagination

use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.

the class MaterialServiceTest method shouldDelegateToMaterialRepository_getModificationsFor.

@Test
public void shouldDelegateToMaterialRepository_getModificationsFor() {
    GitMaterialConfig materialConfig = new GitMaterialConfig("http://test.com");
    GitMaterialInstance gitMaterialInstance = new GitMaterialInstance("http://test.com", null, null, "flyweight");
    Pagination pagination = Pagination.pageStartingAt(0, 10, 10);
    Modifications modifications = new Modifications();
    modifications.add(new Modification("user", "comment", "email", new Date(), "revision"));
    when(materialRepository.findMaterialInstance(materialConfig)).thenReturn(gitMaterialInstance);
    when(materialRepository.getModificationsFor(gitMaterialInstance, pagination)).thenReturn(modifications);
    Modifications gotModifications = materialService.getModificationsFor(materialConfig, pagination);
    assertThat(gotModifications, is(modifications));
}
Also used : GitMaterialInstance(com.thoughtworks.go.domain.materials.git.GitMaterialInstance) Pagination(com.thoughtworks.go.server.util.Pagination) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) Date(java.util.Date) Test(org.junit.Test)

Example 14 with Pagination

use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.

the class StageService method findStageHistoryForChart.

public StageSummaryModels findStageHistoryForChart(String pipelineName, String stageName, int pageNumber, int pageSize, Username username) {
    int total = stageDao.getTotalStageCountForChart(pipelineName, stageName);
    Pagination pagination = Pagination.pageByNumber(pageNumber, total, pageSize);
    List<Stage> stages = stageDao.findStageHistoryForChart(pipelineName, stageName, pageSize, pagination.getOffset());
    StageSummaryModels stageSummaryModels = new StageSummaryModels();
    for (Stage forStage : stages) {
        StageSummaryModel stageSummaryByIdentifier = new StageSummaryModel(forStage, null, stageDao, forStage.getIdentifier());
        if (!stageSummaryByIdentifier.getStage().getState().completed()) {
            continue;
        }
        stageSummaryModels.add(stageSummaryByIdentifier);
    }
    stageSummaryModels.setPagination(pagination);
    return stageSummaryModels;
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageSummaryModel(com.thoughtworks.go.server.ui.StageSummaryModel) StageSummaryModels(com.thoughtworks.go.server.ui.StageSummaryModels)

Example 15 with Pagination

use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.

the class JobInstanceService method completedJobsOnAgent.

public JobInstancesModel completedJobsOnAgent(String uuid, JobHistoryColumns columnName, SortOrder order, int pageNumber, int pageSize) {
    int total = totalCompletedJobsCountOn(uuid);
    Pagination pagination = Pagination.pageByNumber(pageNumber, total, pageSize);
    return completedJobsOnAgent(uuid, columnName, order, pagination);
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination)

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