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");
}
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");
}
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)));
}
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");
}
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());
}
Aggregations