Search in sources :

Example 16 with ActionResponse

use of org.forgerock.json.resource.ActionResponse 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 17 with ActionResponse

use of org.forgerock.json.resource.ActionResponse 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 18 with ActionResponse

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

the class RequesterTest method shouldExecuteActionOperation.

@Test
public void shouldExecuteActionOperation() throws ResourceException {
    // GIVEN
    String location = "location";
    String resourceId = "resourceId";
    String actionId = "actionId";
    JsonValue payload = JsonValueBuilder.jsonValue().build();
    JsonValue expectedResult = JsonValueBuilder.toJsonValue("{ \"lemon\" : \"custard\" } ");
    // Set up mocks
    Promise<ActionResponse, ResourceException> mockResponse = mock(Promise.class);
    ActionResponse mockResourceResponse = mock(ActionResponse.class);
    // Stub mocks
    given(mockRealmRouterProvider.get()).willReturn(mockRouter);
    given(mockRouter.handleAction(any(Context.class), any(ActionRequest.class))).willReturn(mockResponse);
    given(mockResponse.getOrThrowUninterruptibly()).willReturn(mockResourceResponse);
    given(mockResourceResponse.getJsonContent()).willReturn(expectedResult);
    // WHEN
    JsonValue actualResult = requester.action(location, resourceId, actionId, payload, mockServerContext);
    // THEN
    verify(mockRealmRouterProvider, times(1)).get();
    verifyNoMoreInteractions(mockRealmRouterProvider);
    verify(mockRouter, times(1)).handleAction(any(Context.class), any(ActionRequest.class));
    verifyNoMoreInteractions(mockRouter);
    verify(mockResponse, times(1)).getOrThrowUninterruptibly();
    verifyNoMoreInteractions(mockResponse);
    verify(mockResourceResponse, times(1)).getJsonContent();
    verifyNoMoreInteractions(mockResourceResponse);
    assertThat(actualResult).isEqualTo(expectedResult);
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ActionRequest(org.forgerock.json.resource.ActionRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 19 with ActionResponse

use of org.forgerock.json.resource.ActionResponse 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 20 with ActionResponse

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

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