@Test public void shouldUseHandlerToPerformSearch() throws CoreTokenException, IOException { Result mockResult = mock(Result.class); given(searchHandler.performSearch(any(SearchRequest.class), any(Collection.class))).willReturn(mockResult); builder.executeRawResults(); verify(searchHandler).performSearch(any(SearchRequest.class), any(Collection.class)); }
public Collection<Entry> executeRawResults() throws CoreTokenException { Filter ldapFilter = getLDAPFilter(); SearchRequest searchRequest = Requests.newSearchRequest( constants.getTokenStoreRootSuffix(), SearchScope.WHOLE_SUBTREE, ldapFilter, requestedAttributes); searchRequest.setSizeLimit(sizeLimit); if (isPagingResults()) { searchRequest = searchRequest.addControl(SimplePagedResultsControl.newControl(true, pageSize, pagingCookie)); } Collection<Entry> entries = createResultsList(); Result result = handler.performSearch(searchRequest, entries); if (isPagingResults()) { try { SimplePagedResultsControl control = result.getControl( SimplePagedResultsControl.DECODER, new DecodeOptions()); if (control == null) { if (debug.warningEnabled()) { debug.warning("There was no paged result control in the search response, it is recommended to " + "set the CTS user's size-limit at least to " + (pageSize + 1)); } pagingCookie = getEmptyPagingCookie(); } else { pagingCookie = control.getCookie(); } } catch (DecodeException e) { throw new CoreTokenException("Failed to decode Paging Cookie", e); } } if (debug.messageEnabled()) { debug.message(MessageFormat.format( CoreTokenConstants.DEBUG_HEADER + "Query: matched {0} results\n" + "Search Request: {1}\n" + "Filter: {2}\n" + "Result: {3}", entries.size(), searchRequest, ldapFilter.toString(), result)); } return entries; }
QueryBuilder { public Collection<Entry> executeRawResults() throws CoreTokenException { Filter ldapFilter = getLDAPFilter(); SearchRequest searchRequest = Requests.newSearchRequest( constants.getTokenStoreRootSuffix(), SearchScope.WHOLE_SUBTREE, ldapFilter, requestedAttributes); searchRequest.setSizeLimit(sizeLimit); if (isPagingResults()) { searchRequest = searchRequest.addControl(SimplePagedResultsControl.newControl(true, pageSize, pagingCookie)); } Collection<Entry> entries = createResultsList(); Result result = handler.performSearch(searchRequest, entries); if (isPagingResults()) { try { SimplePagedResultsControl control = result.getControl( SimplePagedResultsControl.DECODER, new DecodeOptions()); if (control == null) { if (debug.warningEnabled()) { debug.warning("There was no paged result control in the search response, it is recommended to " + "set the CTS user's size-limit at least to " + (pageSize + 1)); } pagingCookie = getEmptyPagingCookie(); } else { pagingCookie = control.getCookie(); } } catch (DecodeException e) { throw new CoreTokenException("Failed to decode Paging Cookie", e); } } if (debug.messageEnabled()) { debug.message(MessageFormat.format( CoreTokenConstants.DEBUG_HEADER + "Query: matched {0} results\n" + "Search Request: {1}\n" + "Filter: {2}\n" + "Result: {3}", entries.size(), searchRequest, ldapFilter.toString(), result)); } return entries; } }
QueryBuilder { public Collection<Entry> executeRawResults() throws CoreTokenException { Filter ldapFilter = getLDAPFilter(); SearchRequest searchRequest = Requests.newSearchRequest( constants.getTokenStoreRootSuffix(), SearchScope.WHOLE_SUBTREE, ldapFilter, requestedAttributes); searchRequest.setSizeLimit(sizeLimit); if (isPagingResults()) { searchRequest = searchRequest.addControl(SimplePagedResultsControl.newControl(true, pageSize, pagingCookie)); } Collection<Entry> entries = createResultsList(); Result result = handler.performSearch(searchRequest, entries); if (isPagingResults()) { try { SimplePagedResultsControl control = result.getControl( SimplePagedResultsControl.DECODER, new DecodeOptions()); if (control == null) { if (debug.warningEnabled()) { debug.warning("There was no paged result control in the search response, it is recommended to " + "set the CTS user's size-limit at least to " + (pageSize + 1)); } pagingCookie = getEmptyPagingCookie(); } else { pagingCookie = control.getCookie(); } } catch (DecodeException e) { throw new CoreTokenException("Failed to decode Paging Cookie", e); } } if (debug.messageEnabled()) { debug.message(MessageFormat.format( CoreTokenConstants.DEBUG_HEADER + "Query: matched {0} results\n" + "Search Request: {1}\n" + "Filter: {2}\n" + "Result: {3}", entries.size(), searchRequest, ldapFilter.toString(), result)); } return entries; } @Inject  QueryBuilder(TokenAttributeConversion attributeConversion,
                        LDAPConfig constants, LDAPSearchHandler handler,
                        @Named(CoreTokenConstants.CTS_DEBUG) Debug debug); }
QueryBuilder { public Collection<Entry> executeRawResults() throws CoreTokenException { Filter ldapFilter = getLDAPFilter(); SearchRequest searchRequest = Requests.newSearchRequest( constants.getTokenStoreRootSuffix(), SearchScope.WHOLE_SUBTREE, ldapFilter, requestedAttributes); searchRequest.setSizeLimit(sizeLimit); if (isPagingResults()) { searchRequest = searchRequest.addControl(SimplePagedResultsControl.newControl(true, pageSize, pagingCookie)); } Collection<Entry> entries = createResultsList(); Result result = handler.performSearch(searchRequest, entries); if (isPagingResults()) { try { SimplePagedResultsControl control = result.getControl( SimplePagedResultsControl.DECODER, new DecodeOptions()); if (control == null) { if (debug.warningEnabled()) { debug.warning("There was no paged result control in the search response, it is recommended to " + "set the CTS user's size-limit at least to " + (pageSize + 1)); } pagingCookie = getEmptyPagingCookie(); } else { pagingCookie = control.getCookie(); } } catch (DecodeException e) { throw new CoreTokenException("Failed to decode Paging Cookie", e); } } if (debug.messageEnabled()) { debug.message(MessageFormat.format( CoreTokenConstants.DEBUG_HEADER + "Query: matched {0} results\n" + "Search Request: {1}\n" + "Filter: {2}\n" + "Result: {3}", entries.size(), searchRequest, ldapFilter.toString(), result)); } return entries; } @Inject  QueryBuilder(TokenAttributeConversion attributeConversion,
                        LDAPConfig constants, LDAPSearchHandler handler,
                        @Named(CoreTokenConstants.CTS_DEBUG) Debug debug); QueryBuilder limitResultsTo(int maxSize); QueryBuilder pageResultsBy(int pageSize, ByteString cookie); ByteString getPagingCookie(); boolean isPagingResults(); QueryBuilder returnTheseAttributes(CoreTokenField... fields); QueryBuilder withFilter(Filter filter); Collection<Entry> executeRawResults(); Collection<Token> execute(); @Override String toString(); static ByteString getEmptyPagingCookie(); }
QueryBuilder { public Collection<Entry> executeRawResults() throws CoreTokenException { Filter ldapFilter = getLDAPFilter(); SearchRequest searchRequest = Requests.newSearchRequest( constants.getTokenStoreRootSuffix(), SearchScope.WHOLE_SUBTREE, ldapFilter, requestedAttributes); searchRequest.setSizeLimit(sizeLimit); if (isPagingResults()) { searchRequest = searchRequest.addControl(SimplePagedResultsControl.newControl(true, pageSize, pagingCookie)); } Collection<Entry> entries = createResultsList(); Result result = handler.performSearch(searchRequest, entries); if (isPagingResults()) { try { SimplePagedResultsControl control = result.getControl( SimplePagedResultsControl.DECODER, new DecodeOptions()); if (control == null) { if (debug.warningEnabled()) { debug.warning("There was no paged result control in the search response, it is recommended to " + "set the CTS user's size-limit at least to " + (pageSize + 1)); } pagingCookie = getEmptyPagingCookie(); } else { pagingCookie = control.getCookie(); } } catch (DecodeException e) { throw new CoreTokenException("Failed to decode Paging Cookie", e); } } if (debug.messageEnabled()) { debug.message(MessageFormat.format( CoreTokenConstants.DEBUG_HEADER + "Query: matched {0} results\n" + "Search Request: {1}\n" + "Filter: {2}\n" + "Result: {3}", entries.size(), searchRequest, ldapFilter.toString(), result)); } return entries; } @Inject  QueryBuilder(TokenAttributeConversion attributeConversion,
                        LDAPConfig constants, LDAPSearchHandler handler,
                        @Named(CoreTokenConstants.CTS_DEBUG) Debug debug); QueryBuilder limitResultsTo(int maxSize); QueryBuilder pageResultsBy(int pageSize, ByteString cookie); ByteString getPagingCookie(); boolean isPagingResults(); QueryBuilder returnTheseAttributes(CoreTokenField... fields); QueryBuilder withFilter(Filter filter); Collection<Entry> executeRawResults(); Collection<Token> execute(); @Override String toString(); static ByteString getEmptyPagingCookie();  }