Search in sources :

Example 6 with ActionResponse

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);
}
Also used : JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 7 with ActionResponse

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);
}
Also used : ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 8 with ActionResponse

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);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 9 with ActionResponse

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);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Entitlement(com.sun.identity.entitlement.Entitlement) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 10 with ActionResponse

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;
}
Also used : DeleteRequest(org.forgerock.json.resource.DeleteRequest) ActionResponse(org.forgerock.json.resource.ActionResponse)

Aggregations

ActionResponse (org.forgerock.json.resource.ActionResponse)43 ResourceException (org.forgerock.json.resource.ResourceException)37 Test (org.testng.annotations.Test)34 ActionRequest (org.forgerock.json.resource.ActionRequest)29 Context (org.forgerock.services.context.Context)22 JsonValue (org.forgerock.json.JsonValue)20 RealmContext (org.forgerock.openam.rest.RealmContext)13 Promise (org.forgerock.util.promise.Promise)7 Promises.newResultPromise (org.forgerock.util.promise.Promises.newResultPromise)7 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)6 BadRequestException (org.forgerock.json.resource.BadRequestException)5 SSOToken (com.iplanet.sso.SSOToken)4 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)4 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)4 Responses.newActionResponse (org.forgerock.json.resource.Responses.newActionResponse)4 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)4 DeleteFailedException (org.forgerock.openam.cts.exceptions.DeleteFailedException)4 FilterChain (org.forgerock.json.resource.FilterChain)3 NotFoundException (org.forgerock.json.resource.NotFoundException)3 Router (org.forgerock.json.resource.Router)3