Search in sources :

Example 6 with EntitlementsExceptionMappingHandler

use of org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler in project OpenAM by OpenRock.

the class EntitlementsExceptionMappingHandlerTest method shouldGetExceptionMessageAsFrench.

@Test
public void shouldGetExceptionMessageAsFrench() throws Exception {
    // Given
    EntitlementsExceptionMappingHandler errorHandler = new EntitlementsExceptionMappingHandler(Collections.singletonMap(EntitlementException.SUBJECT_REQUIRED, ResourceException.BAD_REQUEST));
    EntitlementException error = new EntitlementException(EntitlementException.SUBJECT_REQUIRED);
    // When
    ResourceException result = errorHandler.handleError(getHttpServerContext("fr"), null, error);
    // Then
    assertThat(result.getMessage()).isEqualTo("Les objets sont obligatoires.");
}
Also used : EntitlementsExceptionMappingHandler(org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler) EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 7 with EntitlementsExceptionMappingHandler

use of org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler in project OpenAM by OpenRock.

the class EntitlementsExceptionMappingHandlerTest method shouldMapUnknownErrorsAsServerErrors.

@Test
public void shouldMapUnknownErrorsAsServerErrors() {
    // Given
    EntitlementsExceptionMappingHandler errorHandler = new EntitlementsExceptionMappingHandler(Collections.<Integer, Integer>emptyMap());
    EntitlementException error = exception(ERROR_CODE, ERROR_MESSAGE);
    // When
    ResourceException result = errorHandler.handleError(error);
    // Then
    assertThat(result).isInstanceOf(InternalServerErrorException.class).hasMessage(ERROR_MESSAGE);
}
Also used : EntitlementsExceptionMappingHandler(org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler) EntitlementException(com.sun.identity.entitlement.EntitlementException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Aggregations

EntitlementsExceptionMappingHandler (org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler)7 EntitlementException (com.sun.identity.entitlement.EntitlementException)5 ResourceException (org.forgerock.json.resource.ResourceException)5 Test (org.testng.annotations.Test)5 Subject (javax.security.auth.Subject)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ActionRequest (org.forgerock.json.resource.ActionRequest)1 BadRequestException (org.forgerock.json.resource.BadRequestException)1 CreateRequest (org.forgerock.json.resource.CreateRequest)1 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)1 NotFoundException (org.forgerock.json.resource.NotFoundException)1 ReadRequest (org.forgerock.json.resource.ReadRequest)1 Request (org.forgerock.json.resource.Request)1 RequestType (org.forgerock.json.resource.RequestType)1 UpdateRequest (org.forgerock.json.resource.UpdateRequest)1 ApplicationV1Filter (org.forgerock.openam.entitlement.rest.ApplicationV1Filter)1 PolicyV1Filter (org.forgerock.openam.entitlement.rest.PolicyV1Filter)1 Context (org.forgerock.services.context.Context)1