Skip to content

Commit d1b571a

Browse files
committed
Add start/stop methods
Closes #1025 Signed-off-by: Emanuel Trandafir <emanueltrandafir1993@gmail.com>
1 parent cc1a15f commit d1b571a

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServer.java

+36-3
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,25 @@
2121
import com.unboundid.ldap.listener.InMemoryListenerConfig;
2222
import com.unboundid.ldap.sdk.DN;
2323
import com.unboundid.ldap.sdk.Entry;
24+
import com.unboundid.ldap.sdk.LDAPException;
2425

2526
/**
2627
* Helper class for embedded Unboundid ldap server.
2728
*
2829
* @author Eddu Melendez
2930
* @since 2.1.0
3031
*/
31-
public final class EmbeddedLdapServer {
32+
public final class EmbeddedLdapServer implements AutoCloseable {
3233

33-
private InMemoryDirectoryServer directoryServer;
34+
private final InMemoryDirectoryServer directoryServer;
3435

3536
private EmbeddedLdapServer(InMemoryDirectoryServer directoryServer) {
3637
this.directoryServer = directoryServer;
3738
}
3839

40+
/**
41+
* Creates and starts new embedded LDAP server.
42+
*/
3943
public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName, String defaultPartitionSuffix,
4044
int port) throws Exception {
4145
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(defaultPartitionSuffix);
@@ -56,7 +60,36 @@ public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName,
5660
return new EmbeddedLdapServer(directoryServer);
5761
}
5862

59-
public void shutdown() throws Exception {
63+
/**
64+
* Starts the embedded LDAP server.
65+
*
66+
* @since 3.3
67+
*/
68+
public void start() {
69+
try {
70+
this.directoryServer.startListening();
71+
}
72+
catch (LDAPException ex) {
73+
throw new RuntimeException(ex);
74+
}
75+
}
76+
77+
/**
78+
* Closes the embedded LDAP server and releases resource, closing existing
79+
* connections.
80+
*
81+
* @since 3.3
82+
*/
83+
@Override
84+
public void close() {
85+
this.directoryServer.shutDown(true);
86+
}
87+
88+
/**
89+
* @deprecated Use {@link #close()} instead.
90+
*/
91+
@Deprecated(since = "3.3")
92+
public void shutdown() {
6093
this.directoryServer.shutDown(true);
6194
}
6295

test-support/src/main/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServerFactoryBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected EmbeddedLdapServer createInstance() throws Exception {
5353

5454
@Override
5555
protected void destroyInstance(EmbeddedLdapServer instance) throws Exception {
56-
instance.shutdown();
56+
instance.close();
5757
}
5858

5959
}

test-support/src/main/java/org/springframework/ldap/test/unboundid/LdapTestUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static void startEmbeddedServer(int port, String defaultPartitionSuffix,
9292
*/
9393
public static void shutdownEmbeddedServer() throws Exception {
9494
if (embeddedServer != null) {
95-
embeddedServer.shutdown();
95+
embeddedServer.close();
9696
embeddedServer = null;
9797
}
9898
}

0 commit comments

Comments
 (0)