Class LdapTestUtils

java.lang.Object
org.springframework.ldap.test.unboundid.LdapTestUtils

public final class LdapTestUtils extends Object
Utilities for starting, stopping and populating an in-process Apache Directory Server to use for integration testing purposes.
  • Method Details

    • startEmbeddedServer

      public static void startEmbeddedServer(int port, String defaultPartitionSuffix, String defaultPartitionName)
      Start an embedded Apache Directory Server. Only one embedded server will be permitted in the same JVM.
      Parameters:
      port - the port on which the server will be listening.
      defaultPartitionSuffix - The default base suffix that will be used for the LDAP server.
      defaultPartitionName - The name to use in the directory server configuration for the default base suffix.
      Throws:
      IllegalStateException - if an embedded server is already started.
    • shutdownEmbeddedServer

      public static void shutdownEmbeddedServer() throws Exception
      Shuts down the embedded server, if there is one. If no server was previously started in this JVM this is silently ignored.
      Throws:
      Exception
    • clearSubContexts

      public static void clearSubContexts(ContextSource contextSource, Name name) throws NamingException
      Clear the directory sub-tree starting with the node represented by the supplied distinguished name.
      Parameters:
      contextSource - the ContextSource to use for getting a DirContext.
      name - the distinguished name of the root node.
      Throws:
      NamingException - if anything goes wrong removing the sub-tree.
    • clearSubContexts

      public static void clearSubContexts(DirContext ctx, Name name) throws NamingException
      Clear the directory sub-tree starting with the node represented by the supplied distinguished name.
      Parameters:
      ctx - The DirContext to use for cleaning the tree.
      name - the distinguished name of the root node.
      Throws:
      NamingException - if anything goes wrong removing the sub-tree.
    • loadLdif

      public static void loadLdif(ContextSource contextSource, org.springframework.core.io.Resource ldifFile) throws IOException
      Load an Ldif file into an LDAP server.
      Parameters:
      contextSource - ContextSource to use for getting a DirContext to interact with the LDAP server.
      ldifFile - a Resource representing a valid LDIF file.
      Throws:
      IOException - if the Resource cannot be read.
    • cleanAndSetup

      public static void cleanAndSetup(ContextSource contextSource, Name rootNode, org.springframework.core.io.Resource ldifFile) throws NamingException, IOException
      Throws:
      NamingException
      IOException
    • loadLdif

      public static void loadLdif(com.unboundid.ldap.listener.InMemoryDirectoryServer directoryServer, org.springframework.core.io.Resource ldifFile) throws IOException
      Throws:
      IOException