From d2276fb43a3d15409a8a0c55246f81bd0080a55e Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 07 Sep 2006 19:25:31 +0000
Subject: [PATCH] Update the TestCaseUtils.startServer() method to build the appropriate server root environment there rather than in the ant script.  This will make it easier to run the tests in an IDE rather than from the command line.

---
 opendj-sdk/opends/build.xml                                                               |   58 +-----------------
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java |   67 +++++++++++++++++-----
 2 files changed, 57 insertions(+), 68 deletions(-)

diff --git a/opendj-sdk/opends/build.xml b/opendj-sdk/opends/build.xml
index e867500..4c345df 100644
--- a/opendj-sdk/opends/build.xml
+++ b/opendj-sdk/opends/build.xml
@@ -53,8 +53,6 @@
 
   <property name="unittest.classes.dir"
        location="${build.dir}/unit-tests/classes" />
-  <property name="unittest.package.dir"
-       location="${build.dir}/unit-tests/package" />
   <property name="unittest.report.dir"
        location="${build.dir}/unit-tests/report"/>
 
@@ -579,54 +577,9 @@
 
 
 
-  <!-- Create a minimal install suitable for running unit tests. -->
-  <target name="testpackage" depends="testinit">
-    <mkdir dir="${unittest.package.dir}"                 />
-    <mkdir dir="${unittest.package.dir}/bak"             />
-    <mkdir dir="${unittest.package.dir}/classes"         />
-    <mkdir dir="${unittest.package.dir}/config"          />
-    <mkdir dir="${unittest.package.dir}/config/schema"   />
-    <mkdir dir="${unittest.package.dir}/config/messages" />
-    <mkdir dir="${unittest.package.dir}/config/MakeLDIF" />
-    <mkdir dir="${unittest.package.dir}/db"              />
-    <mkdir dir="${unittest.package.dir}/changelogDb"     />
-    <mkdir dir="${unittest.package.dir}/ldif"            />
-    <mkdir dir="${unittest.package.dir}/lib"             />
-    <mkdir dir="${unittest.package.dir}/locks"           />
-    <mkdir dir="${unittest.package.dir}/logs"            />
-
-    <jar jarfile="${unittest.package.dir}/lib/OpenDS.jar"
-         basedir="${classes.dir}" compress="true" index="true" />
-
-    <jar jarfile="${unittest.package.dir}/lib/OpenDS-tests.jar"
-         basedir="${unittest.classes.dir}" compress="true" index="true" />
-
-    <copy todir="${unittest.package.dir}/lib">
-      <fileset file="${lib.dir}/*.jar" />
-    </copy>
-
-    <copy todir="${unittest.package.dir}/config">
-      <fileset file="${config.dir}/*" />
-    </copy>
-
-    <copy todir="${unittest.package.dir}/config/schema">
-      <fileset dir="${resource.dir}/schema" />
-    </copy>
-
-    <copy todir="${unittest.package.dir}/config/messages">
-      <fileset dir="${resource.dir}/messages" />
-    </copy>
-
-    <copy todir="${unittest.package.dir}/config/MakeLDIF">
-      <fileset dir="${resource.dir}/MakeLDIF" />
-    </copy>
-  </target>
-
-
-
   <!-- Execute the Directory Server TestNG unit tests in text mode. -->
   <target name="test"
-          depends="testinit,testpackage,runtests"
+          depends="testinit,runtests"
           description="Execute the Directory Server TestNG unit tests in text mode.">
   </target>
 
@@ -652,11 +605,13 @@
             enableAssert="false">
       <classpath>
         <pathelement location="${coverage.instr.dir}" />
+        <pathelement location="${classes.dir}" />
+        <pathelement location="${unittest.classes.dir}" />
 
         <path refid="run.classpath" />
         <path refid="emma.lib" />
 
-        <fileset dir="${unittest.package.dir}/lib">
+        <fileset dir="${lib.dir}">
           <include name="*.jar" />
         </fileset>
 
@@ -666,10 +621,7 @@
       </classpath>
       <jvmarg  value="-Demma.coverage.out.file=${coverage.data.dir}/coverage.emma" />
       <jvmarg value="-Demma.coverage.out.merge=false" />
-      <jvmarg value="-Dorg.opends.server.ForceDaemonThreads=true" />
-      <jvmarg value="-Dorg.opends.server.ServerRoot=${unittest.package.dir}" />
-      <jvmarg value="-Dorg.opends.server.ConfigClass=org.opends.server.config.ConfigFileHandler" />
-      <jvmarg value="-Dorg.opends.server.ConfigFile=${unittest.package.dir}/config/config.ldif" />
+      <jvmarg value="-Dorg.opends.server.BuildRoot=${basedir}" />
       <xmlfileset dir="${testng.dir}" includes="testng.xml" />
     </testng>
 
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
index 104a0ab..e71b669 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -34,29 +34,24 @@
 import java.io.OutputStream;
 
 import org.opends.server.config.ConfigException;
+import org.opends.server.config.ConfigFileHandler;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.InitializationException;
 import org.opends.server.loggers.Error;
 import org.opends.server.loggers.Debug;
 
+import static org.opends.server.util.ServerConstants.*;
+
 /**
  * This class defines some utility functions which can be used by test
  * cases.
  */
 public final class TestCaseUtils {
   /**
-   * The name of the system property that can be used to set the fully-qualified
-   * name of the Java class to use as the config handler.
+   * The name of the system property that specifies the server build root.
    */
-  public static final String PROPERTY_CONFIG_CLASS =
-       "org.opends.server.ConfigClass";
-
-  /**
-   * The name of the system property that can be used to set the path to the
-   * Directory Server configuration file.
-   */
-  public static final String PROPERTY_CONFIG_FILE =
-       "org.opends.server.ConfigFile";
+  public static final String PROPERTY_BUILD_ROOT =
+       "org.opends.server.BuildRoot";
 
   /**
    * Indicates whether the server has already been started.
@@ -69,6 +64,9 @@
    * subsequent attempts to start it will be ignored because it will already be
    * available.
    *
+   * @throws  IOException  If a problem occurs while interacting with the
+   *                       filesystem to prepare the test package root.
+   *
    * @throws  InitializationException  If a problem occurs while starting the
    *                                   server.
    *
@@ -76,15 +74,54 @@
    *                           configuration.
    */
   public static void startServer()
-         throws InitializationException, ConfigException
+         throws IOException, InitializationException, ConfigException
   {
     if (serverStarted)
     {
       return;
     }
 
-    String configClass = System.getProperty(PROPERTY_CONFIG_CLASS);
-    String configFile  = System.getProperty(PROPERTY_CONFIG_FILE);
+    // Get the build root and use it to create a test package directory.
+    String buildRoot = System.getProperty(PROPERTY_BUILD_ROOT);
+    File   testRoot  = new File(buildRoot + File.separator + "build" +
+                                File.separator + "unit-tests" + File.separator +
+                                "package");
+
+    if (testRoot.exists())
+    {
+      deleteDirectory(testRoot);
+    }
+    testRoot.mkdirs();
+
+    String[] subDirectories = { "bak", "changelogDb", "classes", "config", "db",
+                                "ldif", "lib", "locks", "logs" };
+    for (String s : subDirectories)
+    {
+      new File(testRoot, s).mkdir();
+    }
+
+
+    // Copy the configuration, schema, and MakeLDIF resources into the
+    // appropriate place under the test package.
+    File resourceDir   = new File(buildRoot, "resource");
+    File testConfigDir = new File(testRoot, "config");
+
+    copyDirectory(new File(resourceDir, "config"), testConfigDir);
+    copyDirectory(new File(resourceDir, "schema"),
+                  new File(testConfigDir, "schema"));
+    copyDirectory(new File(resourceDir, "MakeLDIF"),
+                  new File(testConfigDir, "MakeLDIF"));
+    // FIXME -- Copy the config-changes.ldif file into place when we have one.
+
+
+    // Actually start the server and set a variable that will prevent us from
+    // needing to do it again.
+    System.setProperty(PROPERTY_SERVER_ROOT, testRoot.getAbsolutePath());
+    System.setProperty(PROPERTY_FORCE_DAEMON_THREADS, "true");
+
+    String configClass = ConfigFileHandler.class.getName();
+    String configFile  = testConfigDir.getAbsolutePath() + File.separator +
+                         "config.ldif";
 
     DirectoryServer directoryServer = DirectoryServer.getInstance();
     directoryServer.bootstrapServer();
@@ -135,7 +172,7 @@
     if (src.isDirectory()) {
       // Create the destination directory if it does not exist.
       if (!dst.exists()) {
-        dst.mkdir();
+        dst.mkdirs();
       }
 
       // Recursively copy sub-directories and files.

--
Gitblit v1.10.0