Author: jkuhnert
Date: Sun Apr 15 09:50:41 2007
New Revision: 529005

URL: http://svn.apache.org/viewvc?view=rev&rev=529005
Log:
-) Fixed new method failed errors encountered with TestNG 5.5 
Parser(file).parse() return type of Collection when it used to be just a single 
XmlSuite. 

-) Updated plugin / logic to handle the new behavior of the parellel 
configuration parameter which now takes true / methods / tests as valid string 
paramteres and appropriately built in the backwards compatible method 
invocation calls to make it all work. 

-) Updated some of the surefire plugin integration tests to work properly / 
pass when testing the parallel mode.

Modified:
    
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test4/pom.xml
    
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test6/pom.xml
    
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test6/src/test/java/TestNGTest.java
    
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/src/test/java/TestNGTest.java
    
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
    
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
    
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
    
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java

Modified: 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test4/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test4/pom.xml?view=diff&rev=529005&r1=529004&r2=529005
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test4/pom.xml
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test4/pom.xml
 Sun Apr 15 09:50:41 2007
@@ -21,45 +21,53 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0";
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
-  <modelVersion>4.0.0</modelVersion>
+    <modelVersion>4.0.0</modelVersion>
 
-  <groupId>org.apache.maven.plugins.surefire</groupId>
-  <artifactId>test4</artifactId>
-  <version>1.0-SNAPSHOT</version>
-  <name>TestNG Suites</name>
-  <description>Uses suite xml file definitions to invoke testng 
tests</description>
+    <groupId>org.apache.maven.plugins.surefire</groupId>
+    <artifactId>test4</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <name>TestNG Suites</name>
+    <description>Uses suite xml file definitions to invoke testng 
tests</description>
 
-  <dependencies>
-    <dependency>
-      <groupId>org.testng</groupId>
-      <artifactId>testng</artifactId>
-      <version>5.1</version>
-      <classifier>jdk15</classifier>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
+    <dependencies>
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <version>5.5</version>
+            <classifier>jdk15</classifier>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <suiteXmlFiles>
-            <file>src/test-data/testng.xml</file>
-          </suiteXmlFiles>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <configuration>
-          <source>1.5</source>
-          <target>1.5</target>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <suiteXmlFiles>
+                        <file>src/test-data/testng.xml</file>
+                    </suiteXmlFiles>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-clean-plugin</artifactId>
+                <version>2.2-SNAPSHOT</version>
+                <inherited>true</inherited>
+            </plugin>
+            
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 
 
 </project>

Modified: 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test6/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test6/pom.xml?view=diff&rev=529005&r1=529004&r2=529005
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test6/pom.xml
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test6/pom.xml
 Sun Apr 15 09:50:41 2007
@@ -33,7 +33,7 @@
     <dependency>
       <groupId>org.testng</groupId>
       <artifactId>testng</artifactId>
-      <version>5.1</version>
+      <version>5.5</version>
       <classifier>jdk15</classifier>
       <scope>test</scope>
     </dependency>
@@ -47,7 +47,7 @@
         <configuration>
           <groups>functional</groups>
           <threadCount>3</threadCount>
-          <parallel>true</parallel>
+          <parallel>methods</parallel>
         </configuration>
       </plugin>
       <plugin>

Modified: 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test6/src/test/java/TestNGTest.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test6/src/test/java/TestNGTest.java?view=diff&rev=529005&r1=529004&r2=529005
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test6/src/test/java/TestNGTest.java
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test6/src/test/java/TestNGTest.java
 Sun Apr 15 09:50:41 2007
@@ -1,7 +1,4 @@
-
-import static org.testng.Assert.*;
-
-import org.testng.annotations.AfterSuite;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
@@ -24,11 +21,9 @@
                testObject = new Object();
        }
        
-       @AfterSuite(groups = "functional")
+       @AfterClass(groups = "functional")
        public void check_Test_Count()
        {
-               System.out.println("check_Test_Count(): " + m_testCount);
-        
                assert m_testCount == 3 : "Expected 3 tests to be run but local 
count was " + m_testCount;
        }
        
@@ -37,10 +32,10 @@
        /**
         * Tests reporting an error
         */
-       @Test(groups = {"functional", "notincluded"})
+       @Test(groups = {"functional", "notincluded"}, threadPoolSize = 3, 
invocationCount = 3)
        public void isTestObjectNull()
        {
-               m_testCount++;
+        m_testCount++;
                assert testObject != null : "testObject is null";
        }
        

Modified: 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/src/test/java/TestNGTest.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/src/test/java/TestNGTest.java?view=diff&rev=529005&r1=529004&r2=529005
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/src/test/java/TestNGTest.java
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/src/test/java/TestNGTest.java
 Sun Apr 15 09:50:41 2007
@@ -24,8 +24,6 @@
        @AfterSuite(alwaysRun = true, groups = "functional")
        public void check_Test_Count()
        {
-               System.out.println("check_Test_Count(): " + m_testCount);
-               
                assert m_testCount == 3 : "Expected 3 tests to be run but local 
count was " + m_testCount;
        }
        
@@ -34,7 +32,7 @@
        /**
         * Tests reporting an error
         */
-       @Test(groups = {"functional", "notincluded"})
+       @Test(groups = {"functional", "notincluded"}, threadPoolSize = 3, 
invocationCount = 3)
        public void isTestObjectNull()
        {
                m_testCount++;

Modified: 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?view=diff&rev=529005&r1=529004&r2=529005
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
 Sun Apr 15 09:50:41 2007
@@ -38,24 +38,11 @@
 import org.apache.maven.surefire.booter.SurefireBooter;
 import org.apache.maven.surefire.booter.SurefireBooterForkException;
 import org.apache.maven.surefire.booter.SurefireExecutionException;
-import org.apache.maven.surefire.report.BriefConsoleReporter;
-import org.apache.maven.surefire.report.BriefFileReporter;
-import org.apache.maven.surefire.report.ConsoleReporter;
-import org.apache.maven.surefire.report.DetailedConsoleReporter;
-import org.apache.maven.surefire.report.FileReporter;
-import org.apache.maven.surefire.report.ForkingConsoleReporter;
-import org.apache.maven.surefire.report.XMLReporter;
+import org.apache.maven.surefire.report.*;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
 
 /**
  * Run tests using Surefire.
@@ -322,9 +309,10 @@
      *
      * @parameter expression="${parallel}"
      * default-value="false"
+     * 
      * @todo test how this works with forking, and console/file output 
parallelism
      */
-    private boolean parallel;
+    private String parallel;
 
     /**
      * Whether to trim the stack trace in the reports to just the lines within 
the test, or show the full trace.
@@ -442,7 +430,7 @@
             return false;
         }
 
-        if ( parallel )
+        if ( parallel != null)
         {
             if ( threadCount < 1 )
             {
@@ -585,7 +573,7 @@
             if ( testNgArtifact != null )
             {
                 surefireBooter.addTestSuite( 
"org.apache.maven.surefire.testng.TestNGDirectoryTestSuite", new Object[]{
-                    testClassesDirectory, includes, excludes, groups, 
excludedGroups, Boolean.valueOf( parallel ),
+                    testClassesDirectory, includes, excludes, groups, 
excludedGroups, parallel,
                     new Integer( threadCount ), 
testSourceDirectory.getAbsolutePath()} );
             }
             else

Modified: 
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java?view=diff&rev=529005&r1=529004&r2=529005
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
 Sun Apr 15 09:50:41 2007
@@ -32,11 +32,7 @@
 import org.testng.xml.XmlTest;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
 
 /**
  * Test suite for TestNG based on a directory of Java test classes. Can also 
execute JUnit tests.
@@ -50,14 +46,14 @@
 
     private String excludedGroups;
 
-    private boolean parallel;
+    private String parallel;
 
     private int threadCount;
 
     private String testSourceDirectory;
 
     public TestNGDirectoryTestSuite( File basedir, ArrayList includes, 
ArrayList excludes, String groups,
-                                     String excludedGroups, Boolean parallel, 
Integer threadCount,
+                                     String excludedGroups, String parallel, 
Integer threadCount,
                                      String testSourceDirectory )
     {
         super( basedir, includes, excludes );
@@ -66,7 +62,7 @@
 
         this.excludedGroups = excludedGroups;
 
-        this.parallel = parallel.booleanValue();
+        this.parallel = parallel;
 
         this.threadCount = threadCount.intValue();
 
@@ -110,7 +106,7 @@
         
         try {
             
-            TestNGExecutor.execute(suite, "setParallel", 
Boolean.valueOf(parallel));
+            TestNGExecutor.execute(suite, "setParallel", parallel);
 
         } catch (Throwable t) {
             throw new RuntimeException("Failed to configure TestNG properly", 
t);
@@ -137,9 +133,10 @@
         
         try {
             
-            TestNGExecutor.execute(suite, "setParallel", 
Boolean.valueOf(parallel));
+            TestNGExecutor.execute(suite, "setParallel", parallel);
 
         } catch (Throwable t) {
+
             throw new RuntimeException("Failed to configure TestNG properly", 
t);
         }
 

Modified: 
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java?view=diff&rev=529005&r1=529004&r2=529005
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
 Sun Apr 15 09:50:41 2007
@@ -42,18 +42,33 @@
     {
     }
 
-    static void execute(Object target, String methodName, Object param)
+    static Object execute(Object target, String methodName, Object param)
     throws Exception
     {
-        Method m = getMethod(target.getClass(), methodName, 1);
-        
-        if (m.getParameterTypes()[0] == boolean.class) {
-            
-            m.invoke(target, new Object[] { param });
+        Method m = getMethod(target.getClass(), methodName, param != null ? 1 
: 0);
+        Object ret = null;
+
+        if (m == null)
+            throw new IllegalArgumentException("No method found with name <" + 
methodName + "> on object " + target);
+
+        if (m.getParameterTypes().length <= 0) {
+
+            ret = m.invoke(target, new Object[0]);
+        } else if (m.getParameterTypes()[0] == boolean.class) {
+
+            Object[] args = { param };
+            if (!Boolean.class.isInstance(param))
+            {
+                args[0] = Boolean.valueOf(param.toString());
+            }
+
+            ret = m.invoke(target, args);
         } else if (m.getParameterTypes()[0] == String.class) {
-            
-            m.invoke(target, new Object[] { param.toString() });
+
+            ret = m.invoke(target, new Object[] { param.toString() });
         }
+
+        return ret;
     }
     
     static Method getMethod(Class clazz, String name, int argCount)

Modified: 
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java?view=diff&rev=529005&r1=529004&r2=529005
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
 Sun Apr 15 09:50:41 2007
@@ -30,16 +30,11 @@
 import javax.xml.parsers.ParserConfigurationException;
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.lang.reflect.Method;
+import java.util.*;
 
 /**
  * Handles suite xml file definitions for TestNG.
- *
- * @author jkuhnert
  */
 public class TestNGXmlTestSuite
     implements SurefireTestSuite
@@ -47,8 +42,8 @@
     private File suiteFile;
 
     private String testSourceDirectory;
-
-    private XmlSuite suite;
+    
+    private Collection suites;
 
     private Map testSets;
 
@@ -75,7 +70,13 @@
             throw new IllegalStateException( "You must call locateTestSets 
before calling execute" );
         }
 
-        TestNGExecutor.executeTestNG( this, testSourceDirectory, suite, 
reporterManager );
+        Iterator it = suites.iterator();
+        while (it.hasNext())
+        {
+            XmlSuite suite = (XmlSuite)it.next();
+
+            TestNGExecutor.executeTestNG( this, testSourceDirectory, suite, 
reporterManager );
+        }
     }
 
     public void execute( String testSetName, ReporterManager reporterManager, 
ClassLoader classLoader )
@@ -92,6 +93,27 @@
             throw new TestSetFailedException( "Unable to find test set '" + 
testSetName + "' in suite" );
         }
 
+        Iterator it = suites.iterator();
+        while (it.hasNext())
+        {
+            XmlSuite suite = (XmlSuite)it.next();
+
+            List originalTests = new ArrayList( suite.getTests() );
+            for ( Iterator i = suite.getTests().iterator(); i.hasNext(); )
+            {
+                XmlTest test = (XmlTest) i.next();
+                if ( !test.getName().equals( testSetName ) )
+                {
+                    i.remove();
+                }
+            }
+
+            TestNGExecutor.executeTestNG( this, testSourceDirectory, suite, 
reporterManager );
+
+            suite.getTests().clear();
+            suite.getTests().addAll( originalTests );
+        }
+        /*
         List originalTests = new ArrayList( suite.getTests() );
         for ( Iterator i = suite.getTests().iterator(); i.hasNext(); )
         {
@@ -106,6 +128,7 @@
 
         suite.getTests().clear();
         suite.getTests().addAll( originalTests );
+        */
     }
 
     public int getNumTests()
@@ -116,7 +139,17 @@
 
     public int getNumTestSets()
     {
-        return suite.getTests().size();
+        int count = 0;
+        Iterator it = suites.iterator();
+
+        while (it.hasNext())
+        {
+            XmlSuite suite = (XmlSuite)it.next();
+
+            count += suite.getTests().size();
+        }
+
+        return count;
     }
 
     public Map locateTestSets( ClassLoader classLoader )
@@ -130,7 +163,24 @@
 
         try
         {
-            suite = new Parser( suiteFile.getAbsolutePath() ).parse();
+            Parser p = new Parser( suiteFile.getAbsolutePath() );
+
+            Method m = TestNGExecutor.getMethod(p.getClass(), "parse", 0);
+
+            if (m == null)
+                throw new IllegalStateException("TestNG suite parser parse() 
method could not be found.");
+
+            if (Collection.class.isAssignableFrom(m.getReturnType())) {
+
+                suites = (Collection) TestNGExecutor.execute(p, "parse", null);
+            } else {
+
+                List parsedSuites = new ArrayList();
+
+                parsedSuites.add(TestNGExecutor.execute(p, "parse", null));
+                
+                suites = parsedSuites;
+            }
         }
         catch ( IOException e )
         {
@@ -144,7 +194,30 @@
         {
             throw new TestSetFailedException( "Error reading test suite", e );
         }
+        catch ( Exception e )
+        {
+            throw new TestSetFailedException( "Error parsing test suite", e );
+        }
 
+        Iterator it = suites.iterator();
+        while (it.hasNext())
+        {
+            XmlSuite suite = (XmlSuite)it.next();
+
+            for ( Iterator i = suite.getTests().iterator(); i.hasNext(); )
+            {
+                XmlTest xmlTest = (XmlTest) i.next();
+
+                if ( testSets.containsKey( xmlTest.getName() ) )
+                {
+                    throw new TestSetFailedException( "Duplicate test set '" + 
xmlTest.getName() + "'" );
+                }
+
+                // We don't need to put real test sets in here, the key is the 
important part
+                testSets.put( xmlTest.getName(), xmlTest );
+            }
+        }
+        /*
         for ( Iterator i = suite.getTests().iterator(); i.hasNext(); )
         {
             XmlTest xmlTest = (XmlTest) i.next();
@@ -156,7 +229,8 @@
 
             // We don't need to put real test sets in here, the key is the 
important part
             testSets.put( xmlTest.getName(), xmlTest );
-        }
+        }*/
+        
         return testSets;
     }
 }


Reply via email to