use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class CoreTokenResourceTest method shouldReadAndReturnTokenInSerialisedForm.
@Test
public void shouldReadAndReturnTokenInSerialisedForm() throws CoreTokenException {
// Given
String serialisedToken = "{ \"value\": \"some JSON\" }";
given(mockStore.read(anyString())).willReturn(mockToken);
given(mockSerialisation.serialise(any(Token.class))).willReturn(serialisedToken);
// When
Promise<ResourceResponse, ResourceException> promise = resource.readInstance(null, "", mock(ReadRequest.class));
// Then
assertThat(promise).succeeded().withContent().stringAt("value").isEqualTo("some JSON");
}
use of org.forgerock.json.resource.ResourceResponse 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.ResourceResponse 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.ResourceResponse 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.ResourceResponse in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldRejectNullPolicyIdInDelete.
@Test
public void shouldRejectNullPolicyIdInDelete() throws Exception {
// Given
String id = null;
DeleteRequest request = mock(DeleteRequest.class);
willThrow(new EntitlementException(EntitlementException.MISSING_PRIVILEGE_NAME)).given(mockStore).delete(id);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
Aggregations