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));
}
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);
}
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
}
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
}
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;
}
Aggregations