| | |
| | | import java.io.IOException; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.ServerSocket; |
| | | import java.net.SocketAddress; |
| | | |
| | | /** |
| | | * This class defines some utility functions which can be used by test cases. |
| | |
| | | } |
| | | |
| | | /** |
| | | * Finds a free server socket port on the local host. |
| | | * |
| | | * @return The free port. |
| | | */ |
| | | public static SocketAddress findFreeSocketAddress() { |
| | | try { |
| | | ServerSocket serverLdapSocket = new ServerSocket(); |
| | | serverLdapSocket.setReuseAddress(true); |
| | | serverLdapSocket.bind(new InetSocketAddress("127.0.0.1", 0)); |
| | | final SocketAddress address = serverLdapSocket.getLocalSocketAddress(); |
| | | serverLdapSocket.close(); |
| | | return address; |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns an internal client connection to the running ldap server. |
| | | * |
| | | * @return The internal client connection. |