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));
}
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);
}
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));
}
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));
}
Aggregations