Set up and expect LDAP server contents.
import com.google.common.base.Supplier;
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
import org.junit.Rule
import org.junit.Test;
import com.zimory.ldapunit.core.ShouldMatchLdapDataSet;
import com.zimory.ldapunit.core.UsingLdapDataSet;
import com.zimory.ldapunit.core.LdapWatcher;
import com.zimory.ldapunit.core.DirectoryServerAccess;
import com.zimory.ldapunit.core.InMemoryDirectoryServerAccess;
public class SomeIT extends AbstractIT {
private static final String ROOT_CONTEXT_DN = "dc=example,dc=com";
@Inject
private InMemoryDirectoryServer ldapServer;
@Rule
public LdapWatcher ldapWatcher = new LdapWatcher(new Supplier<DirectoryServerAccess>() {
@Override
public DirectoryServerAccess get() {
return new InMemoryDirectoryServerAccess(ldapServer, ROOT_CONTEXT_DN);
}
});
@Test
@UsingLdapDataSet
@ShouldMatchLdapDataSet
public void findAndAddNewEntry() throws Exception {
ldapServer.assertEntryExists("cn=SomeUser," + ROOT_CONTEXT_DN);
ldapServer.add(new Entry("cn=SomeOtherUser," + ROOT_CONTEXT_DN, new Attribute("objectClass", "top")));
}
}
dn: cn=SomeUser,dc=example,dc=com
cn: SomeUser
objectClass: top
dn: cn=SomeUser,dc=example,dc=com
cn: SomeUser
objectClass: top
dn: cn=SomeOtherUser,dc=example,dc=com
cn: SomeOtherUser
objectClass: top
Just instantiate com.zimory.ldapunit.core.InMemoryDirectoryServerAccess
as shown in the example above and pass it to the LdapWatcher rule.
Provide an implementation of the com.zimory.ldapunit.core.DirectoryServerAccess
interface yourself.
<dependency>
<groupId>com.zimory.ldapunit</groupId>
<artifactId>ldapunit-core</artifactId>
<version>1.0.0</version>
</dependency>