use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method queryShouldHandleAllResults.
@Test
public void queryShouldHandleAllResults() throws Exception {
//given
QueryRequest queryRequest = makeMockQueryRequest();
QueryResponseHandler queryHandler = makeQueryResponseHandler();
Map<String, Map<String, Set<String>>> resourceTypes = new HashMap<>();
final int resultSize = 10;
for (int i = 0; i < resultSize; i++) {
resourceTypes.put(UUID.randomUUID().toString(), rawData);
}
when(resourceTypeService.getResourceTypesData(any(Subject.class), anyString())).thenReturn(resourceTypes);
when(resourceTypeService.getResourceType(any(Subject.class), anyString(), anyString())).thenReturn(EntitlementUtils.resourceTypeFromMap(UUID.randomUUID().toString(), rawData));
//when
Promise<QueryResponse, ResourceException> promise = resourceTypesResource.queryCollection(mockServerContext, queryRequest, queryHandler);
//then
QueryResponse queryResponse = promise.getOrThrowUninterruptibly();
verify(queryHandler, times(resultSize)).handleResource(any(ResourceResponse.class));
assertThat(queryResponse.getRemainingPagedResults()).isEqualTo(0);
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class SubjectAttributesResourceV1Test method shouldPerformQueryForSubjectAttributes.
@Test
public void shouldPerformQueryForSubjectAttributes() throws Exception {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
Set<String> attributes = new HashSet<>();
attributes.add("attr");
attributes.add("attr2");
given(mockSAM.getAvailableSubjectAttributeNames()).willReturn(attributes);
//when
Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
promise.getOrThrowUninterruptibly();
ArgumentCaptor<ResourceResponse> captor = ArgumentCaptor.forClass(ResourceResponse.class);
verify(mockHandler, times(2)).handleResource(captor.capture());
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class SubjectAttributesResourceV1Test method shouldErrorWhenAttributeRetrievalFails.
@Test
public void shouldErrorWhenAttributeRetrievalFails() throws EntitlementException {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
given(mockSAM.getAvailableSubjectAttributeNames()).willThrow(new EntitlementException(401));
//when
Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
verify(mockDebug, times(1)).error(anyString());
assertThat(promise).failedWithResourceException().withCode(ResourceException.INTERNAL_ERROR);
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class SubjectAttributesResourceV1Test method shouldReturnNoResultWhenNoAttributes.
@Test
public void shouldReturnNoResultWhenNoAttributes() throws Exception {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
Set<String> attributes = new HashSet<>();
given(mockSAM.getAvailableSubjectAttributeNames()).willReturn(attributes);
//when
Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
promise.getOrThrowUninterruptibly();
ArgumentCaptor<ResourceResponse> captor = ArgumentCaptor.forClass(ResourceResponse.class);
verify(mockHandler, never()).handleResource(captor.capture());
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class RealmContextFilter method filterQuery.
@Override
public Promise<QueryResponse, ResourceException> filterQuery(Context context, QueryRequest request, QueryResourceHandler handler, RequestHandler next) {
try {
Context newContext = evaluate(context, request);
QueryRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfQueryRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
return next.handleQuery(evaluate(context, request), evaluatedRequest, handler);
} catch (ResourceException e) {
return newExceptionPromise(e);
}
}
Aggregations