Search in sources :

Example 1 with PipelineStatusModel

use of com.thoughtworks.go.presentation.PipelineStatusModel in project gocd by gocd.

the class PipelineHistoryServiceTest method shouldPopulateResultAsNotFound_getPipelineStatus.

@Test
public void shouldPopulateResultAsNotFound_getPipelineStatus() {
    CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
    when(cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("pipeline-name"))).thenReturn(null);
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    HttpOperationResult result = new HttpOperationResult();
    PipelineStatusModel pipelineStatus = pipelineHistoryService.getPipelineStatus("pipeline-name", "user-name", result);
    assertThat(pipelineStatus, is(nullValue()));
    assertThat(result.httpCode(), is(404));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineStatusModel(com.thoughtworks.go.presentation.PipelineStatusModel) Test(org.junit.Test)

Example 2 with PipelineStatusModel

use of com.thoughtworks.go.presentation.PipelineStatusModel in project gocd by gocd.

the class PipelineHistoryService method getPipelineStatus.

public PipelineStatusModel getPipelineStatus(String pipelineName, String username, OperationResult result) {
    PipelineConfig pipelineConfig = goConfigService.currentCruiseConfig().getPipelineConfigByName(new CaseInsensitiveString(pipelineName));
    if (pipelineConfig == null) {
        result.notFound("Not Found", "Pipeline not found", HealthStateType.general(HealthStateScope.GLOBAL));
        return null;
    }
    if (!securityService.hasViewPermissionForPipeline(Username.valueOf(username), pipelineName)) {
        result.unauthorized("Unauthorized", NOT_AUTHORIZED_TO_VIEW_PIPELINE, HealthStateType.general(HealthStateScope.forPipeline(pipelineName)));
        return null;
    }
    PipelinePauseInfo pipelinePauseInfo = pipelinePauseService.pipelinePauseInfo(pipelineName);
    boolean isCurrentlyLocked = pipelineLockService.isLocked(pipelineName);
    boolean isSchedulable = schedulingCheckerService.canManuallyTrigger(pipelineConfig, username, new ServerHealthStateOperationResult());
    return new PipelineStatusModel(isCurrentlyLocked, isSchedulable, pipelinePauseInfo);
}
Also used : PipelinePauseInfo(com.thoughtworks.go.domain.PipelinePauseInfo) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) PipelineStatusModel(com.thoughtworks.go.presentation.PipelineStatusModel)

Example 3 with PipelineStatusModel

use of com.thoughtworks.go.presentation.PipelineStatusModel in project gocd by gocd.

the class PipelineHistoryServiceTest method shouldPopulateDataCorrectly_getPipelineStatus.

@Test
public void shouldPopulateDataCorrectly_getPipelineStatus() {
    CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
    PipelineConfig pipelineConfig = new PipelineConfig();
    PipelinePauseInfo pipelinePauseInfo = new PipelinePauseInfo(true, "pausing pipeline for some-reason", "some-one");
    when(cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("pipeline-name"))).thenReturn(pipelineConfig);
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(securityService.hasViewPermissionForPipeline(Username.valueOf("user-name"), "pipeline-name")).thenReturn(true);
    when(pipelinePauseService.pipelinePauseInfo("pipeline-name")).thenReturn(pipelinePauseInfo);
    when(pipelineLockService.isLocked("pipeline-name")).thenReturn(true);
    when(schedulingCheckerService.canManuallyTrigger(eq(pipelineConfig), eq("user-name"), any(ServerHealthStateOperationResult.class))).thenReturn(true);
    PipelineStatusModel pipelineStatus = pipelineHistoryService.getPipelineStatus("pipeline-name", "user-name", new HttpOperationResult());
    assertThat(pipelineStatus.isPaused(), is(true));
    assertThat(pipelineStatus.pausedCause(), is("pausing pipeline for some-reason"));
    assertThat(pipelineStatus.pausedBy(), is("some-one"));
    assertThat(pipelineStatus.isLocked(), is(true));
    assertThat(pipelineStatus.isSchedulable(), is(true));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) PipelineStatusModel(com.thoughtworks.go.presentation.PipelineStatusModel) Test(org.junit.Test)

Example 4 with PipelineStatusModel

use of com.thoughtworks.go.presentation.PipelineStatusModel in project gocd by gocd.

the class PipelineHistoryServiceTest method shouldPopulateResultAsUnauthorized_getPipelineStatus.

@Test
public void shouldPopulateResultAsUnauthorized_getPipelineStatus() {
    CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
    PipelineConfig pipelineConfig = new PipelineConfig();
    when(cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("pipeline-name"))).thenReturn(pipelineConfig);
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(securityService.hasViewPermissionForPipeline(Username.valueOf("user-name"), "pipeline-name")).thenReturn(false);
    HttpOperationResult result = new HttpOperationResult();
    PipelineStatusModel pipelineStatus = pipelineHistoryService.getPipelineStatus("pipeline-name", "user-name", result);
    assertThat(pipelineStatus, is(nullValue()));
    assertThat(result.httpCode(), is(401));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineStatusModel(com.thoughtworks.go.presentation.PipelineStatusModel) Test(org.junit.Test)

Aggregations

PipelineStatusModel (com.thoughtworks.go.presentation.PipelineStatusModel)4 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)3 Test (org.junit.Test)3 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)2 PipelinePauseInfo (com.thoughtworks.go.domain.PipelinePauseInfo)1