use of org.forgerock.json.resource.ActionResponse in project OpenAM by OpenRock.
the class RecordResourceTest method stopRecording.
@Test
public void stopRecording() throws IOException, RecordException, ExecutionException, InterruptedException {
JsonValue jsonRecordProperties = JsonValueBuilder.toJsonValue(IOUtils.getFileContentFromClassPath(RecordResourceTest.class, RECORD_DIRECTORY + "startSimpleRecord.json"));
debugRecorder.startRecording(jsonRecordProperties);
// Given...
given(request.getAction()).willReturn("stop");
// When...
Promise<ActionResponse, ResourceException> promise = recordResource.actionCollection(serverContext, request);
// Then...
verify(request).getAction();
RecordProperties recordPropertiesInput = RecordProperties.fromJson(jsonRecordProperties);
RecordProperties recordPropertiesOutput = RecordProperties.fromJson(promise.get().getJsonContent().get("record"));
assertThat(recordPropertiesInput).isEqualTo(recordPropertiesOutput);
}
use of org.forgerock.json.resource.ActionResponse in project OpenAM by OpenRock.
the class OathDevicesResourceTest method shouldFailOnUnknownActionInstance.
@Test
public void shouldFailOnUnknownActionInstance() throws ResourceException, SSOException {
// given
ActionRequest actionRequest = mock(ActionRequest.class);
// when
Promise<ActionResponse, ResourceException> promise = resource.actionInstance(ctx(), "", actionRequest);
// then
assertThat(promise).failedWithResourceException().withCode(ResourceException.NOT_SUPPORTED);
}
use of org.forgerock.json.resource.ActionResponse 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);
}
use of org.forgerock.json.resource.ActionResponse in project OpenAM by OpenRock.
the class PolicyResourceEvaluationTest method shouldMakeBatchEvaluation.
@Test
public void shouldMakeBatchEvaluation() throws EntitlementException {
// Given...
given(request.getAction()).willReturn("evaluate");
Context context = buildContextStructure("/abc");
given(requestFactory.buildRequest(PolicyAction.EVALUATE, context, request)).willReturn(policyRequest);
given(policyRequest.getRestSubject()).willReturn(restSubject);
given(policyRequest.getApplication()).willReturn("some-application");
given(factory.getEvaluator(restSubject, "some-application")).willReturn(evaluator);
given(policyRequest.getApplication()).willReturn("some-application");
given(policyRequest.getRealm()).willReturn("/abc");
List<Entitlement> decisions = Arrays.asList(new Entitlement());
given(evaluator.routePolicyRequest(policyRequest)).willReturn(decisions);
JsonValue jsonDecision = JsonValue.json(array());
given(parser.printEntitlements(decisions)).willReturn(jsonDecision);
// When...
Promise<ActionResponse, ResourceException> promise = policyResource.actionCollection(context, request);
// Then...
verify(request).getAction();
verify(requestFactory).buildRequest(PolicyAction.EVALUATE, context, request);
verify(policyRequest).getRestSubject();
verify(policyRequest, times(2)).getApplication();
verify(policyRequest).getRealm();
verify(factory).getEvaluator(restSubject, "some-application");
verify(evaluator).routePolicyRequest(policyRequest);
verify(parser).printEntitlements(decisions);
assertThat(promise).succeeded().withContent().isEqualTo(jsonDecision);
verifyNoMoreInteractions(request, requestFactory, policyRequest, factory, evaluator, parser);
}
use of org.forgerock.json.resource.ActionResponse in project OpenAM by OpenRock.
the class PolicyResourceWithCopyMoveSupport method movePolicy.
private ActionResponse movePolicy(Context context, String resourceId, ActionRequest request) throws ResourceException {
ActionResponse copyResponse = copyPolicy(context, resourceId, request);
DeleteRequest deleteRequest = Requests.newDeleteRequest("policies", resourceId);
router.handleDelete(context, deleteRequest).getOrThrowUninterruptibly();
return copyResponse;
}
Aggregations