Search in sources :

Example 31 with HttpLocalizedOperationResult

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) RoleConfigDeleteCommand(com.thoughtworks.go.config.update.RoleConfigDeleteCommand) Test(org.junit.Test)

Example 32 with HttpLocalizedOperationResult

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) RoleConfigCreateCommand(com.thoughtworks.go.config.update.RoleConfigCreateCommand) Test(org.junit.Test)

Example 33 with HttpLocalizedOperationResult

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) RoleConfigUpdateCommand(com.thoughtworks.go.config.update.RoleConfigUpdateCommand) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 34 with HttpLocalizedOperationResult

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);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 35 with HttpLocalizedOperationResult

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