mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

boli
19.25.2006 9db56eeb258c99afe8f1d67af66b57e7966811c7
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.

This is implemented by a modified testng.xml file which is modified by a
custom ant task called preptestng. It basically takes a
group include/exclude string like "exclude=slow,include=fast" from ant
and insert the correct tags into a copy of the testng.xml file.

A new resource directory is now created before running tests to hold the
modified testng.xml. it is located at build/unit-tests/resource. The
preptestng task will copy the master testng.xml file from
ext/testng/testng.xml to the new resource directory and add the
appropreate group tags based on parameters from ant.

This also creates a build-tools top level directory to hold this tool and any future build tools. A new ant target called "buildtools" is also added to rebuild the tools and make the build-tools.jar file in ext.

The slow tests are only ran with the all, testall, or
testallwithcoverage targets.
2 files added
2 files modified
210 ■■■■■ changed files
opends/build-tools/src/org/opends/build/tools/PrepTestNG.java 135 ●●●●● patch | view | raw | blame | history
opends/build.xml 74 ●●●●● patch | view | raw | blame | history
opends/ext/build-tools.jar patch | view | raw | blame | history
opends/ext/testng/testng.xml 1 ●●●● patch | view | raw | blame | history
opends/build-tools/src/org/opends/build/tools/PrepTestNG.java
New file
@@ -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());
    }
  }
}
opends/build.xml
@@ -46,6 +46,11 @@
  <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"/>
  <property name="unittest.testng.src.dir"
@@ -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"
@@ -681,5 +715,35 @@
        <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>
opends/ext/build-tools.jar
Binary files differ
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"/>