Search in sources :

Example 66 with HttpLocalizedOperationResult

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

the class PipelineConfigsServiceTest method setUp.

@Before
public void setUp() {
    goConfigService = mock(GoConfigService.class);
    securityService = mock(SecurityService.class);
    configCache = new ConfigCache();
    registry = ConfigElementImplementationRegistryMother.withNoPlugins();
    validUser = new Username(new CaseInsensitiveString("validUser"));
    service = new PipelineConfigsService(configCache, registry, goConfigService, securityService);
    result = new HttpLocalizedOperationResult();
    cruiseConfig = new BasicCruiseConfig();
    ReflectionUtil.setField(cruiseConfig, "md5", "md5");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Before(org.junit.Before)

Example 67 with HttpLocalizedOperationResult

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

the class PipelineHistoryServiceTest method shouldFailWhenFeatureIsToggledOff_updateComment.

@Test
public void shouldFailWhenFeatureIsToggledOff_updateComment() {
    when(featureToggleService.isToggleOn(Toggles.PIPELINE_COMMENT_FEATURE_TOGGLE_KEY)).thenReturn(false);
    Toggles.initializeWith(featureToggleService);
    CaseInsensitiveString unauthorizedUser = new CaseInsensitiveString("cannot-access");
    String pipelineName = "pipeline_name";
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    pipelineHistoryService.updateComment(pipelineName, 1, "test comment", new Username(unauthorizedUser), result);
    assertThat(result.httpCode(), is(SC_NOT_IMPLEMENTED));
    assertThat(result.localizable(), is(LocalizedMessage.string("FEATURE_NOT_AVAILABLE", "Pipeline Comment")));
    verify(pipelineDao, never()).updateComment(pipelineName, 1, "test comment");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 68 with HttpLocalizedOperationResult

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

the class PipelineHistoryServiceTest method shouldNotUpdateCommentWhenUserIsUnauthorized.

@Test
public void shouldNotUpdateCommentWhenUserIsUnauthorized() {
    CaseInsensitiveString unauthorizedUser = new CaseInsensitiveString("cannot-access");
    String pipelineName = "pipeline_name";
    when(securityService.hasOperatePermissionForPipeline(unauthorizedUser, pipelineName)).thenReturn(false);
    HttpLocalizedOperationResult result = mock(HttpLocalizedOperationResult.class);
    pipelineHistoryService.updateComment(pipelineName, 1, "test comment", new Username(unauthorizedUser), result);
    verify(pipelineDao, never()).updateComment(pipelineName, 1, "test comment");
    verify(result, times(1)).unauthorized(LocalizedMessage.cannotOperatePipeline(pipelineName), HealthStateType.general(HealthStateScope.forPipeline(pipelineName)));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 69 with HttpLocalizedOperationResult

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

the class PipelineHistoryServiceTest method shouldUpdateCommentUsingPipelineDao.

@Test
public void shouldUpdateCommentUsingPipelineDao() {
    CaseInsensitiveString authorizedUser = new CaseInsensitiveString("can-access");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(securityService.hasOperatePermissionForPipeline(authorizedUser, "pipeline_name")).thenReturn(true);
    pipelineHistoryService.updateComment("pipeline_name", 1, "test comment", new Username(authorizedUser), result);
    verify(pipelineDao, times(1)).updateComment("pipeline_name", 1, "test comment");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 70 with HttpLocalizedOperationResult

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

the class PipelinePauseServiceTest method shouldPausePipelineEvenWhenPauseCauseIsNull.

@Test
public void shouldPausePipelineEvenWhenPauseCauseIsNull() throws Exception {
    setUpValidPipelineWithAuth();
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    pipelinePauseService.pause(VALID_PIPELINE, null, VALID_USER, result);
    assertThat(result.isSuccessful(), is(true));
    assertThat(result.httpCode(), is(SC_OK));
    verify(pipelineDao).pause(VALID_PIPELINE, "", VALID_USER.getUsername().toString());
}
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