use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldHandleFailureToDeleteUnderlyingPolicies.
@Test(expectedExceptions = ResourceException.class)
@SuppressWarnings("unchecked")
public void shouldHandleFailureToDeleteUnderlyingPolicies() throws Exception {
//Given
Context context = createContext();
ResourceException exception = mock(ResourceException.class);
List<ResourceResponse> readPolicies = new ArrayList<>();
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));
Promise<List<ResourceResponse>, ResourceException> deletePoliciesPromise = newExceptionPromise(exception);
given(policyResourceDelegate.queryPolicies(eq(context), Matchers.<QueryRequest>anyObject())).willReturn(currentPolicyPromise);
given(policyResourceDelegate.deletePolicies(eq(context), anyListOf(String.class))).willReturn(deletePoliciesPromise);
//When
try {
policyService.deletePolicy(context, "RESOURCE_SET_ID").getOrThrowUninterruptibly();
} catch (ResourceException e) {
//Then
verify(policyResourceDelegate).deletePolicies(eq(context), anyListOf(String.class));
throw e;
}
}
use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesBySubject.
@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesBySubject() throws Exception {
//Given
Context context = createContext();
QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "SUBJECT_ONE"));
mockBackendQuery(context, createBackendSubjectOnePolicyJson(), createBackendSubjectTwoPolicyJson());
//When
Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
//Then
assertThat(queryResult.getSecond()).hasSize(1);
}
use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesBySubjectAndResourceServer.
@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesBySubjectAndResourceServer() throws Exception {
//Given
Context context = createContext();
QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.and(QueryFilter.equalTo(new JsonPointer("permissions/subject"), "SUBJECT_ONE"), QueryFilter.equalTo(new JsonPointer("resourceServer"), "CLIENT_ID")));
mockBackendQuery(context, createBackendSubjectOnePolicyJson(), createBackendSubjectTwoPolicyJson());
//When
Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
//Then
assertThat(queryResult.getSecond()).hasSize(1);
}
use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.
the class UmaPolicyServiceImplTest method shouldQueryUmaPoliciesByResourceServer.
@Test
@SuppressWarnings("unchecked")
public void shouldQueryUmaPoliciesByResourceServer() throws Exception {
//Given
Context context = createContext();
QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.equalTo(new JsonPointer("resourceServer"), "CLIENT_ID"));
mockBackendQuery(context, createBackendSubjectOnePolicyJson(), createBackendSubjectTwoPolicyJson());
//When
Pair<QueryResponse, Collection<UmaPolicy>> queryResult = policyService.queryPolicies(context, request).getOrThrowUninterruptibly();
//Then
assertThat(queryResult.getSecond()).hasSize(1);
}
use of org.forgerock.json.resource.QueryResponse in project OpenAM by OpenRock.
the class ResourceSetServiceTest method getResourceSetsShouldReturnSetWhenResourceSetsExistWithNoPolicyQuery.
@Test
public void getResourceSetsShouldReturnSetWhenResourceSetsExistWithNoPolicyQuery() throws Exception {
//Given
Context context = createContext();
String realm = "REALM";
ResourceSetWithPolicyQuery query = new ResourceSetWithPolicyQuery();
String resourceOwnerId = "RESOURCE_OWNER_ID";
boolean augmentWithPolicies = false;
QueryFilter<String> resourceSetQuery = mock(QueryFilter.class);
Set<ResourceSetDescription> queriedResourceSets = new HashSet<>();
ResourceSetDescription resourceSetOne = new ResourceSetDescription("RS_ID_ONE", "CLIENT_ID_ONE", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
ResourceSetDescription resourceSetTwo = new ResourceSetDescription("RS_ID_TWO", "CLIENT_ID_TWO", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
mockResourceOwnerIdentity(resourceOwnerId, realm);
mockFilteredResourceSetsQueryVisitor(resourceSetQuery, queriedResourceSets);
query.setResourceSetQuery(resourceSetQuery);
queriedResourceSets.add(resourceSetOne);
queriedResourceSets.add(resourceSetTwo);
given(resourceSetStore.query(resourceSetQuery)).willReturn(queriedResourceSets);
Collection<UmaPolicy> queriedPolicies = new HashSet<UmaPolicy>();
Pair<QueryResponse, Collection<UmaPolicy>> queriedPoliciesPair = Pair.of(newQueryResponse(), queriedPolicies);
Promise<Pair<QueryResponse, Collection<UmaPolicy>>, ResourceException> queriedPoliciesPromise = Promises.newResultPromise(queriedPoliciesPair);
given(policyService.queryPolicies(eq(context), Matchers.<QueryRequest>anyObject())).willReturn(queriedPoliciesPromise);
//When
Collection<ResourceSetDescription> resourceSets = service.getResourceSets(context, realm, query, resourceOwnerId, augmentWithPolicies).getOrThrowUninterruptibly();
//Then
assertThat(resourceSets).hasSize(2).contains(resourceSetOne, resourceSetTwo);
assertThat(resourceSetOne.getPolicy()).isNull();
assertThat(resourceSetTwo.getPolicy()).isNull();
}
Aggregations