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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations