Package org.springframework.ldap.test
Class LdapTestUtils
java.lang.Object
org.springframework.ldap.test.LdapTestUtils
Utilities for starting, stopping and populating an in-process Apache Directory Server
 to use for integration testing purposes.
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidcleanAndSetup(ContextSource contextSource, Name rootNode, org.springframework.core.io.Resource ldifFile) static voidclearSubContexts(DirContext ctx, Name name) Clear the directory sub-tree starting with the node represented by the supplied distinguished name.static voidclearSubContexts(ContextSource contextSource, Name name) Clear the directory sub-tree starting with the node represented by the supplied distinguished name.static voiddestroyApacheDirectoryServer(String principal, String credentials) Deprecated.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 voidShuts down the embedded server, if there is one.static DirContextstartApacheDirectoryServer(int port, String defaultPartitionSuffix, String defaultPartitionName, String principal, String credentials) Deprecated.usestartEmbeddedServer(int, String, String)instead.static DirContextstartApacheDirectoryServer(int port, String defaultPartitionSuffix, String defaultPartitionName, String principal, String credentials, Set extraSchemas) Deprecated.usestartEmbeddedServer(int, String, String)instead.static voidstartEmbeddedServer(int port, String defaultPartitionSuffix, String defaultPartitionName) Start an embedded Apache Directory Server.
- 
Method Details- 
startApacheDirectoryServerpublic static DirContext startApacheDirectoryServer(int port, String defaultPartitionSuffix, String defaultPartitionName, String principal, String credentials, Set extraSchemas) throws NamingException Deprecated.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 be- null.
- Returns:
- An unusable DirContext instance.
- Throws:
- NamingException- If anything goes wrong when starting the server.
 
- 
startEmbeddedServerpublic 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.
- Since:
- 1.3.2
 
- 
startApacheDirectoryServerpublic static DirContext startApacheDirectoryServer(int port, String defaultPartitionSuffix, String defaultPartitionName, String principal, String credentials) throws NamingException Deprecated.usestartEmbeddedServer(int, String, String)instead.- Throws:
- NamingException
 
- 
shutdownEmbeddedServerShuts down the embedded server, if there is one. If no server was previously started in this JVM this is silently ignored.- Throws:
- Exception
- Since:
- 1.3.2
 
- 
destroyApacheDirectoryServerpublic static void destroyApacheDirectoryServer(String principal, String credentials) throws Exception Deprecated.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:
- Exception- If anything goes wrong when shutting down the server.
 
- 
clearSubContextsClear 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.
 
- 
clearSubContextsClear 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.
 
- 
loadLdifpublic 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.
 
- 
cleanAndSetuppublic static void cleanAndSetup(ContextSource contextSource, Name rootNode, org.springframework.core.io.Resource ldifFile) throws NamingException, IOException - Throws:
- NamingException
- IOException
 
- 
loadLdifpublic static void loadLdif(org.apache.directory.server.core.DefaultDirectoryService directoryService, org.springframework.core.io.Resource ldifFile) throws IOException - Throws:
- IOException
 
 
- 
shutdownEmbeddedServer()instead.