use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class OathDevicesResourceTest method shouldNotDeleteTrustedDeviceWhenNotFound.
@Test
public void shouldNotDeleteTrustedDeviceWhenNotFound() throws ResourceException, SSOException {
// Given
DeleteRequest request = Requests.newDeleteRequest("UUID_3");
List<JsonValue> devices = new ArrayList<JsonValue>();
devices.add(json(object(field("uuid", "UUID_1"), field("name", "NAME_1"))));
devices.add(json(object(field("uuid", "UUID_2"), field("name", "NAME_2"))));
given(dao.getDeviceProfiles(anyString(), anyString())).willReturn(devices);
// When
Promise<ResourceResponse, ResourceException> promise = resource.deleteInstance(ctx(), request.getResourcePath(), request);
// Then
assertThat(promise).failedWithResourceException().withCode(ResourceException.NOT_FOUND);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class CoreTokenResourceTest method shouldGetBadRequestForMissingTokenId.
@Test
public void shouldGetBadRequestForMissingTokenId() throws CoreTokenException {
// Given
CreateRequest request = mock(CreateRequest.class);
given(request.getContent()).willReturn(new JsonValue(""));
doThrow(IllegalArgumentException.class).when(mockStore).createAsync(any(Token.class));
// When
Promise<ResourceResponse, ResourceException> promise = resource.createInstance(null, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class SmsRouteTreeTest method shouldUseProvidedAuthModuleForMatchingPath.
@Test
public void shouldUseProvidedAuthModuleForMatchingPath() throws Exception {
//Given
RequestHandler requestHandler = mock(RequestHandler.class);
Context context = mock(Context.class);
ReadRequest request = Requests.newReadRequest("/not-authorized/service");
Promise<AuthorizationResult, ResourceException> failResult = newResultPromise(accessDenied("no"));
given(authModule.authorizeRead(any(Context.class), any(ReadRequest.class))).willReturn(failResult);
//When
routeTree.handles("NOT_AUTHORIZED").addRoute(RoutingMode.STARTS_WITH, "/service", requestHandler);
Promise<ResourceResponse, ResourceException> result = routeTree.handleRead(context, request);
//Then
assertThat(result).failedWithException();
verify(authModule).authorizeRead(any(Context.class), any(ReadRequest.class));
verifyNoMoreInteractions(requestHandler, defaultAuthModule);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class TokenOwnerAuthzModuleTest method shouldFailInvalidQueryParamToken.
@Test
public void shouldFailInvalidQueryParamToken() throws SSOException, ExecutionException, InterruptedException, BadRequestException {
//given
ActionRequest request = Requests.newActionRequest("resource", "deleteProperty");
request.setAdditionalParameter("tokenId", "token");
given(mockService.isSuperUser(eq("universal_id"))).willReturn(false);
given(mockTokenManager.createSSOToken(eq("token"))).willThrow(new SSOException(""));
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, request);
//then
assertThat(result).failedWithException().isInstanceOf(ForbiddenException.class);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class PolicyResourceEvaluationTest method shouldHandleEntitlementExceptions.
@Test
public void shouldHandleEntitlementExceptions() throws EntitlementException {
// Given...
given(request.getAction()).willReturn("evaluate");
Context context = buildContextStructure("/abc");
EntitlementException eE = new EntitlementException(EntitlementException.INVALID_VALUE);
given(requestFactory.buildRequest(PolicyAction.EVALUATE, context, request)).willThrow(eE);
given(request.getRequestType()).willReturn(RequestType.ACTION);
// When...
Promise<ActionResponse, ResourceException> promise = policyResource.actionCollection(context, request);
// Then...
verify(request).getAction();
verify(requestFactory).buildRequest(PolicyAction.EVALUATE, context, request);
verify(request).getRequestType();
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
verifyNoMoreInteractions(request, requestFactory, policyRequest, factory, evaluator, parser);
}
Aggregations