Search in sources :

Example 26 with QueryResourceHandler

use of org.forgerock.json.resource.QueryResourceHandler in project OpenAM by OpenRock.

the class PolicyResourceDelegateTest method shouldQueryPolicies.

@Test
public void shouldQueryPolicies() throws ResourceException {
    //Given
    Context context = mock(Context.class);
    QueryRequest request = mock(QueryRequest.class);
    QueryResourceHandler handler = mock(QueryResourceHandler.class);
    //When
    delegate.queryPolicies(context, request, handler);
    //Then
    verify(policyResource).handleQuery(context, request, handler);
}
Also used : Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) Test(org.testng.annotations.Test)

Example 27 with QueryResourceHandler

use of org.forgerock.json.resource.QueryResourceHandler 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();
}
Also used : Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) JsonPointer(org.forgerock.json.JsonPointer) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) QueryResponse(org.forgerock.json.resource.QueryResponse) Collection(java.util.Collection) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) Test(org.testng.annotations.Test)

Example 28 with QueryResourceHandler

use of org.forgerock.json.resource.QueryResourceHandler 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();
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) Test(org.testng.annotations.Test)

Example 29 with QueryResourceHandler

use of org.forgerock.json.resource.QueryResourceHandler 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);
}
Also used : Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) Responses.newQueryResponse(org.forgerock.json.resource.Responses.newQueryResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) UmaPolicy(org.forgerock.openam.uma.UmaPolicy) Pair(org.forgerock.util.Pair) Test(org.testng.annotations.Test)

Aggregations

QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)29 QueryRequest (org.forgerock.json.resource.QueryRequest)28 Test (org.testng.annotations.Test)26 Context (org.forgerock.services.context.Context)21 ResourceException (org.forgerock.json.resource.ResourceException)19 QueryResponse (org.forgerock.json.resource.QueryResponse)18 ResourceResponse (org.forgerock.json.resource.ResourceResponse)18 RealmContext (org.forgerock.openam.rest.RealmContext)15 Subject (javax.security.auth.Subject)11 ClientContext (org.forgerock.services.context.ClientContext)11 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)9 EntitlementException (com.sun.identity.entitlement.EntitlementException)6 JsonValue (org.forgerock.json.JsonValue)6 Matchers.anyString (org.mockito.Matchers.anyString)6 JsonSchema (com.fasterxml.jackson.databind.jsonschema.JsonSchema)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 JsonPointer (org.forgerock.json.JsonPointer)4 Application (com.sun.identity.entitlement.Application)3