diff --git a/test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServer.java b/test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServer.java index 81e5a01c..4436125f 100644 --- a/test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServer.java +++ b/test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServer.java @@ -21,6 +21,7 @@ import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig; import com.unboundid.ldap.listener.InMemoryListenerConfig; import com.unboundid.ldap.sdk.DN; import com.unboundid.ldap.sdk.Entry; +import com.unboundid.ldap.sdk.LDAPException; /** * Helper class for embedded Unboundid ldap server. @@ -28,14 +29,17 @@ import com.unboundid.ldap.sdk.Entry; * @author Eddu Melendez * @since 2.1.0 */ -public final class EmbeddedLdapServer { +public final class EmbeddedLdapServer implements AutoCloseable { - private InMemoryDirectoryServer directoryServer; + private final InMemoryDirectoryServer directoryServer; private EmbeddedLdapServer(InMemoryDirectoryServer directoryServer) { this.directoryServer = directoryServer; } + /** + * Creates and starts new embedded LDAP server. + */ public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName, String defaultPartitionSuffix, int port) throws Exception { InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(defaultPartitionSuffix); @@ -56,7 +60,36 @@ public final class EmbeddedLdapServer { return new EmbeddedLdapServer(directoryServer); } - public void shutdown() throws Exception { + /** + * Starts the embedded LDAP server. + * + * @since 3.3 + */ + public void start() { + try { + this.directoryServer.startListening(); + } + catch (LDAPException ex) { + throw new RuntimeException(ex); + } + } + + /** + * Closes the embedded LDAP server and releases resource, closing existing + * connections. + * + * @since 3.3 + */ + @Override + public void close() { + this.directoryServer.shutDown(true); + } + + /** + * @deprecated Use {@link #close()} instead. + */ + @Deprecated(since = "3.3") + public void shutdown() { this.directoryServer.shutDown(true); } diff --git a/test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServerFactoryBean.java b/test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServerFactoryBean.java index b5f24404..360a6867 100644 --- a/test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServerFactoryBean.java +++ b/test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServerFactoryBean.java @@ -53,7 +53,7 @@ public class EmbeddedLdapServerFactoryBean extends AbstractFactoryBean