Search in sources :

Example 71 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class PipelinePauseServiceTest method shouldPopulateHttpResult401WhenPipelineIsNotAuthorizedForUnPausing.

@Test
public void shouldPopulateHttpResult401WhenPipelineIsNotAuthorizedForUnPausing() throws Exception {
    setUpValidPipelineWithInvalidAuth();
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    pipelinePauseService.unpause(VALID_PIPELINE, INVALID_USER, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(SC_UNAUTHORIZED));
    verify(pipelineDao, never()).unpause(VALID_PIPELINE);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 72 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class PipelinePauseServiceTest method shouldPausePipelineWithCaptialName.

@Test
public void shouldPausePipelineWithCaptialName() throws Exception {
    setUpValidPipelineWithAuth();
    when(pipelineDao.pauseState(PIPELINE_WITH_CAPITAL_NAME)).thenReturn(new PipelinePauseInfo(false, "", VALID_USER.getUsername().toString()));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    pipelinePauseService.pause(PIPELINE_WITH_CAPITAL_NAME, "cause", VALID_USER, result);
    verify(pipelineDao).pause(PIPELINE_WITH_CAPITAL_NAME, "cause", VALID_USER.getUsername().toString());
    assertThat(result.isSuccessful(), is(true));
    assertThat(result.httpCode(), is(SC_OK));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PipelinePauseInfo(com.thoughtworks.go.domain.PipelinePauseInfo) Test(org.junit.Test)

Example 73 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class PipelinePauseServiceTest method shouldPopulateHttpResult500WhenPipelinePauseResultsInAnError.

@Test
public void shouldPopulateHttpResult500WhenPipelinePauseResultsInAnError() throws Exception {
    setUpValidPipelineWithAuth();
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    doThrow(new RuntimeException("Failed to pause")).when(pipelineDao).pause(VALID_PIPELINE, "cause", VALID_USER.getUsername().toString());
    pipelinePauseService.pause(VALID_PIPELINE, "cause", VALID_USER, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(SC_INTERNAL_SERVER_ERROR));
    verify(pipelineDao).pause(VALID_PIPELINE, "cause", VALID_USER.getUsername().toString());
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 74 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class PipelinePauseServiceTest method shouldNotPausePipelineWhenPipelineIsAlreadyPaused.

@Test
public void shouldNotPausePipelineWhenPipelineIsAlreadyPaused() throws Exception {
    setUpValidPipelineWithAuth();
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(pipelineDao.pauseState(VALID_PIPELINE)).thenReturn(new PipelinePauseInfo(true, "", VALID_USER.getUsername().toString()));
    pipelinePauseService.pause(VALID_PIPELINE, null, VALID_USER, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(409));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PipelinePauseInfo(com.thoughtworks.go.domain.PipelinePauseInfo) Test(org.junit.Test)

Example 75 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class PipelinePauseServiceTest method shouldPopulateHttpResult404WhenPipelineIsNotFoundForUnpause.

@Test
public void shouldPopulateHttpResult404WhenPipelineIsNotFoundForUnpause() throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(goConfigDao.load()).thenReturn(new BasicCruiseConfig());
    pipelinePauseService.unpause(INVALID_PIPELINE, VALID_USER, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(SC_NOT_FOUND));
    verify(pipelineDao, never()).unpause(INVALID_PIPELINE);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Aggregations

HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)437 Test (org.junit.Test)394 Username (com.thoughtworks.go.server.domain.Username)168 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)41 ArrayList (java.util.ArrayList)27 Before (org.junit.Before)26 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)24 Pipeline (com.thoughtworks.go.domain.Pipeline)24 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)20 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)20 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)19 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)18 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)17 AgentInstance (com.thoughtworks.go.domain.AgentInstance)17 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)17 GoCipher (com.thoughtworks.go.security.GoCipher)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)15 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)14 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14