Search in sources :

Example 16 with QueryRequest

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

the class PolicyResourceTest method shouldHandleQueryRequests.

@Test
public void shouldHandleQueryRequests() throws Exception {
    // Given
    QueryRequest request = mock(QueryRequest.class);
    QueryResourceHandler handler = mock(QueryResourceHandler.class);
    List<Privilege> policies = Arrays.<Privilege>asList(new StubPrivilege("one"), new StubPrivilege("two"));
    given(mockStore.query(request)).willReturn(policies);
    given(handler.handleResource(any(ResourceResponse.class))).willReturn(true);
    // When
    policyResource.queryCollection(mockServerContext, request, handler);
    // Then
    verify(handler, times(policies.size())).handleResource(any(ResourceResponse.class));
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 17 with QueryRequest

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

the class ResourceTypesResourceTest method queryShouldHandleQueryException.

@Test
public void queryShouldHandleQueryException() throws Exception {
    //given
    setupExistingResourceTypeFromJson(jsonResourceType);
    QueryRequest queryRequest = mock(QueryRequest.class);
    QueryResponseHandler queryHandler = makeQueryResponseHandler();
    Throwable t = new QueryException(QueryException.QueryErrorCode.FILTER_BOOLEAN_LITERAL_FALSE);
    when(resourceTypeService.getResourceTypesData(any(Subject.class), anyString())).thenThrow(t);
    //when
    Promise<QueryResponse, ResourceException> promise = resourceTypesResource.queryCollection(mockServerContext, queryRequest, queryHandler);
    //then
    assertThat(promise).failedWithResourceException().withCode(ResourceException.BAD_REQUEST);
}
Also used : QueryException(org.forgerock.openam.rest.query.QueryException) QueryRequest(org.forgerock.json.resource.QueryRequest) QueryResponseHandler(org.forgerock.openam.rest.query.QueryResponseHandler) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 18 with QueryRequest

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

the class PrivilegePolicyStoreTest method shouldRejectAlwaysFalseQueryFilters.

@Test(expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*'false' not supported.*")
public void shouldRejectAlwaysFalseQueryFilters() throws Exception {
    // Given
    QueryRequest request = mockQueryRequest(QueryFilter.alwaysFalse());
    // When
    testStore.query(request);
// Then - exception
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) Test(org.testng.annotations.Test)

Example 19 with QueryRequest

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

the class PrivilegePolicyStoreTest method shouldRejectNotQueries.

@Test(expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*not supported.*")
public void shouldRejectNotQueries() throws Exception {
    // Given
    QueryRequest request = mockQueryRequest(QueryFilter.not(QueryFilter.alwaysTrue()));
    // When
    testStore.query(request);
// Then - exception
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) Test(org.testng.annotations.Test)

Example 20 with QueryRequest

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

the class PrivilegePolicyStoreTest method mockQueryRequest.

private QueryRequest mockQueryRequest(QueryFilter filter) {
    QueryRequest request = mock(QueryRequest.class);
    given(request.getQueryFilter()).willReturn(filter);
    return request;
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest)

Aggregations

QueryRequest (org.forgerock.json.resource.QueryRequest)79 Test (org.testng.annotations.Test)68 QueryResponse (org.forgerock.json.resource.QueryResponse)40 JsonPointer (org.forgerock.json.JsonPointer)34 Context (org.forgerock.services.context.Context)34 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)29 ResourceException (org.forgerock.json.resource.ResourceException)28 Subject (javax.security.auth.Subject)26 RealmContext (org.forgerock.openam.rest.RealmContext)26 ResourceResponse (org.forgerock.json.resource.ResourceResponse)24 ClientContext (org.forgerock.services.context.ClientContext)22 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)20 Collection (java.util.Collection)15 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)15 SearchFilter (com.sun.identity.entitlement.util.SearchFilter)10 Matchers.anyString (org.mockito.Matchers.anyString)9 JsonValue (org.forgerock.json.JsonValue)8 ArrayList (java.util.ArrayList)7 Set (java.util.Set)7 EntitlementException (com.sun.identity.entitlement.EntitlementException)6