From 654eefcc5b1a2c8ba5fd47a83a8be114cef73bf5 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Thu, 28 Jun 2007 21:20:29 +0000
Subject: [PATCH] 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.

---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java |    2 
 opendj-sdk/opends/build.xml                                                                      |   10 +++
 opendj-sdk/opends/src/build-tools/org/opends/build/tools/PrepTestNG.java                         |  114 ++++++++++++++++++++++++++++++-------
 opendj-sdk/opends/ext/testng/testng.xml                                                          |    4 +
 4 files changed, 104 insertions(+), 26 deletions(-)

diff --git a/opendj-sdk/opends/build.xml b/opendj-sdk/opends/build.xml
index 961bf32..d2ca0cf 100644
--- a/opendj-sdk/opends/build.xml
+++ b/opendj-sdk/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"/>
diff --git a/opendj-sdk/opends/ext/testng/testng.xml b/opendj-sdk/opends/ext/testng/testng.xml
index 2f59930..f8f4afa 100644
--- a/opendj-sdk/opends/ext/testng/testng.xml
+++ b/opendj-sdk/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>
diff --git a/opendj-sdk/opends/src/build-tools/org/opends/build/tools/PrepTestNG.java b/opendj-sdk/opends/src/build-tools/org/opends/build/tools/PrepTestNG.java
index 702acb8..7f5cd1f 100644
--- a/opendj-sdk/opends/src/build-tools/org/opends/build/tools/PrepTestNG.java
+++ b/opendj-sdk/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;
+  }
+
 }
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java
index b2da6b2..972ffff 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java
+++ b/opendj-sdk/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);

--
Gitblit v1.10.0