From 069f78c00bfdb01467c6ed9ae602c195c61c4437 Mon Sep 17 00:00:00 2001
From: Luke Taylor <luke.taylor@springsource.com>
Date: Mon, 19 Dec 2005 17:01:25 +0000
Subject: [PATCH] Move the apacheDS working directory to java.io.tmpdir

---
 .../providers/ldap/LdapTestServer.java        | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/core/src/test/java/org/acegisecurity/providers/ldap/LdapTestServer.java b/core/src/test/java/org/acegisecurity/providers/ldap/LdapTestServer.java
index 00152ccfc6..01cc0435ed 100644
--- a/core/src/test/java/org/acegisecurity/providers/ldap/LdapTestServer.java
+++ b/core/src/test/java/org/acegisecurity/providers/ldap/LdapTestServer.java
@@ -35,8 +35,13 @@ import javax.naming.directory.DirContext;
 import java.util.Properties;
 import java.util.Set;
 import java.util.HashSet;
+import java.io.File;
+import java.io.IOException;
 
 /**
+ * An embedded LDAP test server, complete with test data for running the
+ * unit tests against.
+ *
  * @author Luke Taylor
  * @version $Id$
  */
@@ -48,6 +53,11 @@ public class LdapTestServer {
 
     private StartupConfiguration cfg;
 
+    // Move the working dir to the temp directory
+    private File workingDir = new File( System.getProperty("java.io.tmpdir")
+            + File.separator + "apacheds-work" );
+
+
     //~ Constructors ================================================================
 
     /**
@@ -66,12 +76,17 @@ public class LdapTestServer {
 
 
     private void startLdapServer(boolean embedded) {
+
         if(embedded) {
             cfg = new MutableStartupConfiguration();
+            ((MutableStartupConfiguration)cfg).setWorkingDirectory(workingDir);
         } else {
             cfg = new MutableServerStartupConfiguration();
+            ((MutableServerStartupConfiguration)cfg).setWorkingDirectory(workingDir);
         }
 
+        System.out.println("Working directory is " + workingDir.getAbsolutePath());
+
         initConfiguration();
 
         Properties env = new Properties();
@@ -82,7 +97,6 @@ public class LdapTestServer {
         env.putAll( cfg.toJndiEnvironment() );
 
         try {
-            // TODO: Remove all children on startup
             serverContext = new InitialDirContext( env );
         } catch (NamingException e) {
             System.err.println("Failed to start Apache DS");
@@ -182,7 +196,7 @@ public class LdapTestServer {
         try {
             serverContext.createSubcontext( "cn="+cn+",ou=groups", group );
         } catch(NameAlreadyBoundException ignore) {
-            System.out.println(" group " + cn + " already exists.");
+//            System.out.println(" group " + cn + " already exists.");
         } catch (NamingException ne) {
             System.err.println("Failed to create group.");
             ne.printStackTrace();
@@ -190,6 +204,8 @@ public class LdapTestServer {
     }
 
     private void initConfiguration() {
+
+        // Create the partition for the acegi tests
         MutableDirectoryPartitionConfiguration acegiDit = new MutableDirectoryPartitionConfiguration();
         acegiDit.setName("acegisecurity");
         acegiDit.setSuffix("dc=acegisecurity,dc=org");