From f71d31fda015bd87168aba51022daf0cbfa8b26b Mon Sep 17 00:00:00 2001
From: mmarie <mmarie@localhost>
Date: Wed, 29 Oct 2008 08:01:21 +0000
Subject: [PATCH] Fix the startServer method in TestCaseUtils.java to be able to set an alternat instance directory and to allow to not cleanup the test instance dir. Fix a test case (add --noPropertiesFile)

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java |   77 +++++++++++++++++++++++++++-----------
 1 files changed, 55 insertions(+), 22 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
index 3fedc9c..a41dd49 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -126,7 +126,17 @@
    */
   public static final String PROPERTY_CONFIG_CHANGE_FILE =
       "org.opends.server.ConfigChangeFile";
-  
+
+  /**
+   * The name of the system property that specifies if the test instance
+   * direcotry needs to be wiped out before starting the setup or not.
+   * This will let the caller the possibility to copy some files
+   * (ie extensions) inside the test instance directory before the server
+   * starts up.
+   */
+  public static final String PROPERTY_CLEANUP_REQUIRED =
+      "org.opends.server.CleanupDirectories";
+
   /**
    * The name of the system property that specifies the ldap port.
    * Set this property when running the server if you want to use a given
@@ -222,6 +232,11 @@
   private static int serverRestarts = 0;
 
   /**
+   * The config directory in the test environment.
+   */
+  private static File testConfigDir;
+
+  /**
    * Starts the Directory Server so that it will be available for use while
    * running the unit tests.  This will only actually start the server once, so
    * subsequent attempts to start it will be ignored because it will already be
@@ -248,31 +263,48 @@
 
       InvocationCounterPlugin.resetStartupCalled();
 
+      // Retrieves the location of a typical installation directory to use as a
+      // source to build our test instance.
+      String installedRoot = System.getProperty(PROPERTY_INSTALLED_ROOT);
+
       // Get the build root and use it to create a test package directory.
       String buildRoot = System.getProperty(PROPERTY_BUILD_ROOT);
       File   buildDir  = new File(buildRoot, "build");
       File   unitRoot  = new File(buildDir, "unit-tests");
-      File   testInstallRoot  =  new File(unitRoot, "package-install");
-      File   testInstanceRoot  = new File(unitRoot, "package-instance");
+      File   testInstallRoot  = null;
+      File   testInstanceRoot  = null;
+      if (installedRoot == null) {
+         testInstallRoot = new File(unitRoot, "package-install");
+         testInstanceRoot = new File(unitRoot, "package-instance");
+      } else {
+         testInstallRoot = new File(unitRoot, "package");
+         testInstanceRoot = testInstallRoot;
+      }
+
       File   testSrcRoot = new File(buildRoot + File.separator + "tests" +
                                     File.separator + "unit-tests-testng");
 
-      if (testInstallRoot.exists())
+      boolean cleanupRequired = true;
+      String cleanupRequiredString =
+              System.getProperty(PROPERTY_CLEANUP_REQUIRED, "true");
+      if (cleanupRequiredString.equalsIgnoreCase("false"))
       {
-        deleteDirectory(testInstallRoot);
+        cleanupRequired = false;
       }
-      if (testInstanceRoot.exists())
-      {
-        deleteDirectory(testInstanceRoot);
-      }
-      testInstallRoot.mkdirs();
-      testInstanceRoot.mkdirs();
 
-      // Retrieves the location of a typical installation directory to use as a
-      // source to build our test instance.
-      String installedRoot = System.getProperty(PROPERTY_INSTALLED_ROOT);
- 
-      
+      if (cleanupRequired) {
+        if (testInstallRoot.exists())
+        {
+          deleteDirectory(testInstallRoot);
+        }
+        if (testInstanceRoot.exists())
+        {
+          deleteDirectory(testInstanceRoot);
+        }
+        testInstallRoot.mkdirs();
+        testInstanceRoot.mkdirs();
+      }
+
       //db_verify is second jeb backend used by the jeb verify test cases
       //db_rebuild is the third jeb backend used by the jeb rebuild test cases
       //db_unindexed is the forth backend used by the unindexed search privilege
@@ -299,7 +331,8 @@
       File libDir           = new File(buildRoot, "lib");
       File resourceDir      = new File(buildRoot, "resource");
       File testResourceDir  = new File(testSrcRoot, "resource");
-      File testConfigDir    = new File(testInstanceRoot, "config");
+      // Set the class variable
+      testConfigDir    = new File(testInstanceRoot, "config");
       File testClassesDir   = new File(testInstanceRoot, "classes");
       File testLibDir       = new File(testInstallRoot, "lib");
       File testBinDir       = new File(testInstallRoot, "bin");
@@ -607,11 +640,11 @@
 
   private static File getTestConfigDir()
   {
-    String buildRoot = System.getProperty(PROPERTY_BUILD_ROOT);
-    File   buildDir  = new File(buildRoot, "build");
-    File   unitRoot  = new File(buildDir, "unit-tests");
-    File   testRoot  = new File(unitRoot, "package-instance");
-    return new File(testRoot, "config");
+    if (testConfigDir == null) {
+      throw new RuntimeException("The testConfigDir variable is not set yet!");
+    }
+    
+    return (testConfigDir);
   }
 
   public static File getBuildRoot()

--
Gitblit v1.10.0