|
20 | 20 | import java.net.ServerSocket;
|
21 | 21 | import java.net.Socket;
|
22 | 22 |
|
| 23 | +import com.unboundid.ldap.listener.InMemoryDirectoryServer; |
| 24 | +import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig; |
| 25 | +import com.unboundid.ldap.listener.InMemoryListenerConfig; |
23 | 26 | import org.junit.Test;
|
24 | 27 |
|
25 | 28 | import static org.assertj.core.api.Assertions.assertThat;
|
| 29 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
26 | 30 |
|
27 | 31 | public class EmbeddedLdapServerTests {
|
28 | 32 |
|
@@ -61,6 +65,38 @@ public void shouldStartAndCloseServerViaLdapTestUtils() throws Exception {
|
61 | 65 | assertThat(isPortOpen(port)).isFalse();
|
62 | 66 | }
|
63 | 67 |
|
| 68 | + @Test |
| 69 | + public void startWhenNewEmbeddedServerThenException() throws Exception { |
| 70 | + int port = getFreePort(); |
| 71 | + EmbeddedLdapServer server = EmbeddedLdapServer.newEmbeddedServer("jayway", "dc=jayway,dc=se", port); |
| 72 | + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(server::start); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void startWhenUnstartedThenWorks() throws Exception { |
| 77 | + int port = getFreePort(); |
| 78 | + InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=jayway,dc=se"); |
| 79 | + config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", port)); |
| 80 | + InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config); |
| 81 | + try (EmbeddedLdapServer server = new EmbeddedLdapServer(ds)) { |
| 82 | + server.start(); |
| 83 | + assertThat(isPortOpen(port)).isTrue(); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + public void startWhenAlreadyStartedThenFails() throws Exception { |
| 89 | + int port = getFreePort(); |
| 90 | + InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=jayway,dc=se"); |
| 91 | + config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", port)); |
| 92 | + InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config); |
| 93 | + try (EmbeddedLdapServer server = new EmbeddedLdapServer(ds)) { |
| 94 | + server.start(); |
| 95 | + assertThat(isPortOpen(port)).isTrue(); |
| 96 | + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(server::start); |
| 97 | + } |
| 98 | + } |
| 99 | + |
64 | 100 | static boolean isPortOpen(int port) {
|
65 | 101 | try (Socket ignored = new Socket("localhost", port)) {
|
66 | 102 | return true;
|
|
0 commit comments