From 9db56eeb258c99afe8f1d67af66b57e7966811c7 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Tue, 19 Sep 2006 21:25:23 +0000
Subject: [PATCH] This adds the ability to exclude certain slow tests from running in the default test ant target, I have added a "slow" test group to testng. To use it, just put something like "@Test(groups = { "slow" })" before your test case method. 

---
 opends/ext/build-tools.jar                                    |    0 
 opends/build.xml                                              |   96 ++++++++++++++++++++----
 opends/build-tools/src/org/opends/build/tools/PrepTestNG.java |  135 +++++++++++++++++++++++++++++++++
 opends/ext/testng/testng.xml                                  |    1 
 4 files changed, 216 insertions(+), 16 deletions(-)

diff --git a/opends/build-tools/src/org/opends/build/tools/PrepTestNG.java b/opends/build-tools/src/org/opends/build/tools/PrepTestNG.java
new file mode 100644
index 0000000..6b33ada
--- /dev/null
+++ b/opends/build-tools/src/org/opends/build/tools/PrepTestNG.java
@@ -0,0 +1,135 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+
+package org.opends.build.tools;
+
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.io.BufferedReader;
+import java.io.FileReader;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+
+public class PrepTestNG extends Task
+{
+  private String file;
+  private String toFile;
+  private String groupList;
+
+  public void setFile(String file)
+  {
+    this.file = file;
+  }
+
+  public void setToFile(String toFile)
+  {
+    this.toFile = toFile;
+  }
+
+  public void setGroupList(String groupList)
+  {
+    this.groupList = groupList;
+  }
+
+  public void execute() throws BuildException
+  {
+    if(file == null)
+    {
+      throw new BuildException("Attribute file must be set to the orginal " +
+          "TestNG XML file");
+    }
+
+    if(toFile == null)
+    {
+      throw new BuildException("Attribute toFile must be set to the modified " +
+          "TestNG XML file");
+    }
+
+    BufferedReader reader;
+    FileOutputStream outFile;
+    PrintStream writer;
+    String line;
+    String[] groups;
+    String[] groupLine;
+    int replaced = 0;
+
+    try
+    {
+      reader = new BufferedReader(new FileReader(file));
+      outFile = new FileOutputStream(toFile);
+
+      writer = new PrintStream(outFile);
+
+      line = reader.readLine();
+
+      if(groupList != null && groupList.trim() != "")
+      {
+        groups = groupList.split(",");
+      }
+      else
+      {
+        groups = new String[0];
+      }
+
+      while(line != null)
+      {
+        if(line.indexOf("<!-- THIS WILL BE REPLACED WITH GROUP INFO BY " +
+            "ANT -->") >= 0)
+        {
+          if(groups.length > 0 && groupList.trim() != "")
+          {
+            writer.println("<groups>\n<run>");
+            for(String group : groups)
+            {
+              groupLine = group.split("=");
+              if(groupLine.length == 2)
+              {
+                writer.println("<"+groupLine[0]+" " +
+                               "name=\""+groupLine[1] + "\" />\n");
+                replaced++;
+              }
+            }
+            writer.println("</run>\n</groups>");
+          }
+        }
+        else
+        {
+          writer.println(line);
+        }
+
+        line = reader.readLine();
+      }
+
+      System.out.println("Adding " + replaced + " group tags to " + toFile);
+    }
+    catch(Exception e)
+    {
+      throw new BuildException("File Error: " + e.toString());
+    }
+  }
+}
diff --git a/opends/build.xml b/opends/build.xml
index 0b36a1a..32c3d61 100644
--- a/opends/build.xml
+++ b/opends/build.xml
@@ -34,17 +34,22 @@
 
 
 
-  <!-- General server-wide properties                              -->
-  <property name="src.dir"       location="src/server"              />
-  <property name="build.dir"     location="build"                   />
-  <property name="classes.dir"   location="${build.dir}/classes"    />
-  <property name="lib.dir"       location="lib"                     />
-  <property name="ext.dir"       location="ext"                     />
-  <property name="package.dir"   location="${build.dir}/package"    />
-  <property name="javadoc.dir"   location="${build.dir}/javadoc"    />
-  <property name="resource.dir"  location="resource"                />
-  <property name="scripts.dir"   location="${resource.dir}/bin"     />
-  <property name="config.dir"    location="${resource.dir}/config"  />
+  <!-- General server-wide properties                               -->
+  <property name="src.dir"        location="src/server"              />
+  <property name="build.dir"      location="build"                   />
+  <property name="classes.dir"    location="${build.dir}/classes"    />
+  <property name="lib.dir"        location="lib"                     />
+  <property name="ext.dir"        location="ext"                     />
+  <property name="package.dir"    location="${build.dir}/package"    />
+  <property name="javadoc.dir"    location="${build.dir}/javadoc"    />
+  <property name="resource.dir"   location="resource"                />
+  <property name="scripts.dir"    location="${resource.dir}/bin"     />
+  <property name="config.dir"     location="${resource.dir}/config"  />
+
+  <!-- Properties for build tools                                   -->  
+  <property name="buildtools.dir" location="build-tools"              />
+  <property name="buildtools.src.dir" location="${buildtools.dir}/src" />
+  <property name="buildtools.classes.dir" location="${buildtools.dir}/classes" />
 
   <!-- Properties for use in unit testing.                           -->
   <property name="unittest.testng.dir" location="tests/unit-tests-testng"/>
@@ -55,6 +60,8 @@
        location="${build.dir}/unit-tests/classes" />
   <property name="unittest.report.dir"
        location="${build.dir}/unit-tests/report"/>
+  <property name="unittest.resource.dir"
+       location="${build.dir}/unit-tests/resource"/>
 
   <!-- Properties for use in functional/integration testing.  -->
   <property name="functest.testng.dir"
@@ -84,6 +91,10 @@
   <property name="testng.dir" location="${ext.dir}/testng"          />
   <property name="testng.lib.dir" location="${testng.dir}/lib"      />
 
+  <!-- Properties for the ANT build tool.                          -->
+  <property name="ant.dir" location="${ext.dir}/ant"                />
+  <property name="ant.lib.dir" location="${ant.dir}/lib"            />
+
   <!-- Properties for the checkstyle tool.                         -->
   <property name="checkstyle.dir"  location="${ext.dir}/checkstyle" />
 
@@ -143,7 +154,9 @@
        description="Clean up any files generated during the build process">
 
     <delete dir="${build.dir}"           />
-    <delete file="${dynconstants.file}"  />
+    <delete file="${dynconstants.file}"  />                           <fileset dir="${lib.dir}">
+                <include name="*.jar" />
+              </fileset>
   </target>
 
 
@@ -575,6 +588,18 @@
         <path refid="run.classpath" />
       </classpath>
     </javac>
+ 
+    <!-- Prep the TestNG XML file -->
+    <mkdir dir="${unittest.resource.dir}" />
+    <typedef name="preptestng" classname="org.opends.build.tools.PrepTestNG"
+        classpath="${ext.dir}/build-tools.jar" />
+
+
+    <preptestng file="${testng.dir}/testng.xml"
+                tofile="${unittest.resource.dir}/testng.xml"
+                grouplist="${test.groups}" />
+
+
   </target>
 
 
@@ -587,14 +612,14 @@
 
   <!-- Execute all of the Directory Server TestNG unit tests in text mode. -->
   <target name="testall"
-          depends="enableTestNGAssertions,test"
+          depends="enableTestNGAssertions,testinit,runtests"
           description="Run all of the TestNG tests.">
   </target>
 
 
   <!-- Execute the Directory Server TestNG unit tests in text mode. -->
   <target name="test"
-          depends="testinit,runtests"
+          depends="prepdefaulttest,testinit,runtests"
           description="Execute the Directory Server TestNG unit tests in text mode.">
   </target>
 
@@ -604,6 +629,12 @@
           description="Execute the Directory Server TestNG unit tests in text mode with a coverage report.">
   </target>
 
+  <!-- Execute the Directory Server TestNG unit tests in text mode with a coverage report and slow tests. -->
+  <target name="testallwithcoverage"
+          depends="coverage,testall"
+          description="Execute the Directory Server TestNG unit tests in text mode with a coverage report.">
+  </target>
+
   <!-- Internal target to execute the Directory Server TestNG unit tests in text mode after everything has been initialized. -->
   <target name="runtests">
     <mkdir dir="${unittest.report.dir}" />
@@ -644,7 +675,7 @@
       <jvmarg  value="-Demma.coverage.out.file=${coverage.data.dir}/coverage.emma" />
       <jvmarg value="-Demma.coverage.out.merge=false" />
       <jvmarg value="-Dorg.opends.server.BuildRoot=${basedir}" />
-      <xmlfileset dir="${testng.dir}" includes="testng.xml" />
+      <xmlfileset dir="${unittest.resource.dir}" includes="testng.xml" />
     </testng>
 
     <emma enabled="${coverage.enabled}" >
@@ -661,7 +692,10 @@
 
   </target>
 
-
+  <!-- Internal target used to set the group list property for the preptestng task -->
+  <target name="prepdefaulttest">
+    <property name="test.groups" value="exclude=slow" />
+  </target>
 
   <target name="testreport"
         depends="test"
@@ -680,6 +714,36 @@
         description="Builds the integration tests">
         <ant dir="${functest.testng.dir}" />
     </target>
+
+  <target name="buildtools"
+        description="Builds the build tools">
+
+    <!-- Set the amount of memory to use for the build -->
+    <condition property="MEM" value="128M">
+      <not>
+        <isset property="MEM" />
+      </not>
+    </condition>
+
+    <mkdir dir="${buildtools.classes.dir}" />
+
+    <javac srcdir="${buildtools.src.dir}" destdir="${buildtools.classes.dir}"
+           optimize="true" debug="on" debuglevel="lines,source" source="1.5"
+           target="1.5" deprecation="true" fork="true" memoryInitialSize="${MEM}"
+           memoryMaximumSize="${MEM}">
+      <compilerarg value="-Xlint:all" />
+
+      <classpath>
+        <fileset dir="${ant.lib.dir}">
+          <include name="*.jar" />
+        </fileset>
+        <path refid="run.classpath" />
+      </classpath>
+    </javac>
+
+    <jar jarfile="${ext.dir}/build-tools.jar"
+         basedir="${buildtools.classes.dir}" compress="true" index="true" />
+  </target>
         
 </project>
 
diff --git a/opends/ext/build-tools.jar b/opends/ext/build-tools.jar
new file mode 100644
index 0000000..31f2da3
--- /dev/null
+++ b/opends/ext/build-tools.jar
Binary files differ
diff --git a/opends/ext/testng/testng.xml b/opends/ext/testng/testng.xml
index 4da6bb2..0f85089 100644
--- a/opends/ext/testng/testng.xml
+++ b/opends/ext/testng/testng.xml
@@ -1,6 +1,7 @@
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 <suite name="OpenDS"   verbose="1" >
     <test name="default">
+        <!-- THIS WILL BE REPLACED WITH GROUP INFO BY ANT -->
         <packages>
             <package name="org.opends.server.protocols.asn1"/>
             <package name="org.opends.server.protocols.internal"/>

--
Gitblit v1.10.0