Search in sources :

Example 51 with HttpOperationResult

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);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) NullStage(com.thoughtworks.go.domain.NullStage) Stage(com.thoughtworks.go.domain.Stage)

Example 52 with HttpOperationResult

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

Example 53 with HttpOperationResult

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

Example 54 with 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);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 55 with HttpOperationResult

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

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