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

kenneth_suter
28.20.2007 bf940a2b684b0efd2e0966e644e798e1ee8528fd
This improves on the previous commit for grouping and running Windows specific tests.  The previous implementation only worked for the default tests and not the precommit or function test definitions.

With this commit:

The following rules apply to the generation of content for test.xml by PrepTestNG:

- For the default test definition, if no group clauses have been specified and the platform is non-Windows and explicit Windows exclusion element is generated.
- For the default test definition, if group clauses have been specified a Windows exclusion element is generated if the platform is non-Windows and a Windows group clause has not been explicitly provided.
- The precommit and functional test definitions are always parameterized with an explicit Windows exclusion element if the platform is non-Windows.

Corrected and added to the test framework help generated in build.xml.

I have also cleaned up the formatting of the generated XML with reasonable indentation.

Reenabled TestStaticUtils.testRenameFileLockedTarget()
4 files modified
130 ■■■■ changed files
opends/build.xml 10 ●●●●● patch | view | raw | blame | history
opends/ext/testng/testng.xml 4 ●●● patch | view | raw | blame | history
opends/src/build-tools/org/opends/build/tools/PrepTestNG.java 114 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java 2 ●●● patch | view | raw | blame | history
opends/build.xml
@@ -1228,6 +1228,13 @@
    <echo message="      Default debug target:"/>
    <echo message="      org.opends.server:level=warning,category=caught|data|database-access|message|protocol" />
    <echo message=""/>
    <echo message="  -Dtest.groups=exclude=slow"/>
    <echo message="      for example excludes the slow tests.  Each value is expected" />
    <echo message="      group inclusion/exclusion clause which consists of either 'include'" />
    <echo message="      or 'exclude' followed by the '=' character and then a group name." />
    <echo message="      For multiple group clauses, separate them with a ',' and "/>
    <echo message="      quote the entire value. Debug logging is disabled."/>
    <echo message=""/>
    <echo message="  -Dtest.packages=org.opends.server.api"/>
    <echo message="      for example runs only the tests in the api package"/>
    <echo message="      For multiple packages, separate them with a ',' and "/>
@@ -1240,7 +1247,8 @@
    <echo message=""/>
    <echo message="  -Dtest.methods=org.opends.server.types.TestDN.testGetRDN"/>
    <echo message="      for example only runs the testGetRDN method"/>
    <echo message="      For multiple methods, separate them with a ',' and "/>
    <echo message="      For multiple methods within the same class, append additional"/>
    <echo message="      method names to the end separating them with a ',' and "/>
    <echo message="      quote the entire value. Debug logging is disabled."/>
    <echo message=""/>
    <echo message="  -Dtest.diff.srcpath=src/server/org/opends/server/core"/>
opends/ext/testng/testng.xml
@@ -1,12 +1,13 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="OpenDS"   verbose="1" >
    <test name="default">
    <!-- DO NOT REMOVE! - THIS LINE WILL BE REPLACED WITH TAGS GENERATED BY ANT -->
    <!-- DO NOT REMOVE! - GENERATED DEFAULT TAGS (see PrepTestNG class) -->
    </test>
    <test name="precommit">
        <groups>
            <run>
                <!-- DO NOT REMOVE! - GENERATED GLOBAL RUN TAGS (see PrepTestNG class) -->
                <include name="precommit"/>
                <exclude name="broken"/>
            </run>
@@ -16,6 +17,7 @@
    <test name="functional">
        <groups>
            <run>
                <!-- DO NOT REMOVE! - GENERATED GLOBAL RUN TAGS (see PrepTestNG class) -->
                <include name="functional"/>
                <exclude name="broken"/>
            </run>
opends/src/build-tools/org/opends/build/tools/PrepTestNG.java
@@ -31,12 +31,25 @@
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Arrays;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
public class PrepTestNG extends Task
{
  /** Template for inserting children elements of default test tag */
  static private final String DEFAULT_TAGS_TEMPLATE =
    "<!-- DO NOT REMOVE! - GENERATED DEFAULT TAGS (see PrepTestNG class) -->";
  /** Template for inserting global children elements of run tags */
  static private final String GLOBAL_RUN_TAGS_TEMPLATE =
    "<!-- DO NOT REMOVE! - GENERATED GLOBAL RUN TAGS (see PrepTestNG class) -->";
  /** Indentation used in testng.xml */
  static private final int INDENT = 4;
  private String file;
  private String toFile;
  private String groupList;
@@ -156,57 +169,87 @@
      while(line != null)
      {
        if(line.indexOf("<!-- DO NOT REMOVE! - THIS LINE WILL BE " +
            "REPLACED WITH TAGS GENERATED BY ANT -->") >= 0)
        if(line.indexOf(DEFAULT_TAGS_TEMPLATE) >= 0)
        {
          int level = 2;
          if(groups.length > 0)
          {
            writer.println("<groups>\n  <run>");
            boolean windowsClause = false;
            println(writer, level, "<groups>");
            println(writer, ++level,   "<run>");
            level++;
            for(String group : groups)
            {
              groupLine = group.split("=");
              if(groupLine.length == 2)
              {
                writer.println("    <"+groupLine[0].trim()+" " +
                               "name=\""+groupLine[1].trim() + "\" />");
                groupCount++;
                String inc_exc = groupLine[0].trim();
                if (inc_exc == null ||
                        !("include".equals(inc_exc.toLowerCase()) ||
                                "exclude".equals(inc_exc.toLowerCase()))) {
                  System.out.println("Error:  illegal group clause " + group);
                } else {
                  String gr = groupLine[1].trim();
                  println(writer, level, "<" +inc_exc +" "+
                          "name=\""+gr+ "\" />");
                  windowsClause |= "windows".equals(gr);
                  groupCount++;
                }
              }
            }
            writer.println("  </run>\n</groups>");
            // Exclude windows specific tests if the user has not provided
            // an explicit windows clause and we're not on windows.
            if (!windowsClause && !isWindows()) {
              println(writer, level, "<exclude name=\"windows\"/>");
              groupCount++;
            }
            println(writer, --level,   "</run>");
            println(writer, --level, "</groups>");
          } else {
            // No explicit groups have been specified so see if we need
            // to exclude the windows tests.
            if (!isWindows()) {
              writer.println("    <groups><run><exclude name=\"windows\"/></run></groups>");
              println(writer, level,   "<groups>");
              println(writer, ++level,   "<run>");
              println(writer, ++level,     "<exclude name=\"windows\"/>");
              println(writer, --level,   "</run>");
              println(writer, --level, "</groups>");
              groupCount++;
            }
          }
          if(packages.length > 0)
          {
            writer.println("<packages>");
            println(writer, level, "<packages>");
            level++;
            for(String pkg : packages)
            {
              writer.println("  <package name=\"" + pkg.trim() + "\" />");
              println(writer, level, "<package name=\"" + pkg.trim() + "\" />");
              packageCount++;
            }
            writer.println("</packages>");
            println(writer, --level, "</packages>");
          }
          if(classes.length > 0 || methods.length > 0)
          {
            writer.println("<classes>");
            println(writer, level, "<classes>");
            if(classes.length > 0)
            {
              level++;
              for(String cls : classes)
              {
                writer.println("  <class name=\"" + cls.trim() + "\" />");
                println(writer, level, "<class name=\"" + cls.trim() + "\" />");
                classCount++;
              }
            }
            if(methods.length > 0)
            {
              level++;
              for(String mhd : methods)
              {
                methodLine = mhd.split(",");
@@ -222,31 +265,39 @@
                                  methodNameStartIdx);
                  methodName = methodLine[0].substring(methodNameStartIdx + 1,
                                methodLine[0].length());
                  writer.println("  <class name=\"" +
                  println(writer, level, "<class name=\"" +
                      methodClass.trim() + "\" >");
                  writer.println("  <methods>");
                  writer.println("    <include name=\"" +
                  println(writer, ++level, "<methods>");
                  println(writer, ++level, "<include name=\"" +
                      methodName.trim() + "\" />");
                  methodCount++;
                  classCount++;
                  for(int i = 1; i < methodLine.length; i ++)
                  {
                    writer.println("    <include name=\"" +
                    println(writer, level, "<include name=\"" +
                      methodLine[i].trim() + "\" />");
                    methodCount++;
                  }
                  writer.println("  </methods>");
                  writer.println("</class>");
                  println(writer, --level, "</methods>");
                  println(writer, --level, "</class>");
                }
              }
            }
            writer.println("</classes>");
            println(writer, --level, "</classes>");
          }
        }
        else if (line.indexOf(GLOBAL_RUN_TAGS_TEMPLATE) != -1)
        {
          if (!isWindows()) {
            int index = line.indexOf(GLOBAL_RUN_TAGS_TEMPLATE);
            println(writer, levelForIndex(index),
                    "<exclude name=\"windows\"/>");
          }
        }
        else
        {
          writer.println(line);
          println(writer, 0, line);
        }
        line = reader.readLine();
@@ -266,4 +317,21 @@
    String os = System.getProperty("os.name");
    return (os != null && os.toLowerCase().indexOf("windows") != -1);
  }
  static private String indent(int indent) {
    char[] blankArray = new char[indent];
    Arrays.fill(blankArray, ' ');
    return new String(blankArray);
  }
  static private void println(PrintStream writer, int level, String txt) {
    writer.print(indent(INDENT * level));
    writer.print(txt);
    writer.print(System.getProperty("line.separator"));
  }
  static private int levelForIndex(int index) {
    return index / INDENT;
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java
@@ -903,7 +903,7 @@
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test(enabled=false, groups={"windows"}, expectedExceptions=IOException.class)
  @Test(groups={"windows"}, expectedExceptions=IOException.class)
  public void testRenameFileLockedTarget() throws Exception {
    File src = File.createTempFile("src", null);
    File target = File.createTempFile("target", null);