use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class UmaPolicyResourceTest method shouldHandledFailedUpdatePolicy.
@Test
@SuppressWarnings("unchecked")
public void shouldHandledFailedUpdatePolicy() {
//Given
Context context = mock(Context.class);
UpdateRequest request = Requests.newUpdateRequest("/policies", json(object()));
ResourceException resourceException = mock(ResourceException.class);
Promise<UmaPolicy, ResourceException> promise = Promises.newExceptionPromise(resourceException);
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).failedWithResourceException().isEqualTo(resourceException);
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class UmaPolicyResourceTest method shouldHandledFailedCreatePolicy.
@Test
@SuppressWarnings("unchecked")
public void shouldHandledFailedCreatePolicy() {
//Given
Context context = mock(Context.class);
CreateRequest request = Requests.newCreateRequest("/policies", json(object()));
ResourceException resourceException = mock(ResourceException.class);
Promise<UmaPolicy, ResourceException> promise = Promises.newExceptionPromise(resourceException);
given(policyService.createPolicy(context, request.getContent())).willReturn(promise);
//When
Promise<ResourceResponse, ResourceException> result = policyResource.createInstance(context, request);
//Then
assertThat(result).failedWithResourceException().isEqualTo(resourceException);
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldUpdateUmaPolicy.
@Test
public void shouldUpdateUmaPolicy() throws Exception {
//Given
Context context = createContext();
JsonValue policy = createUmaPolicyJson("RESOURCE_SET_ID", "SCOPE_A", "SCOPE_C");
policy.remove(new JsonPointer("/permissions/0/scopes/1"));
List<ResourceResponse> updatedPolicies = new ArrayList<>();
ResourceResponse updatedPolicy1 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectOneUpdatedPolicyJson());
ResourceResponse updatedPolicy2 = newResourceResponse("ID_2", "REVISION_1", createBackendSubjectTwoPolicyJson());
updatedPolicies.add(updatedPolicy1);
updatedPolicies.add(updatedPolicy2);
Promise<List<ResourceResponse>, ResourceException> updatePolicyPromise = newResultPromise(updatedPolicies);
List<ResourceResponse> currentPolicies = new ArrayList<>();
ResourceResponse currentPolicy1 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectOnePolicyJson());
ResourceResponse currentPolicy2 = newResourceResponse("ID_2", "REVISION_1", createBackendSubjectTwoPolicyJson());
currentPolicies.add(currentPolicy1);
currentPolicies.add(currentPolicy2);
Promise<Pair<QueryResponse, List<ResourceResponse>>, ResourceException> currentPolicyPromise = newResultPromise(Pair.of((QueryResponse) null, currentPolicies));
setupQueries(currentPolicyPromise, updatedPolicy1, updatedPolicy2);
given(policyResourceDelegate.updatePolicies(eq(context), Matchers.<Set<JsonValue>>anyObject())).willReturn(updatePolicyPromise);
//When
UmaPolicy umaPolicy = policyService.updatePolicy(context, "RESOURCE_SET_ID", policy).getOrThrowUninterruptibly();
//Then
InOrder inOrder = inOrder(resourceDelegationFilter, policyResourceDelegate);
inOrder.verify(resourceDelegationFilter).beforeResourceSharedModification(any(UmaPolicy.class), any(UmaPolicy.class));
inOrder.verify(policyResourceDelegate, times(2)).updatePolicies(any(Context.class), anySetOf(JsonValue.class));
assertThat(umaPolicy.getId()).isEqualTo("RESOURCE_SET_ID");
assertThat(umaPolicy.getRevision()).isNotNull();
JsonValue expectedPolicyJson = createUmaPolicyJson("RESOURCE_SET_ID", "SCOPE_A", "SCOPE_C");
expectedPolicyJson.remove(new JsonPointer("/permissions/0/scopes/1"));
assertThat(umaPolicy.asJson().asMap()).isEqualTo(expectedPolicyJson.asMap());
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method mockBackendQuery.
private void mockBackendQuery(Context context, JsonValue... policies) {
QueryResponse queryResult = newQueryResponse();
List<ResourceResponse> policyResources = new ArrayList<>();
for (JsonValue policy : policies) {
policyResources.add(newResourceResponse("ID_1", "REVISION_1", policy));
}
Promise<Pair<QueryResponse, List<ResourceResponse>>, ResourceException> backendQueryPromise = newResultPromise(Pair.of(queryResult, policyResources));
given(policyResourceDelegate.queryPolicies(eq(context), Matchers.<QueryRequest>anyObject())).willReturn(backendQueryPromise);
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldDeleteUmaPolicy.
@Test
@SuppressWarnings("unchecked")
public void shouldDeleteUmaPolicy() throws Exception {
//Given
Context context = createContext();
List<ResourceResponse> readPolicies = new ArrayList<ResourceResponse>();
ResourceResponse readPolicy1 = newResourceResponse("ID_1", "REVISION_1", createBackendSubjectOnePolicyJson());
ResourceResponse readPolicy2 = newResourceResponse("ID_2", "REVISION_2", createBackendSubjectTwoPolicyJson());
readPolicies.add(readPolicy1);
readPolicies.add(readPolicy2);
Promise<Pair<QueryResponse, List<ResourceResponse>>, ResourceException> currentPolicyPromise = newResultPromise(Pair.of((QueryResponse) null, readPolicies));
setupQueries(currentPolicyPromise);
Promise<List<ResourceResponse>, ResourceException> deletePoliciesPromise = newResultPromise(readPolicies);
given(policyResourceDelegate.deletePolicies(eq(context), anyListOf(String.class))).willReturn(deletePoliciesPromise);
//When
policyService.deletePolicy(context, "RESOURCE_SET_ID").getOrThrowUninterruptibly();
//Then
InOrder inOrder = inOrder(resourceDelegationFilter, policyResourceDelegate);
inOrder.verify(resourceDelegationFilter).onResourceSharedDeletion(any(UmaPolicy.class));
inOrder.verify(policyResourceDelegate).deletePolicies(eq(context), anyListOf(String.class));
}
Aggregations