21
21
import com .unboundid .ldap .listener .InMemoryListenerConfig ;
22
22
import com .unboundid .ldap .sdk .DN ;
23
23
import com .unboundid .ldap .sdk .Entry ;
24
+ import com .unboundid .ldap .sdk .LDAPException ;
24
25
25
26
/**
26
27
* Helper class for embedded Unboundid ldap server.
27
28
*
28
29
* @author Eddu Melendez
29
30
* @since 2.1.0
30
31
*/
31
- public final class EmbeddedLdapServer {
32
+ public final class EmbeddedLdapServer implements AutoCloseable {
32
33
33
- private InMemoryDirectoryServer directoryServer ;
34
+ private final InMemoryDirectoryServer directoryServer ;
34
35
35
36
private EmbeddedLdapServer (InMemoryDirectoryServer directoryServer ) {
36
37
this .directoryServer = directoryServer ;
37
38
}
38
39
40
+ /**
41
+ * Creates and starts new embedded LDAP server.
42
+ */
39
43
public static EmbeddedLdapServer newEmbeddedServer (String defaultPartitionName , String defaultPartitionSuffix ,
40
44
int port ) throws Exception {
41
45
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig (defaultPartitionSuffix );
@@ -56,7 +60,36 @@ public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName,
56
60
return new EmbeddedLdapServer (directoryServer );
57
61
}
58
62
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 () {
60
93
this .directoryServer .shutDown (true );
61
94
}
62
95
0 commit comments