-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #1025 Signed-off-by: emanueltrandafir1993 <[email protected]>
- Loading branch information
1 parent
cc1a15f
commit 8ee70ea
Showing
4 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...support/src/test/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.springframework.ldap.test.unboundid; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
|
||
import org.junit.Test; | ||
|
||
public class EmbeddedLdapServerTest { | ||
|
||
@Test | ||
public void shouldStartAndCloseServer() throws Exception { | ||
int port = getFreePort(); | ||
assertFalse(isPortOpen(port)); | ||
|
||
EmbeddedLdapServer server = EmbeddedLdapServer.newEmbeddedServer("jayway", "dc=jayway,dc=se", port); | ||
assertTrue(isPortOpen(port)); | ||
|
||
server.close(); | ||
assertFalse(isPortOpen(port)); | ||
} | ||
|
||
@Test | ||
public void shouldStartAndAutoCloseServer() throws Exception { | ||
int port = getFreePort(); | ||
assertFalse(isPortOpen(port)); | ||
|
||
try (EmbeddedLdapServer ignored = EmbeddedLdapServer.newEmbeddedServer("jayway", "dc=jayway,dc=se", port)) { | ||
assertTrue(isPortOpen(port)); | ||
} | ||
assertFalse(isPortOpen(port)); | ||
} | ||
|
||
static boolean isPortOpen(int port) { | ||
try (Socket ignored = new Socket("localhost", port)) { | ||
return true; | ||
} | ||
catch (IOException e) { | ||
return false; | ||
} | ||
} | ||
|
||
static int getFreePort() throws IOException { | ||
try (ServerSocket serverSocket = new ServerSocket(0)) { | ||
return serverSocket.getLocalPort(); | ||
} | ||
} | ||
|
||
} |