From fa6218cf735a15223b2c6abe144c5e0dfc1ac2c5 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Tue, 15 Apr 2014 11:52:09 -0500 Subject: [PATCH] SEC-2558: Fix failing ApacheDSContainerTests when port is taken --- .../ldap/server/ApacheDSContainerTests.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ldap/src/integration-test/java/org/springframework/security/ldap/server/ApacheDSContainerTests.java b/ldap/src/integration-test/java/org/springframework/security/ldap/server/ApacheDSContainerTests.java index b653d533de..a3a8fa08dc 100644 --- a/ldap/src/integration-test/java/org/springframework/security/ldap/server/ApacheDSContainerTests.java +++ b/ldap/src/integration-test/java/org/springframework/security/ldap/server/ApacheDSContainerTests.java @@ -17,6 +17,11 @@ package org.springframework.security.ldap.server; import static junit.framework.Assert.fail; +import java.io.IOException; +import java.net.ServerSocket; +import java.util.ArrayList; +import java.util.List; + import org.junit.Test; /** @@ -32,7 +37,10 @@ public class ApacheDSContainerTests { @Test public void failsToStartThrowsException() throws Exception { ApacheDSContainer server1 = new ApacheDSContainer("dc=springframework,dc=org", "classpath:test-server.ldif"); - ApacheDSContainer server2 = new ApacheDSContainer("dc=springframework,dc=org", "classpath:test-server.ldif"); + ApacheDSContainer server2 = new ApacheDSContainer("dc=springframework,dc=org", "classpath:missing.ldif"); + List ports = getDefaultPorts(1); + server1.setPort(ports.get(0)); + server2.setPort(ports.get(0)); try { server1.afterPropertiesSet(); try { @@ -54,6 +62,9 @@ public class ApacheDSContainerTests { public void multipleInstancesSimultanciously() throws Exception { ApacheDSContainer server1 = new ApacheDSContainer("dc=springframework,dc=org", "classpath:test-server.ldif"); ApacheDSContainer server2 = new ApacheDSContainer("dc=springframework,dc=org", "classpath:test-server.ldif"); + List ports = getDefaultPorts(2); + server1.setPort(ports.get(0)); + server2.setPort(ports.get(1)); try { server1.afterPropertiesSet(); server2.afterPropertiesSet(); @@ -66,4 +77,21 @@ public class ApacheDSContainerTests { }catch(Throwable t) {} } } + + private List getDefaultPorts(int count) throws IOException { + List connections = new ArrayList(); + List availablePorts = new ArrayList(count); + try { + for(int i=0;i