use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldSendAllMatchingPoliciesToQueryHandler.
@Test
public void shouldSendAllMatchingPoliciesToQueryHandler() throws Exception {
// Given
QueryRequest request = mockQueryRequest(QueryFilter.<JsonPointer>alwaysTrue());
Subject subject = new Subject();
Set<String> applications = asSet("one", "two", "three");
given(applicationManagerWrapper.search(eq(subject), eq("/abc"), any(Set.class))).willReturn(applications);
// When
Set<String> result = applicationsResource.query(request, subject, "/abc");
// Then
assertThat(result).isEqualTo(applications);
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class DecisionCombinersResourceTest method testSuccessfulJsonificationAndQuery.
@Test
public void testSuccessfulJsonificationAndQuery() throws JsonMappingException {
//given
SubjectContext mockSubjectContext = mock(SubjectContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
testResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
verify(mockHandler, times(1)).handleResource(any(ResourceResponse.class));
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ApplicationV1FilterTest method forwardOnQuery.
/**
* Verify that query requests are forwarded on and that the response is tailored to represent v1.0 application.
*/
@Test
public void forwardOnQuery() throws Exception {
// Given
given(contextHelper.getRealm(context)).willReturn("/abc");
given(contextHelper.getSubject(context)).willReturn(subject);
QueryRequest queryRequest = mock(QueryRequest.class);
given(requestHandler.handleQuery(eq(context), eq(queryRequest), any(QueryResourceHandler.class))).willReturn(mockQueryResponse);
// When
filter.filterQuery(context, queryRequest, queryResultHandler, requestHandler);
// Then
verify(requestHandler).handleQuery(eq(context), eq(queryRequest), queryResultHandlerCaptor.capture());
verify(applicationTransformer).transform(eq(mockQueryResponse), eq(context), eq(queryRequest), eq(queryResultHandler), anyCollectionOf(ResourceResponse.class));
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldTranslateSupportedOperators.
@Test(dataProvider = "SupportedQueryOperators")
public void shouldTranslateSupportedOperators(String queryOperator, SearchFilter.Operator expectedOperator) throws Exception {
// Given
long value = 123l;
QueryRequest request = mockQueryRequest(comparisonFilter(new JsonPointer(NUMERIC_ATTRIBUTE), queryOperator, value));
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then
SearchFilter searchFilter = new SearchFilter(new SearchAttribute(NUMERIC_ATTRIBUTE, "ou"), value, expectedOperator);
verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter)));
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldRejectPresenceQueries.
@Test(expectedExceptions = EntitlementException.class, expectedExceptionsMessageRegExp = ".*not supported.*")
public void shouldRejectPresenceQueries() throws Exception {
// Given
QueryRequest request = mockQueryRequest(present(new JsonPointer(STRING_ATTRIBUTE)));
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then - exception
}
Aggregations