Package org.springframework.ldap.test
Class LdapTestUtils
- java.lang.Object
-
- org.springframework.ldap.test.LdapTestUtils
-
public final class LdapTestUtils extends java.lang.ObjectUtilities 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 Deprecated Methods Modifier and Type Method Description static voidcleanAndSetup(ContextSource contextSource, javax.naming.Name rootNode, org.springframework.core.io.Resource ldifFile)static voidclearSubContexts(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 voidclearSubContexts(ContextSource contextSource, javax.naming.Name name)Clear the directory sub-tree starting with the node represented by the supplied distinguished name.static voiddestroyApacheDirectoryServer(java.lang.String principal, java.lang.String credentials)Deprecated.useshutdownEmbeddedServer()instead.static voidloadLdif(org.apache.directory.server.core.DefaultDirectoryService directoryService, org.springframework.core.io.Resource ldifFile)static voidloadLdif(ContextSource contextSource, org.springframework.core.io.Resource ldifFile)Load an Ldif file into an LDAP server.static voidshutdownEmbeddedServer()Shuts down the embedded server, if there is one.static javax.naming.directory.DirContextstartApacheDirectoryServer(int port, java.lang.String defaultPartitionSuffix, java.lang.String defaultPartitionName, java.lang.String principal, java.lang.String credentials)Deprecated.usestartEmbeddedServer(int, String, String)instead.static javax.naming.directory.DirContextstartApacheDirectoryServer(int port, java.lang.String defaultPartitionSuffix, java.lang.String defaultPartitionName, java.lang.String principal, java.lang.String credentials, java.util.Set extraSchemas)Deprecated.usestartEmbeddedServer(int, String, String)instead.static voidstartEmbeddedServer(int port, java.lang.String defaultPartitionSuffix, java.lang.String defaultPartitionName)Start an embedded Apache Directory Server.
-
-
-
Method Detail
-
startApacheDirectoryServer
public static javax.naming.directory.DirContext startApacheDirectoryServer(int port, java.lang.String defaultPartitionSuffix, java.lang.String defaultPartitionName, java.lang.String principal, java.lang.String credentials, java.util.Set extraSchemas) throws javax.naming.NamingExceptionDeprecated.usestartEmbeddedServer(int, String, String)instead.Start an in-process Apache Directory Server.- 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.principal- The principal to use when starting the directory server.credentials- The credentials to use when starting the directory server.extraSchemas- Set of extra schemas to add to the bootstrap schemas of ApacheDS. May benull.- Returns:
- An unusable DirContext instance.
- Throws:
javax.naming.NamingException- If anything goes wrong when starting the server.
-
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.- Since:
- 1.3.2
-
startApacheDirectoryServer
public static javax.naming.directory.DirContext startApacheDirectoryServer(int port, java.lang.String defaultPartitionSuffix, java.lang.String defaultPartitionName, java.lang.String principal, java.lang.String credentials) throws javax.naming.NamingExceptionDeprecated.usestartEmbeddedServer(int, String, String)instead.- Throws:
javax.naming.NamingException
-
shutdownEmbeddedServer
public static void shutdownEmbeddedServer() throws java.lang.ExceptionShuts 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- Since:
- 1.3.2
-
destroyApacheDirectoryServer
public static void destroyApacheDirectoryServer(java.lang.String principal, java.lang.String credentials) throws java.lang.ExceptionDeprecated.useshutdownEmbeddedServer()instead.Shut down the in-process Apache Directory Server.- Parameters:
principal- the principal to be used for authentication.credentials- the credentials to be used for authentication.- Throws:
java.lang.Exception- If anything goes wrong when shutting down the server.
-
clearSubContexts
public static void clearSubContexts(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.NamingExceptionClear 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(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(ContextSource contextSource, javax.naming.Name rootNode, org.springframework.core.io.Resource ldifFile) throws javax.naming.NamingException, java.io.IOException
- Throws:
javax.naming.NamingExceptionjava.io.IOException
-
loadLdif
public static void loadLdif(org.apache.directory.server.core.DefaultDirectoryService directoryService, org.springframework.core.io.Resource ldifFile) throws java.io.IOException- Throws:
java.io.IOException
-
-