use of org.forgerock.openam.uma.UmaPolicy in project OpenAM by OpenRock.
the class UmaPolicyResourceTest method shouldSuccessfullyUpdatePolicy.
@Test
@SuppressWarnings("unchecked")
public void shouldSuccessfullyUpdatePolicy() {
//Given
Context context = mock(Context.class);
UpdateRequest request = Requests.newUpdateRequest("/policies", json(object()));
UmaPolicy policy = mock(UmaPolicy.class);
JsonValue policyJson = json(object());
Promise<UmaPolicy, ResourceException> promise = Promises.newResultPromise(policy);
given(policy.getId()).willReturn("ID");
given(policy.getRevision()).willReturn("REVISION");
given(policy.asJson()).willReturn(policyJson);
given(policyService.updatePolicy(context, "RESOURCE_SET_UID", request.getContent())).willReturn(promise);
//When
Promise<ResourceResponse, ResourceException> result = policyResource.updateInstance(context, "RESOURCE_SET_UID", request);
//Then
assertThat(result).succeeded().withId().isEqualTo("ID");
assertThat(result).succeeded().withRevision().isEqualTo("REVISION");
assertThat(result).succeeded().withContent().isObject().isEqualTo(policyJson);
}
use of org.forgerock.openam.uma.UmaPolicy in project OpenAM by OpenRock.
the class UmaPolicyResourceTest method shouldHandleFailedQueryOfPolicies.
@Test
public void shouldHandleFailedQueryOfPolicies() {
//Given
Context context = mock(Context.class);
QueryRequest request = Requests.newQueryRequest("/policies");
QueryResourceHandler handler = mock(QueryResourceHandler.class);
ResourceException resourceException = mock(ResourceException.class);
Promise<Pair<QueryResponse, Collection<UmaPolicy>>, ResourceException> promise = Promises.newExceptionPromise(resourceException);
given(policyService.queryPolicies(context, request)).willReturn(promise);
//When
Promise<QueryResponse, ResourceException> result = policyResource.queryCollection(context, request, handler);
//Then
assertThat(result).failedWithException().isEqualTo(resourceException);
}
use of org.forgerock.openam.uma.UmaPolicy in project OpenAM by OpenRock.
the class UmaPolicyResourceTest method shouldSuccessfullyReadPolicy.
@Test
@SuppressWarnings("unchecked")
public void shouldSuccessfullyReadPolicy() {
//Given
Context context = mock(Context.class);
ReadRequest request = Requests.newReadRequest("/policies");
UmaPolicy policy = mock(UmaPolicy.class);
JsonValue policyJson = json(object());
Promise<UmaPolicy, ResourceException> promise = Promises.newResultPromise(policy);
given(policy.getId()).willReturn("ID");
given(policy.getRevision()).willReturn("REVISION");
given(policy.asJson()).willReturn(policyJson);
given(policyService.readPolicy(context, "RESOURCE_SET_UID")).willReturn(promise);
//When
Promise<ResourceResponse, ResourceException> result = policyResource.readInstance(context, "RESOURCE_SET_UID", request);
//Then
assertThat(result).succeeded().withId().isEqualTo("ID");
assertThat(result).succeeded().withRevision().isEqualTo("REVISION");
assertThat(result).succeeded().withContent().isObject().isEqualTo(policyJson);
}
use of org.forgerock.openam.uma.UmaPolicy 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.openam.uma.UmaPolicy in project OpenAM by OpenRock.
the class UmaPolicyServiceImplDelegationTest method aliceShouldBeAbleToCreatePolicyForResource.
@Test
public void aliceShouldBeAbleToCreatePolicyForResource() throws Exception {
//Given
AMIdentity loggedInUser = userIsLoggedIn("alice", "REALM");
accessingUriForUser("alice");
String resourceSetId = registerResourceSet("alice");
JsonValue policy = policyToCreate(resourceSetId);
Context context = getContext();
//When
Promise<UmaPolicy, ResourceException> promise = policyService.createPolicy(context, policy);
//Then
promise.getOrThrow();
assertThat(promise).succeeded();
verifyPolicyIsCreatedForLoggedInUser();
verifyAuditLogCreatedForLoggedInUser(resourceSetId, loggedInUser);
}
Aggregations