use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class StageInstanceControllerV3 method cancelStage.
public String cancelStage(Request req, Response res) throws Exception {
HttpOperationResult result = new HttpOperationResult();
Optional<Stage> optionalStage = getStageFromRequestParam(req, result);
if (!result.isSuccess()) {
return renderHTTPOperationResult(result, req, res);
}
HttpLocalizedOperationResult localizedOperationResult = new HttpLocalizedOperationResult();
scheduleService.cancelAndTriggerRelevantStages(optionalStage.get().getId(), currentUsername(), localizedOperationResult);
return renderHTTPOperationResult(localizedOperationResult, req, res);
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class StageServiceTest method shouldPopulateErrorWhenPipelineWithCounterNotFound_findStageWithIdentifier.
@Test
public void shouldPopulateErrorWhenPipelineWithCounterNotFound_findStageWithIdentifier() {
when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipeline"))).thenReturn(true);
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(securityService.hasViewPermissionForPipeline(Username.valueOf("looser"), "pipeline")).thenReturn(true);
when(pipelineDao.findPipelineByNameAndCounter("pipeline", 1)).thenReturn(null);
final StageService stageService = new StageService(stageDao, jobInstanceService, mock(StageStatusTopic.class), mock(StageStatusCache.class), securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
HttpOperationResult result = new HttpOperationResult();
Stage stage = stageService.findStageWithIdentifier("pipeline", 1, "stage", "1", "looser", result);
assertThat(stage).isNull();
assertThat(result.httpCode()).isEqualTo(404);
assertThat(result.detailedMessage()).startsWith("Not Found { Pipeline 'pipeline' with counter '1' not found }");
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class StageLockCheckerTest method setUp.
@BeforeEach
public void setUp() throws Exception {
lockService = Mockito.mock(PipelineLockService.class);
pipeline = new PipelineIdentifier("mingle", 10, "2.0.10");
checker = new StageLockChecker(pipeline, lockService);
result = new HttpOperationResult();
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class StageServiceTest method shouldPopulateErrorWhenPipelineNotFound_findStageWithIdentifier.
@Test
public void shouldPopulateErrorWhenPipelineNotFound_findStageWithIdentifier() {
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);
HttpOperationResult result = new HttpOperationResult();
Stage stage = stageService.findStageWithIdentifier("pipeline", 1, "stage", "1", "looser", result);
assertThat(stage).isNull();
assertThat(result.httpCode()).isEqualTo(404);
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class StageServiceTest method shouldPopulateErrorWhenUnauthorized_findStageWithIdentifier.
@Test
public void shouldPopulateErrorWhenUnauthorized_findStageWithIdentifier() {
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);
HttpOperationResult result = new HttpOperationResult();
Stage stage = stageService.findStageWithIdentifier("pipeline", 1, "stage", "1", "looser", result);
assertThat(stage).isNull();
assertThat(result.httpCode()).isEqualTo(403);
}
Aggregations