LdapTemplate implements LdapOperations, InitializingBean { @Override public void search(Name base, String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler) { search(base, filter, getDefaultSearchControls(searchScope, returningObjFlag, ALL_ATTRIBUTES), handler); } LdapTemplate();  LdapTemplate(ContextSource contextSource); void setContextSource(ContextSource contextSource); @Override ObjectDirectoryMapper getObjectDirectoryMapper(); void setObjectDirectoryMapper(ObjectDirectoryMapper odm); ContextSource getContextSource(); void setIgnoreNameNotFoundException(boolean ignore); void setIgnorePartialResultException(boolean ignore); void setIgnoreSizeLimitExceededException(boolean ignore); void setDefaultSearchScope(int defaultSearchScope); void setDefaultTimeLimit(int defaultTimeLimit); void setDefaultCountLimit(int defaultCountLimit); @Override void search(Name base, String filter, int searchScope, boolean returningObjFlag,
			NameClassPairCallbackHandler handler); @Override void search(String base, String filter, int searchScope, boolean returningObjFlag,
			NameClassPairCallbackHandler handler); @Override void search(final Name base, final String filter, final SearchControls controls,
			NameClassPairCallbackHandler handler); @Override void search(final String base, final String filter, final SearchControls controls,
			NameClassPairCallbackHandler handler); @Override void search(final Name base, final String filter, final SearchControls controls,
			NameClassPairCallbackHandler handler, DirContextProcessor processor); @Override void search(final String base, final String filter, final SearchControls controls,
			NameClassPairCallbackHandler handler, DirContextProcessor processor); @Override void search(SearchExecutor se, NameClassPairCallbackHandler handler, DirContextProcessor processor); @Override void search(SearchExecutor se, NameClassPairCallbackHandler handler); @Override void search(Name base, String filter, NameClassPairCallbackHandler handler); @Override void search(String base, String filter, NameClassPairCallbackHandler handler); @Override List<T> search(Name base, String filter, int searchScope, String[] attrs, AttributesMapper<T> mapper); @Override List<T> search(String base, String filter, int searchScope, String[] attrs, AttributesMapper<T> mapper); @Override List<T> search(Name base, String filter, int searchScope, AttributesMapper<T> mapper); @Override List<T> search(String base, String filter, int searchScope, AttributesMapper<T> mapper); @Override List<T> search(Name base, String filter, AttributesMapper<T> mapper); @Override List<T> search(String base, String filter, AttributesMapper<T> mapper); @Override List<T> search(Name base, String filter, int searchScope, String[] attrs, ContextMapper<T> mapper); @Override List<T> search(String base, String filter, int searchScope, String[] attrs, ContextMapper<T> mapper); @Override List<T> search(Name base, String filter, int searchScope, ContextMapper<T> mapper); @Override List<T> search(String base, String filter, int searchScope, ContextMapper<T> mapper); @Override List<T> search(Name base, String filter, ContextMapper<T> mapper); @Override List<T> search(String base, String filter, ContextMapper<T> mapper); @Override List<T> search(String base, String filter, SearchControls controls, ContextMapper<T> mapper); @Override List<T> search(Name base, String filter, SearchControls controls, ContextMapper<T> mapper); @Override List<T> search(Name base, String filter, SearchControls controls, AttributesMapper<T> mapper); @Override List<T> search(String base, String filter, SearchControls controls, AttributesMapper<T> mapper); @Override List<T> search(String base, String filter, SearchControls controls, AttributesMapper<T> mapper,
			DirContextProcessor processor); @Override List<T> search(Name base, String filter, SearchControls controls, AttributesMapper<T> mapper,
			DirContextProcessor processor); @Override List<T> search(String base, String filter, SearchControls controls, ContextMapper<T> mapper,
			DirContextProcessor processor); @Override List<T> search(Name base, String filter, SearchControls controls, ContextMapper<T> mapper,
			DirContextProcessor processor); @Override void list(final String base, NameClassPairCallbackHandler handler); @Override void list(final Name base, NameClassPairCallbackHandler handler); @Override List<T> list(String base, NameClassPairMapper<T> mapper); @Override List<T> list(Name base, NameClassPairMapper<T> mapper); @Override List<String> list(final Name base); @Override List<String> list(final String base); @Override void listBindings(final String base, NameClassPairCallbackHandler handler); @Override void listBindings(final Name base, NameClassPairCallbackHandler handler); @Override List<T> listBindings(String base, NameClassPairMapper<T> mapper); @Override List<T> listBindings(Name base, NameClassPairMapper<T> mapper); @Override List<String> listBindings(final String base); @Override List<String> listBindings(final Name base); @Override List<T> listBindings(String base, ContextMapper<T> mapper); @Override List<T> listBindings(Name base, ContextMapper<T> mapper); @Override T executeReadOnly(ContextExecutor<T> ce); @Override T executeReadWrite(ContextExecutor<T> ce); @Override Object lookup(final Name dn); @Override Object lookup(final String dn); @Override T lookup(final Name dn, final AttributesMapper<T> mapper); @Override T lookup(final String dn, final AttributesMapper<T> mapper); @Override T lookup(final Name dn, final ContextMapper<T> mapper); @Override T lookup(final String dn, final ContextMapper<T> mapper); @Override T lookup(final Name dn, final String[] attributes, final AttributesMapper<T> mapper); @Override T lookup(final String dn, final String[] attributes, final AttributesMapper<T> mapper); @Override T lookup(final Name dn, final String[] attributes, final ContextMapper<T> mapper); @Override T lookup(final String dn, final String[] attributes, final ContextMapper<T> mapper); @Override void modifyAttributes(final Name dn, final ModificationItem[] mods); @Override void modifyAttributes(final String dn, final ModificationItem[] mods); @Override void bind(final Name dn, final Object obj, final Attributes attributes); @Override void bind(final String dn, final Object obj, final Attributes attributes); @Override void unbind(final Name dn); @Override void unbind(final String dn); @Override void unbind(final Name dn, boolean recursive); @Override void unbind(final String dn, boolean recursive); @Override void rebind(final Name dn, final Object obj, final Attributes attributes); @Override void rebind(final String dn, final Object obj, final Attributes attributes); @Override void rename(final Name oldDn, final Name newDn); @Override void rename(final String oldDn, final String newDn); @Override void afterPropertiesSet(); @Override DirContextOperations lookupContext(Name dn); @Override DirContextOperations lookupContext(String dn); @Override void modifyAttributes(DirContextOperations ctx); @Override void bind(DirContextOperations ctx); @Override void rebind(DirContextOperations ctx); @Override boolean authenticate(Name base, String filter, String password); @Override boolean authenticate(String base, String filter, String password); @Override boolean authenticate(String base, String filter, String password,
			AuthenticatedLdapEntryContextCallback callback); @Override boolean authenticate(Name base, String filter, String password,
			final AuthenticatedLdapEntryContextCallback callback); @Override boolean authenticate(String base, String filter, String password,
			AuthenticationErrorCallback errorCallback); @Override boolean authenticate(Name base, String filter, String password,
			final AuthenticationErrorCallback errorCallback); @Override boolean authenticate(String base, String filter, String password,
			final AuthenticatedLdapEntryContextCallback callback, final AuthenticationErrorCallback errorCallback); @Override boolean authenticate(Name base, String filter, String password,
			final AuthenticatedLdapEntryContextCallback callback, final AuthenticationErrorCallback errorCallback); @Override T authenticate(LdapQuery query, String password, AuthenticatedLdapEntryContextMapper<T> mapper); @Override void authenticate(LdapQuery query, String password); @Override T searchForObject(Name base, String filter, ContextMapper<T> mapper); @Override T searchForObject(String base, String filter, ContextMapper<T> mapper); @Override T searchForObject(Name base, String filter, SearchControls searchControls, ContextMapper<T> mapper); @Override T searchForObject(String base, String filter, SearchControls searchControls, ContextMapper<T> mapper); @Override void search(LdapQuery query, NameClassPairCallbackHandler callbackHandler); @Override List<T> search(LdapQuery query, ContextMapper<T> mapper); @Override List<T> search(LdapQuery query, AttributesMapper<T> mapper); @Override DirContextOperations searchForContext(LdapQuery query); @Override T searchForObject(LdapQuery query, ContextMapper<T> mapper); @Override T findByDn(Name dn, final Class<T> clazz); @Override void create(Object entry); @Override void update(Object entry); @Override void delete(Object entry); @Override List<T> findAll(Name base, SearchControls searchControls, final Class<T> clazz); @Override List<T> findAll(Class<T> clazz); @Override List<T> find(Name base, Filter filter, SearchControls searchControls, final Class<T> clazz); @Override List<T> find(LdapQuery query, Class<T> clazz); @Override T findOne(LdapQuery query, Class<T> clazz);  }
@Test public void testSearch_CallbackHandler() throws Exception { expectGetReadOnlyContext(); SearchResult searchResult = new SearchResult("", new Object(), new BasicAttributes()); singleSearchResult(searchControlsOneLevel(), searchResult); tested.search(nameMock, "(ou=somevalue)", 1, true, handlerMock); verify(handlerMock).handleNameClassPair(searchResult); verify(dirContextMock).close(); }
@Test public void testSearch_StringBase_CallbackHandler() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsOneLevel(); SearchResult searchResult = new SearchResult("", new Object(), new BasicAttributes()); singleSearchResultWithStringBase(controls, searchResult); tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", 1, true, handlerMock); verify(handlerMock).handleNameClassPair(searchResult); verify(dirContextMock).close(); }
@Test public void testSearch_CallbackHandler_Defaults() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); controls.setReturningObjFlag(false); SearchResult searchResult = new SearchResult("", new Object(), new BasicAttributes()); singleSearchResult(controls, searchResult); tested.search(nameMock, "(ou=somevalue)", handlerMock); verify(handlerMock).handleNameClassPair(searchResult); verify(dirContextMock).close(); }
@Test public void testSearch_String_CallbackHandler_Defaults() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); controls.setReturningObjFlag(false); SearchResult searchResult = new SearchResult("", new Object(), new BasicAttributes()); singleSearchResultWithStringBase(controls, searchResult); tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", handlerMock); verify(handlerMock).handleNameClassPair(searchResult); verify(dirContextMock).close(); }
@Test public void testSearch_NameNotFoundException() throws Exception { expectGetReadOnlyContext(); final SearchControls controls = searchControlsRecursive(); controls.setReturningObjFlag(false); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException("some text"); when(dirContextMock.search( eq(nameMock), eq("(ou=somevalue)"), argThat(new SearchControlsMatcher(controls)))).thenThrow(ne); try { tested.search(nameMock, "(ou=somevalue)", handlerMock); fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { assertThat(true).isTrue(); } verify(dirContextMock).close(); }
@Test public void testSearch_NamingException() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); controls.setReturningObjFlag(false); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); when(dirContextMock.search( eq(nameMock), eq("(ou=somevalue)"), argThat(new SearchControlsMatcher(controls)))).thenThrow(ne); try { tested.search(nameMock, "(ou=somevalue)", handlerMock); fail("LimitExceededException expected"); } catch (LimitExceededException expected) { } verify(dirContextMock).close(); }
@Test public void testSearch_CallbackHandler_DirContextProcessor() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); controls.setReturningObjFlag(false); SearchResult searchResult = new SearchResult("", new Object(), new BasicAttributes()); singleSearchResult(controls, searchResult); tested.search(nameMock, "(ou=somevalue)", controls, handlerMock, dirContextProcessorMock); verify(dirContextProcessorMock).preProcess(dirContextMock); verify(dirContextProcessorMock).postProcess(dirContextMock); verify(namingEnumerationMock).close(); verify(handlerMock).handleNameClassPair(searchResult); verify(dirContextMock).close(); }
@Test public void testSearch_String_CallbackHandler_DirContextProcessor() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); controls.setReturningObjFlag(false); SearchResult searchResult = new SearchResult("", new Object(), new BasicAttributes()); singleSearchResultWithStringBase(controls, searchResult); tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, handlerMock, dirContextProcessorMock); verify(dirContextProcessorMock).preProcess(dirContextMock); verify(dirContextProcessorMock).postProcess(dirContextMock); verify(namingEnumerationMock).close(); verify(handlerMock).handleNameClassPair(searchResult); verify(dirContextMock).close(); }
@Test public void testSearch_String_AttributesMapper_DirContextProcessor() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsOneLevel(); controls.setReturningObjFlag(false); BasicAttributes expectedAttributes = new BasicAttributes(); SearchResult searchResult = new SearchResult("", null, expectedAttributes); singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = new Object(); when(attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, attributesMapperMock, dirContextProcessorMock); verify(dirContextProcessorMock).preProcess(dirContextMock); verify(dirContextProcessorMock).postProcess(dirContextMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_Name_AttributesMapper_DirContextProcessor() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsOneLevel(); controls.setReturningObjFlag(false); BasicAttributes expectedAttributes = new BasicAttributes(); SearchResult searchResult = new SearchResult("", null, expectedAttributes); singleSearchResult(controls, searchResult); Object expectedResult = new Object(); when(attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); List list = tested.search(nameMock, "(ou=somevalue)", controls, attributesMapperMock, dirContextProcessorMock); verify(dirContextProcessorMock).preProcess(dirContextMock); verify(dirContextProcessorMock).postProcess(dirContextMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_String_SearchControls_ContextMapper_DirContextProcessor() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, contextMapperMock, dirContextProcessorMock); verify(dirContextProcessorMock).preProcess(dirContextMock); verify(dirContextProcessorMock).postProcess(dirContextMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_Name_SearchControls_ContextMapper_DirContextProcessor() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResult(controls, searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(nameMock, "(ou=somevalue)", controls, contextMapperMock, dirContextProcessorMock); verify(dirContextProcessorMock).preProcess(dirContextMock); verify(dirContextProcessorMock).postProcess(dirContextMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_AttributesMapper_ReturningAttrs() throws Exception { expectGetReadOnlyContext(); String[] attrs = new String[0]; SearchControls controls = new SearchControls(); controls.setSearchScope(SearchControls.ONELEVEL_SCOPE); controls.setReturningObjFlag(false); controls.setReturningAttributes(attrs); BasicAttributes expectedAttributes = new BasicAttributes(); SearchResult searchResult = new SearchResult("", null, expectedAttributes); singleSearchResult(controls, searchResult); Object expectedResult = new Object(); when(attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); List list = tested.search(nameMock, "(ou=somevalue)", 1, attrs, attributesMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_String_AttributesMapper_ReturningAttrs() throws Exception { expectGetReadOnlyContext(); String[] attrs = new String[0]; SearchControls controls = new SearchControls(); controls.setSearchScope(SearchControls.ONELEVEL_SCOPE); controls.setReturningObjFlag(false); controls.setReturningAttributes(attrs); BasicAttributes expectedAttributes = new BasicAttributes(); SearchResult searchResult = new SearchResult("", null, expectedAttributes); singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = new Object(); when(attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", 1, attrs, attributesMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_AttributesMapper() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsOneLevel(); controls.setReturningObjFlag(false); BasicAttributes expectedAttributes = new BasicAttributes(); SearchResult searchResult = new SearchResult("", null, expectedAttributes); singleSearchResult(controls, searchResult); Object expectedResult = new Object(); when(attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); List list = tested.search(nameMock, "(ou=somevalue)", 1, attributesMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_String_AttributesMapper() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsOneLevel(); controls.setReturningObjFlag(false); BasicAttributes expectedAttributes = new BasicAttributes(); SearchResult searchResult = new SearchResult("", null, expectedAttributes); singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = new Object(); when(attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", 1, attributesMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_AttributesMapper_Default() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); controls.setReturningObjFlag(false); BasicAttributes expectedAttributes = new BasicAttributes(); SearchResult searchResult = new SearchResult("", null, expectedAttributes); singleSearchResult(controls, searchResult); Object expectedResult = new Object(); when(attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); List list = tested.search(nameMock, "(ou=somevalue)", attributesMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_String_AttributesMapper_Default() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); controls.setReturningObjFlag(false); BasicAttributes expectedAttributes = new BasicAttributes(); SearchResult searchResult = new SearchResult("", null, expectedAttributes); singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = new Object(); when(attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", attributesMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_ContextMapper() throws Exception { expectGetReadOnlyContext(); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResult(searchControlsOneLevel(), searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(nameMock, "(ou=somevalue)", 1, contextMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_ContextMapper_ReturningAttrs() throws Exception { expectGetReadOnlyContext(); String[] attrs = new String[0]; SearchControls controls = searchControlsOneLevel(); controls.setReturningAttributes(attrs); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResult(controls, searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(nameMock, "(ou=somevalue)", 1, attrs, contextMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_String_ContextMapper_ReturningAttrs() throws Exception { expectGetReadOnlyContext(); String[] attrs = new String[0]; SearchControls controls = searchControlsOneLevel(); controls.setReturningAttributes(attrs); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", 1, attrs, contextMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_String_ContextMapper() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsOneLevel(); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", 1, contextMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_ContextMapper_Default() throws Exception { expectGetReadOnlyContext(); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResult(searchControlsRecursive(), searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(nameMock, "(ou=somevalue)", contextMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_String_ContextMapper_Default() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", contextMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_String_SearchControls_ContextMapper() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, contextMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_String_SearchControls_ContextMapper_ReturningObjFlagNotSet() throws Exception { expectGetReadOnlyContext(); SearchControls controls = new SearchControls(); controls.setSearchScope(SearchControls.SUBTREE_SCOPE); SearchControls expectedControls = new SearchControls(); expectedControls.setSearchScope(SearchControls.SUBTREE_SCOPE); expectedControls.setReturningObjFlag(true); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResultWithStringBase(expectedControls, searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, contextMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_Name_SearchControls_ContextMapper() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsRecursive(); Object expectedObject = new Object(); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResult(controls, searchResult); Object expectedResult = expectedObject; when(contextMapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); List list = tested.search(nameMock, "(ou=somevalue)", controls, contextMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_String_SearchControls_AttributesMapper() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsOneLevel(); controls.setReturningObjFlag(false); BasicAttributes expectedAttributes = new BasicAttributes(); SearchResult searchResult = new SearchResult("", null, expectedAttributes); singleSearchResultWithStringBase(controls, searchResult); Object expectedResult = new Object(); when(attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); List list = tested.search(DEFAULT_BASE_STRING, "(ou=somevalue)", controls, attributesMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testSearch_Name_SearchControls_AttributesMapper() throws Exception { expectGetReadOnlyContext(); SearchControls controls = searchControlsOneLevel(); controls.setReturningObjFlag(false); BasicAttributes expectedAttributes = new BasicAttributes(); SearchResult searchResult = new SearchResult("", null, expectedAttributes); singleSearchResult(controls, searchResult); Object expectedResult = new Object(); when(attributesMapperMock.mapFromAttributes(expectedAttributes)).thenReturn(expectedResult); List list = tested.search(nameMock, "(ou=somevalue)", controls, attributesMapperMock); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); assertThat(list).isNotNull(); assertThat(list).hasSize(1); assertThat(list.get(0)).isSameAs(expectedResult); }
@Test public void testDoSearch_DirContextProcessor() throws Exception { expectGetReadOnlyContext(); SearchResult searchResult = new SearchResult(null, null, null); when(searchExecutorMock.executeSearch(dirContextMock)).thenReturn(namingEnumerationMock); when(namingEnumerationMock.hasMore()).thenReturn(true, false); when(namingEnumerationMock.next()).thenReturn(searchResult); tested.search(searchExecutorMock, handlerMock, dirContextProcessorMock); verify(dirContextProcessorMock).preProcess(dirContextMock); verify(dirContextProcessorMock).postProcess(dirContextMock); verify(handlerMock).handleNameClassPair(searchResult); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); }
@Test public void testDoSearch_DirContextProcessor_NamingException() throws Exception { expectGetReadOnlyContext(); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); when(searchExecutorMock.executeSearch(dirContextMock)).thenThrow(ne); try { tested.search(searchExecutorMock, handlerMock, dirContextProcessorMock); fail("LimitExceededException expected"); } catch (LimitExceededException expected) { assertThat(true).isTrue(); } verify(dirContextProcessorMock).preProcess(dirContextMock); verify(dirContextProcessorMock).postProcess(dirContextMock); verify(dirContextMock).close(); }
@Test public void testDoSearch() throws Exception { expectGetReadOnlyContext(); SearchResult searchResult = new SearchResult(null, null, null); when(searchExecutorMock.executeSearch(dirContextMock)).thenReturn(namingEnumerationMock); when(namingEnumerationMock.hasMore()).thenReturn(true, false); when(namingEnumerationMock.next()).thenReturn(searchResult); tested.search(searchExecutorMock, handlerMock); verify(handlerMock).handleNameClassPair(searchResult); verify(namingEnumerationMock).close(); verify(dirContextMock).close(); }
@Test public void testDoSearch_NamingException() throws Exception { expectGetReadOnlyContext(); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); when(searchExecutorMock.executeSearch(dirContextMock)).thenThrow(ne); try { tested.search(searchExecutorMock, handlerMock); fail("LimitExceededException expected"); } catch (LimitExceededException expected) { assertThat(true).isTrue(); } verify(dirContextMock).close(); }
@Test public void testDoSearch_NamingException_NamingEnumeration() throws Exception { expectGetReadOnlyContext(); when(searchExecutorMock.executeSearch(dirContextMock)).thenReturn(namingEnumerationMock); javax.naming.LimitExceededException ne = new javax.naming.LimitExceededException(); when(namingEnumerationMock.hasMore()).thenThrow(ne); try { tested.search(searchExecutorMock, handlerMock); fail("LimitExceededException expected"); } catch (LimitExceededException expected) { assertThat(true).isTrue(); } verify(namingEnumerationMock).close(); verify(dirContextMock).close(); }
@Test public void testDoSearch_NameNotFoundException() throws Exception { expectGetReadOnlyContext(); when(searchExecutorMock.executeSearch(dirContextMock)).thenThrow(new javax.naming.NameNotFoundException()); try { tested.search(searchExecutorMock, handlerMock); fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { assertThat(true).isTrue(); } verify(dirContextMock).close(); }
@Test public void testSearch_PartialResult_IgnoreNotSet() throws Exception { expectGetReadOnlyContext(); javax.naming.PartialResultException ex = new javax.naming.PartialResultException(); when(searchExecutorMock.executeSearch(dirContextMock)).thenThrow(ex); try { tested.search(searchExecutorMock, handlerMock, dirContextProcessorMock); fail("PartialResultException expected"); } catch (PartialResultException expected) { assertThat(true).isTrue(); } verify(dirContextProcessorMock).preProcess(dirContextMock); verify(dirContextProcessorMock).postProcess(dirContextMock); verify(dirContextMock).close(); }