use of com.thoughtworks.go.i18n.Localizable in project gocd by gocd.
the class HttpLocalizedOperationResultTest method shouldReturn401WhenNotAuthorized.
@Test
public void shouldReturn401WhenNotAuthorized() {
Localizable message = LocalizedMessage.cannotViewPipeline("whateva");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
result.unauthorized(message, HealthStateType.general(HealthStateScope.GLOBAL));
assertThat(result.httpCode(), is(401));
}
use of com.thoughtworks.go.i18n.Localizable in project gocd by gocd.
the class HttpLocalizedOperationResultTest method shouldReturnAccepted.
@Test
public void shouldReturnAccepted() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Localizable localizable = LocalizedMessage.string("KEY");
result.accepted(localizable);
assertThat(result.httpCode(), is(202));
assertThat(result.localizable(), is(localizable));
}
use of com.thoughtworks.go.i18n.Localizable in project gocd by gocd.
the class HttpLocalizedOperationResultTest method shouldReturnMessageAndStatus501WhenNotImplemented.
@Test
public void shouldReturnMessageAndStatus501WhenNotImplemented() {
Localizable message = mock(Localizable.class);
Localizer localizer = mock(Localizer.class);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(message.localize(localizer)).thenReturn("Seriously, whateva");
result.notImplemented(message);
assertThat(result.httpCode(), is(501));
}
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 AddEnvironmentCommand method canContinue.
@Override
public boolean canContinue(CruiseConfig cruiseConfig) {
if (!goConfigService.isUserAdmin(user)) {
Localizable noPermission = LocalizedMessage.string("NO_PERMISSION_TO_ADD_ENVIRONMENT", user.getDisplayName());
result.unauthorized(noPermission, HealthStateType.unauthorised());
return false;
}
CaseInsensitiveString environmentName = environmentConfig.name();
if (goConfigService.hasEnvironmentNamed(environmentName)) {
result.conflict(LocalizedMessage.string("RESOURCE_ALREADY_EXISTS", "environment", environmentName));
return false;
}
return true;
}
Aggregations