Search in sources :

Example 46 with HttpOperationResult

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)"));
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 47 with HttpOperationResult

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"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 48 with HttpOperationResult

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);
    }
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) BadRequestException(com.thoughtworks.go.config.exceptions.BadRequestException)

Example 49 with HttpOperationResult

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);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.jupiter.api.Test)

Example 50 with HttpOperationResult

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);
    }
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Pagination(com.thoughtworks.go.server.util.Pagination) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig)

Aggregations

HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)146 Test (org.junit.jupiter.api.Test)64 Test (org.junit.Test)53 Username (com.thoughtworks.go.server.domain.Username)34 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)23 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)12 Pagination (com.thoughtworks.go.server.util.Pagination)7 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)6 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)6 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)6 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)6 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)5 AgentInstance (com.thoughtworks.go.domain.AgentInstance)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)4 NullStage (com.thoughtworks.go.domain.NullStage)4 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)4 PipelineStatusModel (com.thoughtworks.go.presentation.PipelineStatusModel)4 Stage (com.thoughtworks.go.domain.Stage)3