Class LdapTestUtils


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void cleanAndSetup​(org.springframework.ldap.core.ContextSource contextSource, javax.naming.Name rootNode, org.springframework.core.io.Resource ldifFile)  
      static void clearSubContexts​(javax.naming.directory.DirContext ctx, javax.naming.Name name)
      Clear the directory sub-tree starting with the node represented by the supplied distinguished name.
      static void clearSubContexts​(org.springframework.ldap.core.ContextSource contextSource, javax.naming.Name name)
      Clear the directory sub-tree starting with the node represented by the supplied distinguished name.
      static void loadLdif​(com.unboundid.ldap.listener.InMemoryDirectoryServer directoryServer, org.springframework.core.io.Resource ldifFile)  
      static void loadLdif​(org.springframework.ldap.core.ContextSource contextSource, org.springframework.core.io.Resource ldifFile)
      Load an Ldif file into an LDAP server.
      static void shutdownEmbeddedServer()
      Shuts down the embedded server, if there is one.
      static void startEmbeddedServer​(int port, java.lang.String defaultPartitionSuffix, java.lang.String defaultPartitionName)
      Start an embedded Apache Directory Server.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • startEmbeddedServer

        public static void startEmbeddedServer​(int port,
                                               java.lang.String defaultPartitionSuffix,
                                               java.lang.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:
        java.lang.IllegalStateException - if an embedded server is already started.
      • shutdownEmbeddedServer

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

        public static void clearSubContexts​(org.springframework.ldap.core.ContextSource contextSource,
                                            javax.naming.Name name)
                                     throws javax.naming.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:
        javax.naming.NamingException - if anything goes wrong removing the sub-tree.
      • clearSubContexts

        public static void clearSubContexts​(javax.naming.directory.DirContext ctx,
                                            javax.naming.Name name)
                                     throws javax.naming.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:
        javax.naming.NamingException - if anything goes wrong removing the sub-tree.
      • loadLdif

        public static void loadLdif​(org.springframework.ldap.core.ContextSource contextSource,
                                    org.springframework.core.io.Resource ldifFile)
                             throws java.io.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:
        java.io.IOException - if the Resource cannot be read.
      • cleanAndSetup

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

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