use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class RoleConfigServiceTest method delete_shouldDeleteARole.
@Test
public void delete_shouldDeleteARole() throws Exception {
PluginRoleConfig role = new PluginRoleConfig("operate", "ldap");
Username admin = new Username("admin");
roleConfigService.delete(admin, role, new HttpLocalizedOperationResult());
verify(configService).updateConfig(any(RoleConfigDeleteCommand.class), eq(admin));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class RoleConfigServiceTest method create_shouldAddARoleToConfig.
@Test
public void create_shouldAddARoleToConfig() throws Exception {
PluginRoleConfig role = new PluginRoleConfig();
Username admin = new Username("admin");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
roleConfigService.create(admin, role, result);
verify(configService).updateConfig(any(RoleConfigCreateCommand.class), eq(admin));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class RoleConfigServiceTest method update_shouldUpdateAnExistingPluginRole.
@Test
public void update_shouldUpdateAnExistingPluginRole() throws Exception {
PluginRoleConfig role = new PluginRoleConfig();
Username admin = new Username("admin");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
roleConfigService.update(admin, "md5", role, result);
verify(configService).updateConfig(any(RoleConfigUpdateCommand.class), eq(admin));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class ScheduleServiceTest method shouldCancelStageUsingPipelineNameAndStageName.
@Test
public void shouldCancelStageUsingPipelineNameAndStageName() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
String pipelineName = "pipeline-name";
Username admin = new Username(new CaseInsensitiveString("admin"));
String stageName = "mingle";
Pipeline pipeline = PipelineMother.pipeline(pipelineName, StageMother.passedStageInstance(stageName, "job-bar", pipelineName));
Stage firstStage = pipeline.getFirstStage();
long stageId = firstStage.getId();
when(stageService.findLatestStage(pipelineName, stageName)).thenReturn(firstStage);
ScheduleService spyedService = spy(service);
doReturn(firstStage).when(spyedService).cancelAndTriggerRelevantStages(stageId, admin, result);
Stage resultStage = spyedService.cancelAndTriggerRelevantStages(pipelineName, stageName, admin, result);
assertThat(resultStage, is(firstStage));
assertThat(result.httpCode(), is(SC_OK));
assertThat(result.isSuccessful(), is(true));
verify(stageService).findLatestStage(pipelineName, stageName);
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class ScheduleServiceTest method shouldNotCancelStageWhenTheUserDoesNotHaveOperatePermission.
@Test
public void shouldNotCancelStageWhenTheUserDoesNotHaveOperatePermission() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Pipeline pipeline = PipelineMother.pipeline("pipeline-name", StageMother.passedStageInstance("mingle", "job-bar", "pipeline-name"));
Stage spiedStage = spy(pipeline.getFirstStage());
long stageId = spiedStage.getId();
Username admin = new Username(new CaseInsensitiveString("admin"));
doReturn(true).when(spiedStage).isActive();
when(stageService.stageById(stageId)).thenReturn(spiedStage);
when(securityService.hasOperatePermissionForStage(pipeline.getName(), spiedStage.getName(), admin.getUsername().toString())).thenReturn(false);
Stage resultStage = service.cancelAndTriggerRelevantStages(stageId, admin, result);
assertThat(resultStage, is(nullValue()));
assertThat(result.httpCode(), is(SC_UNAUTHORIZED));
assertThat(result.isSuccessful(), is(false));
verify(securityService).hasOperatePermissionForStage(pipeline.getName(), spiedStage.getName(), admin.getUsername().toString());
verify(stageService, never()).cancelStage(spiedStage);
verify(spiedStage).isActive();
}
Aggregations