use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PackageRepositoryServiceIntegrationTest method shouldReturnTheExactLocalizeMessageIfItFailsToCreatePackageRepository.
@Test
public void shouldReturnTheExactLocalizeMessageIfItFailsToCreatePackageRepository() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
String repoId = "npm";
PackageRepository npmRepo = new PackageRepository();
npmRepo.setId(repoId);
goConfigService.getConfigForEditing().setPackageRepositories(new PackageRepositories(npmRepo));
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.unauthorized(LocalizedMessage.string("UNAUTHORIZED_TO_EDIT"), HealthStateType.unauthorised());
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
service.createPackageRepository(npmRepo, new Username("UnauthorizedUser"), result);
assertThat(result, is(expectedResult));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PackageRepositoryServiceIntegrationTest method shouldReturnTheExactLocalizeMessageIfItFailsToDeletePackageRepository.
@Test
public void shouldReturnTheExactLocalizeMessageIfItFailsToDeletePackageRepository() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
String repoId = "npm";
PackageRepository npmRepo = new PackageRepository();
npmRepo.setId(repoId);
goConfigService.getConfigForEditing().setPackageRepositories(new PackageRepositories(npmRepo));
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.unauthorized(LocalizedMessage.string("UNAUTHORIZED_TO_EDIT"), HealthStateType.unauthorised());
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
service.deleteRepository(new Username("UnauthorizedUser"), npmRepo, result);
assertThat(result, is(expectedResult));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PackageRepositoryServiceIntegrationTest method shouldDeleteTheSpecifiedPackageRepository.
@Test
public void shouldDeleteTheSpecifiedPackageRepository() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
String repoId = "npm";
PackageRepository npmRepo = new PackageRepository();
npmRepo.setId(repoId);
goConfigService.getConfigForEditing().setPackageRepositories(new PackageRepositories(npmRepo));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
service.deleteRepository(username, npmRepo, result);
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.setMessage(LocalizedMessage.string("RESOURCE_DELETE_SUCCESSFUL", "package repository", npmRepo.getId()));
assertThat(result, is(expectedResult));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(0));
assertNull(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId));
}
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();
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class ScheduleServiceTest method shouldNotCancelStageIfItsNotActive.
@Test
public void shouldNotCancelStageIfItsNotActive() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Pipeline pipeline = PipelineMother.pipeline("pipeline-name", StageMother.passedStageInstance("mingle", "job-bar", "pipeline-name"));
Stage firstStage = pipeline.getFirstStage();
long stageId = firstStage.getId();
Username admin = new Username(new CaseInsensitiveString("admin"));
when(stageService.stageById(stageId)).thenReturn(firstStage);
Stage resultStage = service.cancelAndTriggerRelevantStages(stageId, admin, result);
assertThat(resultStage, is(firstStage));
assertThat(result.httpCode(), is(SC_OK));
assertThat(result.isSuccessful(), is(true));
assertThat(result.hasMessage(), is(true));
Localizer localizer = mock(Localizer.class);
String respMsg = "Stage is not active. Cancellation Ignored";
String stageNotActiveKey = "STAGE_IS_NOT_ACTIVE_FOR_CANCELLATION";
when(localizer.localize(eq(stageNotActiveKey), anyVararg())).thenReturn(respMsg);
assertThat(result.message(localizer), is(respMsg));
verify(stageService).stageById(stageId);
verify(localizer).localize(eq(stageNotActiveKey), anyVararg());
}
Aggregations