Search in sources :

Example 16 with ActionRequest

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

the class BatchResourceTest method shouldRejectNonBatchActions.

@Test
public void shouldRejectNonBatchActions() {
    //given
    Context mockContext = Mockito.mock(Context.class);
    ActionRequest mockRequest = mock(ActionRequest.class);
    given(mockRequest.getAction()).willReturn("false");
    @SuppressWarnings("unchecked") ExceptionHandler<ResourceException> handler = mock(ExceptionHandler.class);
    //when
    Promise<ActionResponse, ResourceException> result = batchResource.actionCollection(mockContext, mockRequest);
    result.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 17 with ActionRequest

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

the class ScriptResourceTest method shouldReturnErrorWhenActionNotRecognised.

@Test(expectedExceptions = NotSupportedException.class)
@SuppressWarnings("unchecked")
public void shouldReturnErrorWhenActionNotRecognised() throws ResourceException {
    // given
    ActionRequest request = prepareActionRequestForValidate("var a = 123;var b = 456;", "JAVASCRIPT", "invalid_action");
    // when
    scriptResource.actionCollection(context, request).getOrThrowUninterruptibly();
// then - exception
}
Also used : ActionRequest(org.forgerock.json.resource.ActionRequest) Test(org.testng.annotations.Test)

Example 18 with ActionRequest

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

the class ScriptResourceTest method shouldReturnErrorWhenNoScriptSpecified.

@Test(expectedExceptions = BadRequestException.class)
@SuppressWarnings("unchecked")
public void shouldReturnErrorWhenNoScriptSpecified() throws ResourceException {
    // given
    JsonValue requestJson = json(object(field(SCRIPT_LANGUAGE, "JAVASCRIPT")));
    ActionRequest request = mock(ActionRequest.class);
    when(request.getContent()).thenReturn(requestJson);
    when(request.getAction()).thenReturn("validate");
    // when
    scriptResource.actionCollection(context, request).getOrThrowUninterruptibly();
// then - exception
}
Also used : ActionRequest(org.forgerock.json.resource.ActionRequest) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 19 with ActionRequest

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

the class UmaPolicyResourceTest method shouldThrowNotSupportedExceptionForActionInstance.

@Test
@SuppressWarnings("unchecked")
public void shouldThrowNotSupportedExceptionForActionInstance() {
    //Given
    Context context = mock(Context.class);
    ActionRequest request = Requests.newActionRequest("/policies", "ACTION_ID");
    //When
    Promise<ActionResponse, ResourceException> result = policyResource.actionInstance(context, "RESOURCE_SET_ID", request);
    //Then
    assertThat(result).failedWithException().isInstanceOf(NotSupportedException.class);
}
Also used : Context(org.forgerock.services.context.Context) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 20 with ActionRequest

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

the class UmaPolicyResourceTest method shouldThrowNotSupportedExceptionForActionCollection.

@Test
@SuppressWarnings("unchecked")
public void shouldThrowNotSupportedExceptionForActionCollection() {
    //Given
    Context context = mock(Context.class);
    ActionRequest request = Requests.newActionRequest("/policies", "ACTION_ID");
    //When
    Promise<ActionResponse, ResourceException> result = policyResource.actionCollection(context, request);
    //Then
    assertThat(result).failedWithException().isInstanceOf(NotSupportedException.class);
}
Also used : Context(org.forgerock.services.context.Context) 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