use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ResourceSetResourceTest method nameQueryShouldBeSupported.
@Test
public void nameQueryShouldBeSupported() throws Exception {
//Given
Context context = mock(Context.class);
QueryRequest request = mock(QueryRequest.class);
given(request.getFields()).willReturn(Arrays.asList(new JsonPointer("/fred")));
QueryResourceHandler handler = mock(QueryResourceHandler.class);
ResourceSetDescription resourceSet = mock(ResourceSetDescription.class);
QueryFilter<JsonPointer> queryFilter = QueryFilter.and(QueryFilter.equalTo(new JsonPointer("/name"), "NAME"), QueryFilter.equalTo(new JsonPointer("/resourceServer"), "myclient"), QueryFilter.equalTo(new JsonPointer("/policy/permissions/subject"), "SUBJECT"));
Promise<Collection<ResourceSetDescription>, ResourceException> resourceSetsPromise = Promises.newResultPromise((Collection<ResourceSetDescription>) asSet(resourceSet));
given(contextHelper.getRealm(context)).willReturn("REALM");
given(contextHelper.getUserId(context)).willReturn("RESOURCE_OWNER_ID");
given(request.getQueryFilter()).willReturn(queryFilter);
given(resourceSetService.getResourceSets(eq(context), eq("REALM"), Matchers.<ResourceSetWithPolicyQuery>anyObject(), eq("RESOURCE_OWNER_ID"), eq(false))).willReturn(resourceSetsPromise);
//When
Promise<QueryResponse, ResourceException> promise = resource.queryCollection(context, request, handler);
//Then
ArgumentCaptor<ResourceSetWithPolicyQuery> queryCaptor = ArgumentCaptor.forClass(ResourceSetWithPolicyQuery.class);
verify(resourceSetService).getResourceSets(eq(context), eq("REALM"), queryCaptor.capture(), eq("RESOURCE_OWNER_ID"), eq(false));
assertThat(queryCaptor.getValue().getOperator()).isEqualTo(AggregateQuery.Operator.AND);
assertThat(queryCaptor.getValue().getPolicyQuery()).isEqualTo(QueryFilter.equalTo(new JsonPointer("/permissions/subject"), "SUBJECT"));
assertThat(queryCaptor.getValue().getResourceSetQuery()).isEqualTo(QueryFilter.and(QueryFilter.equalTo("name", "NAME"), QueryFilter.equalTo("clientId", "myclient")));
assertThat(promise).succeeded().withObject().isNotNull();
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class PendingRequestResourceTest method shouldQueryPendingRequests.
@Test
public void shouldQueryPendingRequests() throws Exception {
//Given
Context context = mockContext("REALM");
QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.<JsonPointer>alwaysTrue());
QueryResourceHandler handler = mock(QueryResourceHandler.class);
given(handler.handleResource(any(ResourceResponse.class))).willReturn(true);
mockPendingRequestsForUser("alice", "REALM", 2);
//When
Promise<QueryResponse, ResourceException> promise = resource.queryCollection(context, request, handler);
//Then
verify(handler, times(2)).handleResource(any(ResourceResponse.class));
assertThat(promise).succeeded();
}
use of org.forgerock.json.resource.QueryRequest 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.QueryRequest 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.QueryRequest 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);
}
Aggregations