use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class PolicyResourceEvaluationTest method shouldMakeBatchEvaluation.
@Test
public void shouldMakeBatchEvaluation() throws EntitlementException {
// Given...
given(request.getAction()).willReturn("evaluate");
Context context = buildContextStructure("/abc");
given(requestFactory.buildRequest(PolicyAction.EVALUATE, context, request)).willReturn(policyRequest);
given(policyRequest.getRestSubject()).willReturn(restSubject);
given(policyRequest.getApplication()).willReturn("some-application");
given(factory.getEvaluator(restSubject, "some-application")).willReturn(evaluator);
given(policyRequest.getApplication()).willReturn("some-application");
given(policyRequest.getRealm()).willReturn("/abc");
List<Entitlement> decisions = Arrays.asList(new Entitlement());
given(evaluator.routePolicyRequest(policyRequest)).willReturn(decisions);
JsonValue jsonDecision = JsonValue.json(array());
given(parser.printEntitlements(decisions)).willReturn(jsonDecision);
// When...
Promise<ActionResponse, ResourceException> promise = policyResource.actionCollection(context, request);
// Then...
verify(request).getAction();
verify(requestFactory).buildRequest(PolicyAction.EVALUATE, context, request);
verify(policyRequest).getRestSubject();
verify(policyRequest, times(2)).getApplication();
verify(policyRequest).getRealm();
verify(factory).getEvaluator(restSubject, "some-application");
verify(evaluator).routePolicyRequest(policyRequest);
verify(parser).printEntitlements(decisions);
assertThat(promise).succeeded().withContent().isEqualTo(jsonDecision);
verifyNoMoreInteractions(request, requestFactory, policyRequest, factory, evaluator, parser);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldRejectNullPolicyIdInDelete.
@Test
public void shouldRejectNullPolicyIdInDelete() throws Exception {
// Given
String id = null;
DeleteRequest request = mock(DeleteRequest.class);
willThrow(new EntitlementException(EntitlementException.MISSING_PRIVILEGE_NAME)).given(mockStore).delete(id);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReportCreatePolicyStoreErrors.
@Test
public void shouldReportCreatePolicyStoreErrors() throws Exception {
// Given
String id = "uniqueId";
JsonValue json = new JsonValue("");
CreateRequest request = mockCreateRequest(id, json);
Privilege policy = mockPrivilege(id, 123l);
given(mockParser.parsePolicy(id, json)).willReturn(policy);
willThrow(new EntitlementException(EntitlementException.INVALID_APPLICATION_CLASS)).given(mockStore).create(policy);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(InternalServerErrorException.class);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReportMissingPoliciesInDelete.
@Test
public void shouldReportMissingPoliciesInDelete() throws Exception {
// Given
String id = "unknown";
DeleteRequest request = mock(DeleteRequest.class);
willThrow(new EntitlementException(EntitlementException.NO_SUCH_POLICY)).given(mockStore).delete(id);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(NotFoundException.class);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method readShouldHandleServiceException.
@Test
public void readShouldHandleServiceException() throws Exception {
//given
ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
ReadRequest readRequest = mock(ReadRequest.class);
Throwable t = new EntitlementException(EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS);
when(resourceTypeService.getResourceType(any(Subject.class), anyString(), anyString())).thenThrow(t);
//when
Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.readInstance(mockServerContext, createdResource.getId(), readRequest);
//then
assertResourcePromiseFailedWithCodes(promise, ResourceException.CONFLICT, EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS);
}
Aggregations