From 438dc440046e3501a4098da9c9e38f1955f38198 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Tue, 2 Oct 2007 14:50:08 +0000 Subject: [PATCH] Minor changes to improve robustess of LDAP tests. --- .../config/LdapBeanDefinitionParserTests.java | 1 - .../ldap/AbstractLdapIntegrationTests.java | 24 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/org/springframework/security/config/LdapBeanDefinitionParserTests.java b/core/src/test/java/org/springframework/security/config/LdapBeanDefinitionParserTests.java index 06f761f770..128e5c3610 100644 --- a/core/src/test/java/org/springframework/security/config/LdapBeanDefinitionParserTests.java +++ b/core/src/test/java/org/springframework/security/config/LdapBeanDefinitionParserTests.java @@ -41,6 +41,5 @@ public class LdapBeanDefinitionParserTests { template.lookup("uid=ben,ou=people"); - } } diff --git a/core/src/test/java/org/springframework/security/ldap/AbstractLdapIntegrationTests.java b/core/src/test/java/org/springframework/security/ldap/AbstractLdapIntegrationTests.java index d8de681a56..1a3099a1e5 100644 --- a/core/src/test/java/org/springframework/security/ldap/AbstractLdapIntegrationTests.java +++ b/core/src/test/java/org/springframework/security/ldap/AbstractLdapIntegrationTests.java @@ -23,6 +23,7 @@ import org.junit.Before; import org.junit.AfterClass; import org.junit.After; import org.apache.directory.server.protocol.shared.store.LdifFileLoader; +import org.apache.directory.server.core.DirectoryService; import javax.naming.directory.DirContext; import javax.naming.Name; @@ -31,6 +32,7 @@ import javax.naming.NamingEnumeration; import javax.naming.Binding; import javax.naming.ContextNotEmptyException; import javax.naming.NameNotFoundException; +import java.util.Set; /** * Based on class borrowed from Spring Ldap project. @@ -46,15 +48,31 @@ public abstract class AbstractLdapIntegrationTests { } @BeforeClass - public static void loadContext() { + public static void loadContext() throws NamingException { + shutdownRunningServers(); appContext = new ClassPathXmlApplicationContext("/org/springframework/security/ldap/ldapIntegrationTestContext.xml"); + } @AfterClass - public static void closeContext() { - appContext.close(); + public static void closeContext() throws Exception { + if(appContext != null) { + appContext.close(); + } + shutdownRunningServers(); } + private static void shutdownRunningServers() throws NamingException { + DirectoryService ds = DirectoryService.getInstance(); + + if (ds.isStarted()) { + System.out.println("WARNING: Discovered running DirectoryService with configuration: " + ds.getConfiguration().getStartupConfiguration().toString()); + System.out.println("Shutting it down..."); + ds.shutdown(); + } + } + + @Before public void onSetUp() throws Exception { }