LDAP-56: generic integration tests are now configurable to run against a local LDAP server rather than startin in-process ApacheDS.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.ldap.test;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.directory.server.core.DefaultDirectoryService;
|
||||
import org.apache.directory.server.core.DirectoryService;
|
||||
import org.apache.directory.server.core.entry.ServerEntry;
|
||||
@@ -35,6 +36,7 @@ import java.io.File;
|
||||
public final class EmbeddedLdapServer {
|
||||
private final DirectoryService directoryService;
|
||||
private final LdapServer ldapServer;
|
||||
private static File workingDirectory;
|
||||
|
||||
private EmbeddedLdapServer(DirectoryService directoryService,
|
||||
LdapServer ldapServer) {
|
||||
@@ -44,11 +46,14 @@ public final class EmbeddedLdapServer {
|
||||
|
||||
public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName, String defaultPartitionSuffix, int port)
|
||||
throws Exception{
|
||||
workingDirectory = new File(System.getProperty("java.io.tmpdir") + "/apacheds-test1");
|
||||
FileUtils.deleteDirectory(workingDirectory);
|
||||
|
||||
DefaultDirectoryService directoryService = new DefaultDirectoryService();
|
||||
directoryService.setShutdownHookEnabled(true);
|
||||
directoryService.setAllowAnonymousAccess(true);
|
||||
directoryService.setWorkingDirectory(new File(System.getProperty("java.io.tmpdir") + "/apacheds-test1"));
|
||||
|
||||
directoryService.setWorkingDirectory(workingDirectory);
|
||||
directoryService.getChangeLog().setEnabled( false );
|
||||
|
||||
JdbmPartition partition = new JdbmPartition();
|
||||
@@ -80,5 +85,7 @@ public final class EmbeddedLdapServer {
|
||||
public void shutdown() throws Exception {
|
||||
ldapServer.stop();
|
||||
directoryService.shutdown();
|
||||
|
||||
FileUtils.deleteDirectory(workingDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,6 +229,10 @@ public final class LdapTestUtils {
|
||||
}
|
||||
|
||||
private static void loadLdif(DirContext context, Resource ldifFile) throws IOException {
|
||||
loadLdif(context, LdapUtils.emptyLdapName(), ldifFile);
|
||||
}
|
||||
|
||||
private static void loadLdif(DirContext context, Name rootNode, Resource ldifFile) {
|
||||
try {
|
||||
LdapName baseDn = (LdapName)
|
||||
context.getEnvironment().get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY);
|
||||
@@ -243,9 +247,13 @@ public final class LdapTestUtils {
|
||||
if(baseDn != null) {
|
||||
dn = LdapUtils.removeFirst(dn, baseDn);
|
||||
}
|
||||
|
||||
if(!rootNode.isEmpty()) {
|
||||
dn = LdapUtils.prepend(dn, rootNode);
|
||||
}
|
||||
context.bind(dn, null, record);
|
||||
}
|
||||
} catch (NamingException e) {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to populate LDIF", e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user