use of com.thoughtworks.go.i18n.Localizable in project gocd by gocd.
the class PatchEnvironmentCommandTest method shouldNotContinueIfTheUserDontHavePermissionsToOperateOnEnvironments.
@Test
public void shouldNotContinueIfTheUserDontHavePermissionsToOperateOnEnvironments() throws Exception {
PatchEnvironmentCommand command = new PatchEnvironmentCommand(goConfigService, environmentConfig, pipelinesToAdd, pipelinesToRemove, agentsToAdd, agentsToRemove, envVarsToAdd, envVarsToRemove, currentUser, actionFailed, result);
when(goConfigService.isAdministrator(currentUser.getUsername())).thenReturn(false);
assertThat(command.canContinue(cruiseConfig), is(false));
HttpLocalizedOperationResult expectResult = new HttpLocalizedOperationResult();
Localizable noPermission = LocalizedMessage.string("NO_PERMISSION_TO_UPDATE_ENVIRONMENT", environmentConfig.name().toString(), currentUser.getDisplayName());
expectResult.unauthorized(noPermission, HealthStateType.unauthorised());
assertThat(result, is(expectResult));
}
use of com.thoughtworks.go.i18n.Localizable in project gocd by gocd.
the class BackupServiceIntegrationTest method shouldReturnBackupRunningSinceValue_inISO8601_format.
@Test
public void shouldReturnBackupRunningSinceValue_inISO8601_format() throws InterruptedException {
assertThat(backupService.backupRunningSinceISO8601(), is(nullValue()));
final Semaphore waitForBackupToStart = new Semaphore(1);
final Semaphore waitForAssertionToCompleteWhileBackupIsOn = new Semaphore(1);
final HttpLocalizedOperationResult result = new HttpLocalizedOperationResult() {
@Override
public void setMessage(Localizable message) {
waitForBackupToStart.release();
super.setMessage(message);
try {
waitForAssertionToCompleteWhileBackupIsOn.acquire();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
};
waitForAssertionToCompleteWhileBackupIsOn.acquire();
waitForBackupToStart.acquire();
Thread backupThd = new Thread(new Runnable() {
public void run() {
backupService.startBackup(admin, result);
}
});
backupThd.start();
waitForBackupToStart.acquire();
String backupStartedTimeString = backupService.backupRunningSinceISO8601();
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime();
DateTime dateTime = dateTimeFormatter.parseDateTime(backupStartedTimeString);
assertThat(ReflectionUtil.getField(backupService, "backupRunningSince"), is(dateTime));
waitForAssertionToCompleteWhileBackupIsOn.release();
backupThd.join();
}
use of com.thoughtworks.go.i18n.Localizable in project gocd by gocd.
the class HttpLocalizedOperationResultTest method shouldReturn404AndLocalizeWhenNotFound.
@Test
public void shouldReturn404AndLocalizeWhenNotFound() {
Localizable message = mock(Localizable.class);
Localizer localizer = mock(Localizer.class);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(message.localize(localizer)).thenReturn("Seriously, whateva");
result.notFound(message, HealthStateType.general(HealthStateScope.GLOBAL));
assertThat(result.httpCode(), is(404));
assertThat(result.message(localizer), is("Seriously, whateva"));
}
use of com.thoughtworks.go.i18n.Localizable in project gocd by gocd.
the class PipelineConfigsService method updateXml.
public GoConfigOperationalResponse<PipelineConfigs> updateXml(String groupName, String xmlPartial, final String md5, Username username, HttpLocalizedOperationResult result) throws Exception {
if (!userHasPermissions(username, groupName, result)) {
return new GoConfigOperationalResponse<>(GoConfigValidity.valid(), null);
}
GoConfigValidity goConfigValidity = goConfigService.groupSaver(groupName).saveXml(xmlPartial, md5);
if (!goConfigValidity.isValid()) {
handleError(groupName, goConfigValidity, result);
return new GoConfigOperationalResponse<>(goConfigValidity, null);
}
Localizable savedSuccessMessage = LocalizedMessage.string("SAVED_CONFIGURATION_SUCCESSFULLY");
Localizable localizableMessage = goConfigValidity.wasMerged() ? LocalizedMessage.composite(savedSuccessMessage, LocalizedMessage.string("CONFIG_MERGED")) : savedSuccessMessage;
result.setMessage(localizableMessage);
PipelineConfigs pipelineConfigs = magicalGoConfigXmlLoader.fromXmlPartial(xmlPartial, BasicPipelineConfigs.class);
return new GoConfigOperationalResponse<>(goConfigValidity, pipelineConfigs);
}
use of com.thoughtworks.go.i18n.Localizable in project gocd by gocd.
the class UpdateEnvironmentCommandTest method shouldNotContinueIfTheUserDontHavePermissionsToOperateOnEnvironments.
@Test
public void shouldNotContinueIfTheUserDontHavePermissionsToOperateOnEnvironments() throws Exception {
UpdateEnvironmentCommand command = new UpdateEnvironmentCommand(goConfigService, oldEnvironmentConfig.name().toString(), newEnvironmentConfig, currentUser, actionFailed, md5, entityHashingService, result);
when(goConfigService.isAdministrator(currentUser.getUsername())).thenReturn(false);
assertThat(command.canContinue(cruiseConfig), is(false));
HttpLocalizedOperationResult expectResult = new HttpLocalizedOperationResult();
Localizable noPermission = LocalizedMessage.string("NO_PERMISSION_TO_UPDATE_ENVIRONMENT", oldEnvironmentConfig.name().toString(), currentUser.getDisplayName());
expectResult.unauthorized(noPermission, HealthStateType.unauthorised());
assertThat(result, is(expectResult));
}
Aggregations