use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class Requester method read.
/**
* Request to read a specified resource at a specified endpoint.
*
* @param location Endpoint destination of this request. May not be null.
* @param resourceId Resource ID to read. May not be null.
* @param context Context of this request.
* @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
* @throws ResourceException If any exception occurred during processing.
*/
public JsonValue read(String location, String resourceId, Context context) throws ResourceException {
Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
Reject.ifTrue(StringUtils.isEmpty(resourceId), "The resourceId to read may not be null or empty.");
final Router rootRouter = router.get();
final ReadRequest readRequest = Requests.newReadRequest(location, resourceId);
return rootRouter.handleRead(context, readRequest).getOrThrowUninterruptibly().getContent();
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldReadScriptConfigurationWithoutError.
@Test
public void shouldReadScriptConfigurationWithoutError() throws Exception {
// given
String resourceId = "1234567890";
scriptConfigSet.clear();
scriptConfigSet.put(resourceId, ScriptConfiguration.builder().setId(resourceId).setName("MyJavaScript").setDescription("A test JavaScript configuration").setScript(script).setLanguage(JAVASCRIPT).setContext(POLICY_CONDITION).build());
ReadRequest readRequest = mock(ReadRequest.class);
// when
Promise<ResourceResponse, ResourceException> promise = scriptResource.readInstance(context, resourceId, readRequest);
ResourceResponse response = promise.getOrThrowUninterruptibly();
// then
assertNotNull(response);
assertNotNull(response.getId());
assertEquals(response.getId(), resourceId);
JsonValue responseJson = response.getContent();
assertEquals(responseJson.get(JSON_UUID).asString(), resourceId);
assertEquals(responseJson.get(SCRIPT_NAME).asString(), "MyJavaScript");
assertEquals(responseJson.get(SCRIPT_DESCRIPTION).asString(), "A test JavaScript configuration");
assertEquals(responseJson.get(SCRIPT_TEXT).asString(), encodeScript);
assertEquals(getLanguageFromString(responseJson.get(SCRIPT_LANGUAGE).asString()), JAVASCRIPT);
assertEquals(getContextFromString(responseJson.get(SCRIPT_CONTEXT).asString()), POLICY_CONDITION);
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReadPoliciesFromStore.
@Test
public void shouldReadPoliciesFromStore() throws Exception {
// Given
String id = "testPolicy";
long lastModified = 1234l;
Privilege policy = mockPrivilege(id, lastModified);
ReadRequest request = mock(ReadRequest.class);
given(mockStore.read(id)).willReturn(policy);
JsonValue content = new JsonValue("content");
given(mockParser.printPolicy(policy)).willReturn(content);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.readInstance(mockServerContext, id, request);
// Then
assertThat(promise).succeeded().withId().isNotNull();
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReportMissingPoliciesInRead.
@Test
public void shouldReportMissingPoliciesInRead() throws Exception {
// Given
String id = "unknown";
given(mockStore.read(id)).willThrow(new EntitlementException(EntitlementException.NO_SUCH_POLICY));
ReadRequest request = mock(ReadRequest.class);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.readInstance(mockServerContext, id, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(NotFoundException.class);
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class PolicyV1FilterTest method forwardOnRead.
/**
* Verify that read requests are forwarded on and that the response is tailored to represent v1.0 policy.
*/
@Test
public void forwardOnRead() throws Exception {
// Given
ReadRequest readRequest = mock(ReadRequest.class);
// When
Promise<ResourceResponse, ResourceException> promise = filter.filterRead(context, readRequest, requestHandler);
// Then
assertThat(promise).succeeded();
verify(requestHandler).handleRead(eq(context), eq(readRequest));
assertThat(promise.get().getContent().contains("resourceTypeUuid")).isFalse();
}
Aggregations