use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class PipelineUnlockApiServiceTest method unlockShouldSetResultToNotAcceptableWhenAPipelineInstanceIsCurrentlyRunning.
@Test
public void unlockShouldSetResultToNotAcceptableWhenAPipelineInstanceIsCurrentlyRunning() throws Exception {
when(securityService.hasOperatePermissionForPipeline(new CaseInsensitiveString("username"), "pipeline-name")).thenReturn(true);
when(goConfigService.hasPipelineNamed(new CaseInsensitiveString("pipeline-name"))).thenReturn(true);
when(goConfigService.isLockable("pipeline-name")).thenReturn(true);
StageIdentifier identifier = new StageIdentifier("pipeline-name", 10, "10", "stage", "1");
when(pipelineLockService.lockedPipeline("pipeline-name")).thenReturn(identifier);
when(stageService.isAnyStageActiveForPipeline(identifier.pipelineIdentifier())).thenReturn(true);
HttpOperationResult result = new HttpOperationResult();
pipelineUnlockApiService.unlock("pipeline-name", new Username(new CaseInsensitiveString("username")), result);
assertThat(result.httpCode(), is(409));
assertThat(result.message(), is("Locked pipeline instance is currently running (one of the stages is in progress)"));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class PipelineUnlockApiServiceTest method unlockShouldSetResultToNotAcceptableWhenNoPipelineInstanceIsCurrentlyLocked.
@Test
public void unlockShouldSetResultToNotAcceptableWhenNoPipelineInstanceIsCurrentlyLocked() throws Exception {
Mockito.when(securityService.hasOperatePermissionForPipeline(new CaseInsensitiveString("username"), "pipeline-name")).thenReturn(true);
Mockito.when(goConfigService.hasPipelineNamed(new CaseInsensitiveString("pipeline-name"))).thenReturn(true);
Mockito.when(goConfigService.isLockable("pipeline-name")).thenReturn(true);
Mockito.when(pipelineLockService.lockedPipeline("pipeline-name")).thenReturn(null);
HttpOperationResult result = new HttpOperationResult();
pipelineUnlockApiService.unlock("pipeline-name", new Username(new CaseInsensitiveString("username")), result);
assertThat(result.httpCode(), is(409));
assertThat(result.message(), is("Lock exists within the pipeline configuration but no pipeline instance is currently in progress"));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class BuildCauseController method index.
public String index(Request req, Response res) throws IOException {
HttpOperationResult httpOperationResult = new HttpOperationResult();
int result;
try {
result = Integer.parseInt(req.params(":pipeline_counter"));
} catch (NumberFormatException nfe) {
throw new BadRequestException("Parameter `pipeline_counter` must be an integer.");
}
String pipelineName = req.params("pipeline_name");
PipelineInstanceModel pipelineInstance = pipelineHistoryService.findPipelineInstance(pipelineName, result, currentUsername(), httpOperationResult);
if (httpOperationResult.isSuccess()) {
return writerForTopLevelObject(req, res, outputWriter -> BuildCauseRepresenter.toJSON(outputWriter, pipelineInstance.getBuildCause()));
} else {
return renderHTTPOperationResult(httpOperationResult, req, res);
}
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldNotIncludeStageWithJobRerunWhileGettingLastStageInstances.
@Test
public void shouldNotIncludeStageWithJobRerunWhileGettingLastStageInstances() throws Exception {
configHelper.addPipeline(mingleConfig);
configHelper.turnOffSecurity();
List<Pipeline> completedPipelines = new ArrayList<>();
for (int i = 0; i < 5; i++) {
Pipeline completed = dbHelper.schedulePipelineWithAllStages(mingleConfig, ModificationsMother.modifySomeFiles(mingleConfig));
dbHelper.pass(completed);
completedPipelines.add(completed);
}
HttpOperationResult result = new HttpOperationResult();
scheduleService.rerunJobs(completedPipelines.get(0).getFirstStage(), asList(CaseInsensitiveString.str(mingleConfig.first().getJobs().first().name())), result);
List<Stage> stages = stageDao.findStageHistoryForChart(mingleConfig.name().toString(), mingleConfig.first().name().toString(), 10, 0);
assertThat(stages.size()).isEqualTo(5);
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class MaterialModificationsControllerV2 method modifications.
public String modifications(Request req, Response res) throws IOException {
String fingerprint = req.params("fingerprint");
Integer offset = req.params("offset") == null ? null : Integer.parseInt(req.params("offset"));
HttpOperationResult result = new HttpOperationResult();
MaterialConfig materialConfig = materialConfigService.getMaterialConfig(currentUsernameString(), fingerprint, result);
if (result.canContinue()) {
Long modificationsCount = materialService.getTotalModificationsFor(materialConfig);
Pagination pagination = Pagination.pageStartingAt(offset, modificationsCount.intValue(), 10);
Modifications modifications = materialService.getModificationsFor(materialConfig, pagination);
return writerForTopLevelObject(req, res, writer -> ModificationsRepresenter.toJSON(writer, modifications, pagination, fingerprint));
} else {
return renderHTTPOperationResult(result, req, res);
}
}
Aggregations