Search in sources :

Example 1 with EntitlementsExceptionMappingHandler

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

the class PolicyV1FilterTest method setUp.

@BeforeMethod
public void setUp() {
    MockitoAnnotations.initMocks(this);
    EntitlementsExceptionMappingHandler resourceErrorHandler = new EntitlementsExceptionMappingHandler(EntitlementRestGuiceModule.getEntitlementsErrorHandlers());
    filter = new PolicyV1Filter(applicationServiceFactory, resourceErrorHandler, contextHelper, debug);
    subject = new Subject();
    when(requestHandler.handleAction(any(Context.class), any(ActionRequest.class))).thenReturn(Promises.<ActionResponse, ResourceException>newResultPromise(newActionResponse((json(object(field("ttl", "1234567890")))))));
    when(requestHandler.handleCreate(any(Context.class), any(CreateRequest.class))).thenReturn(Promises.<ResourceResponse, ResourceException>newResultPromise(newResourceResponse("A", "1", (json(object(field("resourceTypeUuid", "abc-def-hij")))))));
    when(requestHandler.handleUpdate(any(Context.class), any(UpdateRequest.class))).thenReturn(Promises.<ResourceResponse, ResourceException>newResultPromise(newResourceResponse("A", "1", (json(object(field("resourceTypeUuid", "abc-def-hij")))))));
    when(requestHandler.handleRead(any(Context.class), any(ReadRequest.class))).thenReturn(Promises.<ResourceResponse, ResourceException>newResultPromise(newResourceResponse("A", "1", (json(object(field("resourceTypeUuid", "abc-def-hij")))))));
}
Also used : EntitlementsExceptionMappingHandler(org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler) Context(org.forgerock.services.context.Context) PolicyV1Filter(org.forgerock.openam.entitlement.rest.PolicyV1Filter) ActionRequest(org.forgerock.json.resource.ActionRequest) UpdateRequest(org.forgerock.json.resource.UpdateRequest) CreateRequest(org.forgerock.json.resource.CreateRequest) Subject(javax.security.auth.Subject) ReadRequest(org.forgerock.json.resource.ReadRequest) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with EntitlementsExceptionMappingHandler

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

the class EntitlementsExceptionMappingHandlerTest method shouldMapKnownErrorsAsConfigured.

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

Example 3 with EntitlementsExceptionMappingHandler

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

the class ApplicationV1FilterTest method setUp.

@BeforeMethod
public void setUp() {
    MockitoAnnotations.initMocks(this);
    EntitlementsExceptionMappingHandler resourceErrorHandler = new EntitlementsExceptionMappingHandler(EntitlementRestGuiceModule.getEntitlementsErrorHandlers());
    filter = new ApplicationV1Filter(resourceTypeService, applicationServiceFactory, resourceErrorHandler, contextHelper, applicationTransformer, debug);
    subject = new Subject();
}
Also used : EntitlementsExceptionMappingHandler(org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler) ApplicationV1Filter(org.forgerock.openam.entitlement.rest.ApplicationV1Filter) Subject(javax.security.auth.Subject) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with EntitlementsExceptionMappingHandler

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

the class EntitlementsExceptionMappingHandlerTest method shouldApplyRequestTypeOverrides.

@Test
public void shouldApplyRequestTypeOverrides() {
    // Given
    Map<RequestType, Map<Integer, Integer>> overrides = new HashMap<RequestType, Map<Integer, Integer>>();
    RequestType requestType = RequestType.CREATE;
    overrides.put(requestType, Collections.singletonMap(ResourceException.NOT_FOUND, ResourceException.BAD_REQUEST));
    EntitlementsExceptionMappingHandler errorHandler = new EntitlementsExceptionMappingHandler(Collections.singletonMap(ERROR_CODE, ResourceException.NOT_FOUND), overrides, Collections.<Integer, Integer>emptyMap());
    EntitlementException error = exception(ERROR_CODE, ERROR_MESSAGE);
    Request request = mock(Request.class);
    given(request.getRequestType()).willReturn(requestType);
    // When
    ResourceException result = errorHandler.handleError(request, error);
    // Then
    assertThat(result).isInstanceOf(BadRequestException.class).hasMessage(ERROR_MESSAGE);
}
Also used : EntitlementsExceptionMappingHandler(org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler) EntitlementException(com.sun.identity.entitlement.EntitlementException) HashMap(java.util.HashMap) Request(org.forgerock.json.resource.Request) BadRequestException(org.forgerock.json.resource.BadRequestException) ResourceException(org.forgerock.json.resource.ResourceException) HashMap(java.util.HashMap) Map(java.util.Map) RequestType(org.forgerock.json.resource.RequestType) Test(org.testng.annotations.Test)

Example 5 with EntitlementsExceptionMappingHandler

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

the class EntitlementsExceptionMappingHandlerTest method shouldGetExceptionMessageAsEnglish.

@Test
public void shouldGetExceptionMessageAsEnglish() throws Exception {
    // Given
    EntitlementsExceptionMappingHandler errorHandler = new EntitlementsExceptionMappingHandler(Collections.singletonMap(EntitlementException.EMPTY_PRIVILEGE_NAME, ResourceException.BAD_REQUEST));
    EntitlementException error = new EntitlementException(EntitlementException.EMPTY_PRIVILEGE_NAME);
    // When
    ResourceException result = errorHandler.handleError(getHttpServerContext("en"), null, error);
    // Then
    assertThat(result.getMessage()).isEqualTo("Policy name cannot be empty.");
}
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)

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