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")))))));
}
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);
}
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();
}
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);
}
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.");
}
Aggregations