Search in sources :

Example 36 with ActionRequest

use of org.forgerock.json.resource.ActionRequest 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 ActionRequest

use of org.forgerock.json.resource.ActionRequest 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 ActionRequest

use of org.forgerock.json.resource.ActionRequest 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 ActionRequest

use of org.forgerock.json.resource.ActionRequest 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)

Example 40 with ActionRequest

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

the class OathDevicesResourceTest method shouldFailOnUnknownAction.

@Test
public void shouldFailOnUnknownAction() throws ResourceException, SSOException {
    // given
    ActionRequest request = Requests.newActionRequest("instanceId", "fake");
    // when
    Promise<ActionResponse, ResourceException> promise = resource.actionCollection(ctx(), request);
    // 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)

Aggregations

ActionRequest (org.forgerock.json.resource.ActionRequest)44 Test (org.testng.annotations.Test)39 ResourceException (org.forgerock.json.resource.ResourceException)31 ActionResponse (org.forgerock.json.resource.ActionResponse)28 Context (org.forgerock.services.context.Context)23 JsonValue (org.forgerock.json.JsonValue)12 RealmContext (org.forgerock.openam.rest.RealmContext)10 BeforeTest (org.testng.annotations.BeforeTest)8 AuthorizationResult (org.forgerock.authz.filter.api.AuthorizationResult)6 Router (org.forgerock.json.resource.Router)4 Matchers.anyString (org.mockito.Matchers.anyString)4 FilterChain (org.forgerock.json.resource.FilterChain)3 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)3 RootContext (org.forgerock.services.context.RootContext)3 DelegationPermission (com.sun.identity.delegation.DelegationPermission)2 HashSet (java.util.HashSet)2 Requests.newActionRequest (org.forgerock.json.resource.Requests.newActionRequest)2 SSOException (com.iplanet.sso.SSOException)1 UriRouterContext (org.forgerock.http.routing.UriRouterContext)1 CreateRequest (org.forgerock.json.resource.CreateRequest)1