Search in sources :

Example 1 with Localizable

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));
}
Also used : Localizable(com.thoughtworks.go.i18n.Localizable) Test(org.junit.Test)

Example 2 with Localizable

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));
}
Also used : Localizable(com.thoughtworks.go.i18n.Localizable) Test(org.junit.Test)

Example 3 with 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));
}
Also used : Localizer(com.thoughtworks.go.i18n.Localizer) Localizable(com.thoughtworks.go.i18n.Localizable) Test(org.junit.Test)

Example 4 with Localizable

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

Example 5 with Localizable

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;
}
Also used : Localizable(com.thoughtworks.go.i18n.Localizable)

Aggregations

Localizable (com.thoughtworks.go.i18n.Localizable)9 Test (org.junit.Test)6 Localizer (com.thoughtworks.go.i18n.Localizer)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2