use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class UmaPolicyResourceTest method shouldHandledFailedReadPolicy.
@Test
@SuppressWarnings("unchecked")
public void shouldHandledFailedReadPolicy() {
//Given
Context context = mock(Context.class);
ReadRequest request = Requests.newReadRequest("/policies");
ResourceException resourceException = mock(ResourceException.class);
Promise<UmaPolicy, ResourceException> promise = Promises.newExceptionPromise(resourceException);
given(policyService.readPolicy(context, "RESOURCE_SET_UID")).willReturn(promise);
//When
Promise<ResourceResponse, ResourceException> result = policyResource.readInstance(context, "RESOURCE_SET_UID", request);
//Then
assertThat(result).failedWithResourceException().isEqualTo(resourceException);
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class PolicyResourceWithCopyMoveSupport method copyPolicy.
private ActionResponse copyPolicy(Context context, String resourceId, ActionRequest request) throws ResourceException {
String sourceRealm = RealmContext.getRealm(context);
JsonValue payload = request.getContent().get("to");
if (payload.isNull()) {
throw new BadRequestException("to definition is missing");
}
String destinationRealm = payload.get("realm").defaultTo(sourceRealm).asString();
ReadRequest readRequest = Requests.newReadRequest("policies", resourceId);
JsonValue policy = router.handleRead(context, readRequest).getOrThrowUninterruptibly().getContent();
String sourceApplication = policy.get("applicationName").asString();
String sourceResourceType = policy.get("resourceTypeUuid").asString();
String destinationApplication = payload.get("application").defaultTo(sourceApplication).asString();
String destinationResourceTypeId = payload.get("resourceType").defaultTo(sourceResourceType).asString();
String copiedName = payload.get("name").defaultTo(resourceId).asString();
if (sourceRealm.equals(destinationRealm) && resourceId.equals(copiedName)) {
throw new BadRequestException("policy name already exists within the realm");
}
policy.put("name", copiedName);
policy.put("applicationName", destinationApplication);
policy.put("resourceTypeUuid", destinationResourceTypeId);
RealmContext updatedContext = new RealmContext(context);
updatedContext.setOverrideRealm(destinationRealm);
CreateRequest createRequest = Requests.newCreateRequest("policies", policy);
JsonValue copiedPolicy = router.handleCreate(updatedContext, createRequest).getOrThrowUninterruptibly().getContent();
return Responses.newActionResponse(copiedPolicy);
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class ApplicationTypesResourceTest method undefinedSubjectShouldFail.
@Test(expectedExceptions = InternalServerErrorException.class)
public void undefinedSubjectShouldFail() throws ResourceException {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject subject = null;
given(mockSubjectContext.getCallerSubject()).willReturn(subject);
ReadRequest request = mock(ReadRequest.class);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "test", request);
result.getOrThrowUninterruptibly();
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class ApplicationTypesResourceTest method readShouldFailOnInvalidApplicationType.
@Test(expectedExceptions = NotFoundException.class)
public void readShouldFailOnInvalidApplicationType() throws ResourceException {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject subject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(subject);
ReadRequest request = mock(ReadRequest.class);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "test", request);
//then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method shouldThrowErrorWthInvalidCondition.
@Test(expectedExceptions = NotFoundException.class)
public void shouldThrowErrorWthInvalidCondition() throws JsonMappingException, ResourceException {
//given
SubjectContext mockSubjectContext = mock(SubjectContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
ReadRequest mockRequest = mock(ReadRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "invalidCondition", mockRequest);
//then
result.getOrThrowUninterruptibly();
}
Aggregations