Search in sources :

Example 36 with ActionResponse

use of org.forgerock.json.resource.ActionResponse in project OpenAM by OpenRock.

the class ScriptResourceTest method shouldPassScriptValidation.

@Test
@SuppressWarnings("unchecked")
public void shouldPassScriptValidation() throws ResourceException {
    // given
    ActionRequest request = prepareActionRequestForValidate("var a = 123;var b = 456;", "JAVASCRIPT", "validate");
    // when
    ActionResponse response = scriptResource.actionCollection(context, request).getOrThrowUninterruptibly();
    // then
    assertThat(response.getJsonContent().get("success").asBoolean()).isEqualTo(true);
}
Also used : ActionRequest(org.forgerock.json.resource.ActionRequest) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 37 with ActionResponse

use of org.forgerock.json.resource.ActionResponse in project OpenAM by OpenRock.

the class ScriptResourceTest method shouldFailScriptValidationWithOneError.

@Test
@SuppressWarnings("unchecked")
public void shouldFailScriptValidationWithOneError() throws ResourceException {
    // given
    ActionRequest request = prepareActionRequestForValidate("var a = 123;var b = 456; =VALIDATION SHOULD FAIL=", "JAVASCRIPT", "validate");
    // when
    ActionResponse response = scriptResource.actionCollection(context, request).getOrThrowUninterruptibly();
    // then
    assertThat(response.getJsonContent().get("success").asBoolean()).isEqualTo(false);
    assertThat(response.getJsonContent().get("errors").get("line")).isNotNull();
    assertThat(response.getJsonContent().get("errors").get("column")).isNotNull();
    assertThat(response.getJsonContent().get("errors").get("message")).isNotNull();
}
Also used : ActionRequest(org.forgerock.json.resource.ActionRequest) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 38 with ActionResponse

use of org.forgerock.json.resource.ActionResponse in project OpenAM by OpenRock.

the class BatchResourceTest method shouldRejectNullScriptId.

@Test
public void shouldRejectNullScriptId() {
    //given
    Context mockContext = mock(Context.class);
    ActionRequest action = newActionRequest("batch", "batch");
    action.setContent(JsonValueBuilder.toJsonValue("{ \"notScriptId\" : \"blah\" }"));
    @SuppressWarnings("unchecked") ExceptionHandler<ResourceException> handler = mock(ExceptionHandler.class);
    //when
    Promise<ActionResponse, ResourceException> promise = batchResource.actionCollection(mockContext, action);
    promise.thenOnException(handler);
    //then
    verify(handler, times(1)).handleException(any(ResourceException.class));
    verifyNoMoreInteractions(handler);
}
Also used : Context(org.forgerock.services.context.Context) Requests.newActionRequest(org.forgerock.json.resource.Requests.newActionRequest) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 39 with ActionResponse

use of org.forgerock.json.resource.ActionResponse in project OpenAM by OpenRock.

the class PolicyResourceEvaluationTest method shouldMakeTreeEvaluation.

@Test
public void shouldMakeTreeEvaluation() throws EntitlementException {
    // Given...
    given(request.getAction()).willReturn("evaluateTree");
    Context context = buildContextStructure("/abc");
    given(requestFactory.buildRequest(PolicyAction.TREE_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.TREE_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, subjectContext, 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 40 with ActionResponse

use of org.forgerock.json.resource.ActionResponse in project OpenAM by OpenRock.

the class PolicyV1FilterTest method forwardOnAction.

/**
     * Verify that action requests are forwarded on.
     */
@Test
public void forwardOnAction() throws Exception {
    // Given
    ActionRequest actionRequest = mock(ActionRequest.class);
    // When
    Promise<ActionResponse, ResourceException> promise = filter.filterAction(context, actionRequest, requestHandler);
    // Then
    assertThat(promise).succeeded();
    assertThat(promise.get().getJsonContent().contains("ttl")).isFalse();
}
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)

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