LdapTemplate implements LdapOperations, InitializingBean { @Override public void bind(final Name dn, final Object obj, final Attributes attributes) { executeReadWrite(new ContextExecutor<Object>() { public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException { ctx.bind(dn, obj, attributes); return null; } }); } 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 testBind() throws Exception { expectGetReadWriteContext(); Object expectedObject = new Object(); BasicAttributes expectedAttributes = new BasicAttributes(); tested.bind(nameMock, expectedObject, expectedAttributes); verify(dirContextMock).bind(nameMock, expectedObject, expectedAttributes); verify(dirContextMock).close(); }
@Test public void testBind_String() throws Exception { expectGetReadWriteContext(); Object expectedObject = new Object(); BasicAttributes expectedAttributes = new BasicAttributes(); tested.bind(DEFAULT_BASE_STRING, expectedObject, expectedAttributes); verify(dirContextMock).bind(DEFAULT_BASE_STRING, expectedObject, expectedAttributes); verify(dirContextMock).close(); }
@Test public void testBind_NamingException() throws Exception { expectGetReadWriteContext(); Object expectedObject = new Object(); BasicAttributes expectedAttributes = new BasicAttributes(); javax.naming.NameNotFoundException ne = new javax.naming.NameNotFoundException(); doThrow(ne).when(dirContextMock).bind(nameMock, expectedObject, expectedAttributes); try { tested.bind(nameMock, expectedObject, expectedAttributes); fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { assertThat(true).isTrue(); } verify(dirContextMock).close(); }
@Test public void testBindWithContext() throws Exception { expectGetReadWriteContext(); when(dirContextOperationsMock.getDn()).thenReturn(nameMock); when(dirContextOperationsMock.isUpdateMode()).thenReturn(false); tested.bind(dirContextOperationsMock); verify(dirContextMock).bind(nameMock, dirContextOperationsMock, null); verify(dirContextMock).close(); }