Search in sources :

Example 11 with ActionRequest

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

the class ResourceSetResourceTest method actionCollectionShouldNotBeSupported.

@Test
public void actionCollectionShouldNotBeSupported() {
    //Given
    Context context = mock(Context.class);
    ActionRequest request = mock(ActionRequest.class);
    //When
    Promise<ActionResponse, ResourceException> promise = resource.actionCollection(context, request);
    //Then
    assertThat(promise).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 12 with ActionRequest

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

the class PrivilegeAuthzModuleTest method crestActionNoMappingFails.

@Test
public void crestActionNoMappingFails() throws SSOException, DelegationException {
    // When...
    final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
    final Router router = new Router();
    router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
    final Context context = new RealmContext(subjectContext);
    final ActionRequest request = Requests.newActionRequest("/policies", "unknownAction");
    Promise<ActionResponse, ResourceException> promise = router.handleAction(context, request);
    // Then...
    assertThat(promise).failedWithException().isInstanceOf(ForbiddenException.class);
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) Context(org.forgerock.services.context.Context) RealmContext(org.forgerock.openam.rest.RealmContext) ActionRequest(org.forgerock.json.resource.ActionRequest) FilterChain(org.forgerock.json.resource.FilterChain) Router(org.forgerock.json.resource.Router) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 13 with ActionRequest

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

the class ScriptResourceTest method prepareActionRequestForValidate.

private ActionRequest prepareActionRequestForValidate(String script, String language, String action) {
    String encodeScript = Base64.encode(script.getBytes());
    JsonValue requestJson = json(object(field(SCRIPT_TEXT, encodeScript), field(SCRIPT_LANGUAGE, language)));
    ActionRequest actionRequest = mock(ActionRequest.class);
    when(actionRequest.getContent()).thenReturn(requestJson);
    when(actionRequest.getAction()).thenReturn(action);
    return actionRequest;
}
Also used : ActionRequest(org.forgerock.json.resource.ActionRequest) JsonValue(org.forgerock.json.JsonValue) Matchers.anyString(org.mockito.Matchers.anyString)

Example 14 with ActionRequest

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

the class ScriptResourceTest method shouldReturnErrorWhenLanguageNotRecognised.

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

Example 15 with ActionRequest

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

the class ScriptResourceTest method shouldReturnErrorWhenNoLanguageSpecified.

@Test(expectedExceptions = BadRequestException.class)
@SuppressWarnings("unchecked")
public void shouldReturnErrorWhenNoLanguageSpecified() throws ResourceException {
    // given
    String encodeScript = Base64.encode("var a = 123;var b = 456;".getBytes());
    JsonValue requestJson = json(object(field(SCRIPT_TEXT, encodeScript)));
    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) Matchers.anyString(org.mockito.Matchers.anyString) 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