Author: brett
Date: Sat Feb 25 23:02:56 2006
New Revision: 381066

URL: http://svn.apache.org/viewcvs?rev=381066&view=rev
Log:
[MSUREFIRE-23] first cut of test ng support. Needs work:
- formatting
- static block
- exceptions doing a printstacktrace
- want to separate it out as a provider

Added:
    
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java
   (with props)
    
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java
   (with props)
    
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java
   (with props)
Modified:
    maven/surefire/branches/surefire-testng/pom.xml
    maven/surefire/branches/surefire-testng/surefire-booter/pom.xml
    
maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
    maven/surefire/branches/surefire-testng/surefire-site/pom.xml
    maven/surefire/branches/surefire-testng/surefire/pom.xml
    
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/Surefire.java
    
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/SurefireUtils.java
    
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/DirectoryBattery.java
    
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java
    
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ReportEntry.java
    
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
    
maven/surefire/branches/surefire-testng/surefire/src/main/resources/org/apache/maven/surefire/surefire.properties

Modified: maven/surefire/branches/surefire-testng/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/pom.xml?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/pom.xml (original)
+++ maven/surefire/branches/surefire-testng/pom.xml Sat Feb 25 23:02:56 2006
@@ -6,7 +6,7 @@
   <artifactId>surefire-root</artifactId>
   <packaging>pom</packaging>
   <name>SureFire Parent</name>
-  <version>1.1</version>
+  <version>1.6-SNAPSHOT</version>
   <description>Surefire is a test framework project.</description>
   <url>http://maven.apache.org/surefire</url>
   <issueManagement>

Modified: maven/surefire/branches/surefire-testng/surefire-booter/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-booter/pom.xml?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-booter/pom.xml (original)
+++ maven/surefire/branches/surefire-testng/surefire-booter/pom.xml Sat Feb 25 
23:02:56 2006
@@ -1,24 +1,23 @@
-<?xml version="1.0" encoding="UTF-8"?><project>
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
   <parent>
     <artifactId>surefire-root</artifactId>
     <groupId>org.apache.maven.surefire</groupId>
-    <version>1.1</version>
+    <version>1.6-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>surefire-booter</artifactId>
   <name>SureFire Booter</name>
-  <version>1.5.3-SNAPSHOT</version>
   <dependencies>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
-      <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.maven.surefire</groupId>
       <artifactId>surefire</artifactId>
-      <version>1.5.3-SNAPSHOT</version>
+      <version>${project.version}</version>
     </dependency>
   </dependencies>
-</project>
\ No newline at end of file
+</project>

Modified: 
maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
 Sat Feb 25 23:02:56 2006
@@ -61,6 +61,8 @@
 
     private List classpathUrls = new ArrayList();
 
+    private String testSourceDirectory;
+    
     private String reportsDirectory;
 
     private String forkMode;
@@ -81,6 +83,16 @@
 
     private boolean debug;
 
+    private boolean forceTestNG;
+    
+    private String groups;
+    
+    private String excludedGroups;
+    
+    private int threadCount;
+    
+    private boolean parallel;
+    
     private String surefireBooterJar;
 
     private String plexusUtilsJar;
@@ -145,12 +157,17 @@
             classpathUrls.add( path );
         }
     }
-
+    
     public void setClassPathUrls( List classpathUrls )
     {
         this.classpathUrls = classpathUrls;
     }
 
+    public void setTestSourceDirectory(String dirPath)
+    {
+        this.testSourceDirectory = dirPath;
+    }
+    
     // ----------------------------------------------------------------------
     // Forking options
     // ----------------------------------------------------------------------
@@ -172,6 +189,31 @@
         this.jvm = jvm;
     }
 
+    public void setForceTestNG( boolean forceTestNG )
+    {
+        this.forceTestNG = forceTestNG;
+    }
+    
+    public void setGroups(String groups)
+    {
+        this.groups = groups;
+    }
+    
+    public void setExcludedGroups(String excludedGroups)
+    {
+        this.excludedGroups = excludedGroups;
+    }
+    
+    public void setThreadCount(int threadCount)
+    {
+        this.threadCount = threadCount;
+    }
+    
+    public void setParallel(boolean parallel)
+    {
+        this.parallel = parallel;
+    }
+    
     public void setSystemProperties( Properties systemProperties )
     {
         this.systemProperties = systemProperties;
@@ -295,17 +337,23 @@
         Class batteryExecutorClass = surefireClassLoader.loadClass( 
BATTERY_EXECUTOR );
 
         Object batteryExecutor = batteryExecutorClass.newInstance();
-
-        Method run = batteryExecutorClass.getMethod( "run", new 
Class[]{List.class, List.class, ClassLoader.class, String.class} );
-
+        
+        Method run = batteryExecutorClass.getMethod( "run", new 
Class[]{List.class, 
+                List.class, ClassLoader.class, String.class, 
+                Boolean.class, String.class, String.class,
+                Integer.class, Boolean.class, String.class} );
+        
         ClassLoader oldContextClassLoader = Thread.currentThread() 
.getContextClassLoader();
-
+        
         Thread.currentThread().setContextClassLoader( surefireClassLoader );
-
-        Boolean result = (Boolean) run.invoke( batteryExecutor, new 
Object[]{reports, batteries, surefireClassLoader, reportsDirectory} );
-
+        
+        Boolean result = (Boolean) run.invoke( batteryExecutor, 
+                new Object[]{reports, batteries, surefireClassLoader, 
+                reportsDirectory, new Boolean(forceTestNG), groups, 
excludedGroups,
+                new Integer(threadCount), new Boolean(parallel), 
testSourceDirectory} );
+        
         Thread.currentThread().setContextClassLoader( oldContextClassLoader );
-
+        
         return result.booleanValue();
     }
 

Modified: maven/surefire/branches/surefire-testng/surefire-site/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-site/pom.xml?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-site/pom.xml (original)
+++ maven/surefire/branches/surefire-testng/surefire-site/pom.xml Sat Feb 25 
23:02:56 2006
@@ -5,11 +5,10 @@
   <parent>
     <groupId>surefire</groupId>
     <artifactId>surefire-root</artifactId>
-    <version>1.1</version>
+    <version>1.6-SNAPSHOT</version>
   </parent>
   <groupId>surefire</groupId>
   <artifactId>surefire-site</artifactId>
-  <version>1.1-SNAPSHOT</version>
   <name>Surefire</name>
   <distributionManagement>
     <site>
@@ -17,15 +16,6 @@
       <url>scpexe://minotaur.apache.org/www/maven.apache.org/surefire/</url>
     </site>
   </distributionManagement>
-   <build>
-    <extensions>
-      <extension>
-        <groupId>org.apache.maven.wagon</groupId>
-         <artifactId>wagon-ssh-external</artifactId>
-         <version>1.0-alpha-5</version>
-      </extension>
-    </extensions>
-  </build>
   <reporting>
     <!-- TODO: disable dependencies -->
     <plugins>

Modified: maven/surefire/branches/surefire-testng/surefire/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/pom.xml?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire/pom.xml (original)
+++ maven/surefire/branches/surefire-testng/surefire/pom.xml Sat Feb 25 
23:02:56 2006
@@ -1,13 +1,13 @@
-<?xml version="1.0" encoding="UTF-8"?><project>
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
   <parent>
     <artifactId>surefire-root</artifactId>
     <groupId>org.apache.maven.surefire</groupId>
-    <version>1.1</version>
+    <version>1.6-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>surefire</artifactId>
   <name>SureFire</name>
-  <version>1.5.3-SNAPSHOT</version>
   <dependencies>
     <dependency>
       <groupId>junit</groupId>
@@ -18,6 +18,18 @@
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
       <version>1.0.5</version>
+    </dependency>
+    <dependency>
+      <groupId>org.testng</groupId>
+      <artifactId>testng</artifactId>
+      <version>4.6.1</version>
+      <classifier>jdk15</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.testng</groupId>
+      <artifactId>testng</artifactId>
+      <version>4.6.1</version>
+      <classifier>jdk14</classifier>
     </dependency>
   </dependencies>
 </project>

Modified: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/Surefire.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/Surefire.java?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/Surefire.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/Surefire.java
 Sat Feb 25 23:02:56 2006
@@ -17,10 +17,19 @@
  */
 
 import org.apache.maven.surefire.battery.Battery;
+import org.apache.maven.surefire.battery.JUnitBattery;
+import org.apache.maven.surefire.battery.TestNGBattery;
+import org.apache.maven.surefire.battery.TestNGXMLBattery;
 import org.apache.maven.surefire.battery.assertion.BatteryTestFailedException;
 import org.apache.maven.surefire.report.ReportEntry;
 import org.apache.maven.surefire.report.Reporter;
 import org.apache.maven.surefire.report.ReporterManager;
+import org.apache.maven.surefire.report.TestNGReporter;
+import org.testng.ISuiteListener;
+import org.testng.ITestListener;
+import org.testng.TestNG;
+import org.testng.internal.Utils;
+import org.testng.xml.ClassSuite;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -29,7 +38,7 @@
 
 /**
  * @version $Id$
- * @uathor Jason van Zyl
+ * @author Jason van Zyl
  */
 public class Surefire
 {
@@ -45,6 +54,18 @@
 
     private String reportsDirectory;
 
+    private String testSourceDirectory;
+
+    private boolean forceTestNG;
+
+    private String groups;
+
+    private String excludedGroups;
+
+    private int threadCount;
+
+    private boolean parallel;
+
     public Surefire()
     {
         super();
@@ -55,26 +76,32 @@
         return resources;
     }
 
-    public boolean run( List reports, List batteryHolders, String 
reportsDirectory )
+    public boolean run(List reports, List batteryHolders,
+            String reportsDirectory)
         throws Exception
     {
         ClassLoader classLoader = this.getClass().getClassLoader();
 
-        return run( reports, batteryHolders, classLoader, reportsDirectory );
+        return run(reports, batteryHolders, classLoader, reportsDirectory);
     }
 
-    public boolean run( List reports, List batteryHolders, ClassLoader 
classLoader, String reportsDirectory )
+    public boolean run(List reports, List batteryHolders,
+            ClassLoader classLoader, String reportsDirectory)
         throws Exception
     {
-        if ( reports == null || batteryHolders == null || classLoader == null )
-        {
-            throw new NullPointerException();
-        }
+        return run(reports, batteryHolders, classLoader, reportsDirectory,
+                Boolean.FALSE, null, null, new Integer(0), Boolean.FALSE, 
null);
+    }
 
-        if ( batteryHolders.size() == 0 )
-        {
-            throw new IllegalArgumentException();
-        }
+    public boolean run(List reports, List batteryHolders,
+            ClassLoader classLoader, String reportsDirectory,
+            Boolean forceTestNG, String groups, String excludedGroups,
+            Integer threadCount, Boolean parallel, String testSourceDirectory)
+        throws Exception
+    {
+        if (reports == null || batteryHolders == null || classLoader == null) 
{ throw new NullPointerException(); }
+
+        if (batteryHolders.size() == 0) { throw new 
IllegalArgumentException(); }
 
         this.batteryHolders = batteryHolders;
 
@@ -84,114 +111,202 @@
 
         this.reportsDirectory = reportsDirectory;
 
+        this.forceTestNG = forceTestNG.booleanValue();
+
+        this.groups = groups;
+
+        this.excludedGroups = excludedGroups;
+
+        this.threadCount = threadCount.intValue();
+
+        this.parallel = parallel.booleanValue();
+
+        this.testSourceDirectory = testSourceDirectory;
+
         return run();
     }
 
     public boolean run()
         throws Exception
     {
-        List batts = instantiateBatteries( batteryHolders, classLoader );
+        //required for jdk14 javadoc annotations
+        if (testSourceDirectory != null) {
+            SurefireUtils.setTestSourceDirectory(testSourceDirectory);
+        }
+
+        List batts = instantiateBatteries(batteryHolders, classLoader);
+
+        reporterManager = new ReporterManager(instantiateReports(reports,
+                classLoader), reportsDirectory);
 
-        reporterManager = new ReporterManager( instantiateReports( reports, 
classLoader ), reportsDirectory );
+        boolean jvm15 = false;
+        if (System.getProperty("java.version").indexOf("1.5") > -1) jvm15 = 
true;
 
-        try
-        {
-            reporterManager.runStarting( 100 );
+        try {
+            reporterManager.runStarting(100);
 
-            if ( batts.size() > 0 )
-            {
+            if (batts.size() > 0) {
                 int nbTests = 0;
 
-                for ( Iterator i = batts.iterator(); i.hasNext(); )
-                {
-                    Battery battery = (Battery) i.next();
+                for(Iterator i = batts.iterator(); i.hasNext();) {
+                    Battery battery = (Battery)i.next();
 
                     int testCount = 0;
 
-                    try
-                    {
+                    try {
                         testCount = battery.getTestCount();
-                    }
-                    catch ( BatteryTestFailedException e )
-                    {
+                    } catch (BatteryTestFailedException e) {
                         e.printStackTrace();
 
-                        ReportEntry report = new ReportEntry( e, 
"org.apache.maven.surefire.Runner", getResources().getString( "bigProblems" ), 
e );
+                        ReportEntry report = new ReportEntry(e,
+                                "org.apache.maven.surefire.Runner",
+                                getResources().getString("bigProblems"), e);
 
-                        reporterManager.batteryAborted( report );
+                        reporterManager.batteryAborted(report);
                     }
 
-                    if ( testCount > 0 )
-                    {
-                        executeBattery( battery, reporterManager );
+                    //TestNG needs a little config love
+                    if (battery instanceof TestNGXMLBattery) {
+                        TestNGXMLBattery xbat = (TestNGXMLBattery)battery;
+                        xbat.setOutputDirectory(reportsDirectory);
+                        xbat.setReporter(new TestNGReporter(reporterManager, 
this));
+                        xbat.execute(reporterManager);
+                        nbTests += xbat.getTestCount();
+                    } else if (testCount > 0) {
+                        executeBattery(battery, reporterManager);
 
                         nbTests += testCount;
                     }
 
                     List list = new ArrayList();
 
-                    for ( Iterator j = 
battery.getSubBatteryClassNames().iterator(); j.hasNext(); )
-                    {
-                        String s = (String) j.next();
+                    for(Iterator j = battery.getSubBatteryClassNames()
+                            .iterator(); j.hasNext();) {
+                        String s = (String)j.next();
 
-                        list.add( new Object[]{s, null} );
+                        list.add(new Object[] { s, null });
                     }
 
-                    List subBatteries = instantiateBatteries( list, 
classLoader );
+                    List subBatteries = instantiateBatteries(list, 
classLoader);
+
+                    //Handle testng tests
+                    if (forceTestNG || isTestNG(subBatteries)) {
+                        TestNG testNG = new TestNG();
+                        List classes = new ArrayList();
+                        for (Iterator j = subBatteries.iterator(); 
j.hasNext();) {
+                            Battery b = (Battery)j.next();
+                            if (b instanceof TestNGBattery) {
+                                TestNGBattery tb = (TestNGBattery)b;
+                                classes.add(tb.getTestClass());
+                                j.remove();
+                            } else if (forceTestNG && b instanceof 
JUnitBattery) {
+                                JUnitBattery jb = (JUnitBattery)b;
+                                classes.add(jb.getTestClass());
+                                j.remove();
+                            }
+                        }
+
+                        //configure testng parameters
+                        ClassSuite classSuite =
+                            new ClassSuite(groups != null ? groups : "TestNG 
Suite",
+                                    Utils.classesToXmlClasses(
+                                            (Class[])classes.toArray(new 
Class[classes.size()])));
+                        testNG.setCommandLineSuite(classSuite);
+                        testNG.setOutputDirectory(reportsDirectory);
+                        TestNGReporter testngReporter = new 
TestNGReporter(reporterManager, this);
+                        testNG.addListener((ITestListener)testngReporter);
+                        testNG.addListener((ISuiteListener)testngReporter);
+                        // TODO: bring back when TestNG returns the method
+//                        testNG.setReportResults(false);
+                        testNG.setThreadCount(threadCount);
+                        testNG.setParallel(parallel);
+
+                        if (groups != null)
+                            testNG.setGroups(groups);
+                        if (excludedGroups != null)
+                            testNG.setExcludedGroups(excludedGroups);
+
+                        //set source path so testng can find javadoc
+                        //annotations if not in 1.5 jvm
+                        if (!jvm15 && testSourceDirectory != null)
+                            testNG.setSourcePath(testSourceDirectory);
+
+                        //actually runs all the tests
+                        List result = testNG.runSuitesLocally();
+                        nbTests += result.size();
+                    }
 
-                    for ( Iterator j = subBatteries.iterator(); j.hasNext(); )
-                    {
-                        Battery b = (Battery) j.next();
+                    //continue normal mode
+                    for(Iterator j = subBatteries.iterator(); j.hasNext();) {
+                        Battery b = (Battery)j.next();
 
                         testCount = 0;
 
-                        try
-                        {
+                        try {
                             testCount = b.getTestCount();
-                        }
-                        catch ( BatteryTestFailedException e )
-                        {
+                        } catch (BatteryTestFailedException e) {
                             e.printStackTrace();
 
-                            ReportEntry report = new ReportEntry( e, 
"org.apache.maven.surefire.Runner", getResources().getString( "bigProblems" ), 
e );
+                            ReportEntry report = new ReportEntry(
+                                    e,
+                                    "org.apache.maven.surefire.SurefireRunner",
+                                    getResources().getString("bigProblems"),
+                                    e);
 
-                            reporterManager.batteryAborted( report );
+                            reporterManager.batteryAborted(report);
                         }
 
-                        if ( testCount > 0 )
-                        {
-                            executeBattery( b, reporterManager );
+                        if (testCount > 0) {
+
+                            executeBattery(b, reporterManager);
 
                             nbTests += testCount;
                         }
                     }
+
                 }
 
-                if ( nbTests == 0 )
-                {
-                    reporterManager.writeMessage( "There are no tests to run." 
);
+                if (nbTests == 0) {
+                    reporterManager.writeMessage("There are no tests to run.");
                 }
-            }
-            else
-            {
-                reporterManager.writeMessage( "There are no batteries to run." 
);
+            } else {
+                reporterManager.writeMessage("There are no batteries to run.");
             }
 
             reporterManager.runCompleted();
-        }
-        catch ( Throwable ex )
-        {
+        } catch (Throwable ex) {
             ex.printStackTrace();
 
-            ReportEntry report = new ReportEntry( ex, 
"org.apache.maven.surefire.Runner", getResources().getString( "bigProblems" ), 
ex );
+            ReportEntry report = new ReportEntry(ex,
+                    "org.apache.maven.surefire.Runner", getResources()
+                            .getString("bigProblems"), ex);
 
-            reporterManager.runAborted( report );
+            reporterManager.runAborted(report);
         }
 
         reporterManager.resume();
 
-        return !( reporterManager.getNbErrors() > 0 || reporterManager
-            .getNbFailures() > 0 );
+        return !(reporterManager.getNbErrors() > 0 || reporterManager
+                .getNbFailures() > 0);
+    }
+
+    /**
+     * Determines if <i>any</i> of the batteries specified
+     * is an instance of [EMAIL PROTECTED] TestNGBattery}.
+     * @param batteries The batteries to check
+     * @return True, if any of the objects are an instanceof [EMAIL PROTECTED] 
TestNGBattery}
+     */
+    public boolean isTestNG(List batteries)
+    {
+        if (batteries.size() > 0) {
+            for (int i = 0; i < batteries.size(); i++) {
+                Object obj = batteries.get(i);
+                if (obj instanceof TestNGBattery)
+                    return true;
+            }
+        }
+
+        return false;
     }
 
     /**
@@ -199,36 +314,38 @@
      * @param reportManager
      * @throws Exception
      */
-    public void executeBattery( Battery battery, ReporterManager reportManager 
)
+    public void executeBattery(Battery battery, ReporterManager reportManager)
         throws Exception
     {
-        try
-        {
-            String rawString = getResources().getString( 
"suiteExecutionStarting" );
+        try {
+            String rawString = getResources().getString(
+                    "suiteExecutionStarting");
 
-            ReportEntry report = new ReportEntry( this, 
battery.getBatteryName(), rawString );
+            ReportEntry report = new ReportEntry(this,
+                    battery.getBatteryName(), battery.getBatteryName(), 
rawString);
 
-            reportManager.batteryStarting( report );
+            reportManager.batteryStarting(report);
 
-            try
-            {
-                battery.execute( reportManager );
+            try {
+                battery.execute(reportManager);
 
-                rawString = getResources().getString( "suiteCompletedNormally" 
);
+                rawString = getResources().getString("suiteCompletedNormally");
 
-                report = new ReportEntry( this, battery.getBatteryName(), 
rawString );
+                report = new ReportEntry(this, battery.getBatteryName(),
+                        battery.getBatteryName(),
+                        rawString);
 
-                reportManager.batteryCompleted( report );
-            }
-            catch ( RuntimeException e )
-            {
+                reportManager.batteryCompleted(report);
+            } catch (RuntimeException e) {
                 e.printStackTrace();
 
-                rawString = getResources().getString( "executeException" );
+                rawString = getResources().getString("executeException");
 
-                report = new ReportEntry( this, battery.getBatteryName(), 
rawString, e );
+                report = new ReportEntry(this, battery.getBatteryName(),
+                        battery.getBatteryName(),
+                        rawString, e);
 
-                reportManager.batteryAborted( report );
+                reportManager.batteryAborted(report);
             }
 
             reportManager.runCompleted();
@@ -236,11 +353,12 @@
             reportManager.dispose();
         }
 
-        catch ( Throwable ex )
-        {
-            ReportEntry report = new ReportEntry( ex, 
"org.apache.maven.surefire.Runner", getResources().getString( "bigProblems" ), 
ex );
+        catch (Throwable ex) {
+            ReportEntry report = new ReportEntry(ex,
+                    "org.apache.maven.surefire.Runner", getResources()
+                            .getString("bigProblems"), ex);
 
-            reportManager.runAborted( report );
+            reportManager.runAborted(report);
         }
     }
 
@@ -250,27 +368,27 @@
      * @return
      * @throws Exception
      */
-    public static List instantiateBatteries( List batteryHolders, ClassLoader 
loader )
+    public static List instantiateBatteries(List batteryHolders,
+            ClassLoader loader)
         throws Exception
     {
         List batteries = new ArrayList();
 
-        for ( int i = 0; i < batteryHolders.size(); i++ )
-        {
-            Object[] holder = (Object[]) batteryHolders.get( i );
-
-            Object battery = SurefireUtils.instantiateBattery( holder, loader 
);
-
-            if ( battery != null )
-            {
-                batteries.add( battery );
+        for(int i = 0; i < batteryHolders.size(); i++) {
+            Object[] holder = (Object[])batteryHolders.get(i);
+
+            Object battery = SurefireUtils.instantiateBattery(holder, loader);
+
+            if (battery != null) {
+                batteries.add(battery);
             }
         }
 
         return batteries;
     }
 
-    protected List instantiateReports( List reportClassNames, ClassLoader 
classLoader )
+    protected List instantiateReports(List reportClassNames,
+            ClassLoader classLoader)
         throws Exception
     {
         List reports = new ArrayList();
@@ -279,35 +397,28 @@
 
         ClassLoader reporterClassLoader = Reporter.class.getClassLoader();
 
-        for ( Iterator i = reportClassNames.iterator(); i.hasNext(); )
-        {
-            String reportClassName = (String) i.next();
+        for(Iterator i = reportClassNames.iterator(); i.hasNext();) {
+            String reportClassName = (String)i.next();
 
-            try
-            {
-                Class reportClass = reporterClassLoader.loadClass( 
reportClassName );
+            try {
+                Class reportClass = reporterClassLoader
+                        .loadClass(reportClassName);
 
-                //assert Reporter.class.isAssignableFrom(reportClass);
+                // assert Reporter.class.isAssignableFrom(reportClass);
 
-                Reporter report = (Reporter) reportClass.newInstance();
+                Reporter report = (Reporter)reportClass.newInstance();
 
-                report.setReportsDirectory( reportsDirectory );
+                report.setReportsDirectory(reportsDirectory);
 
-                reports.add( report );
-            }
-            catch ( Exception e )
-            {
+                reports.add(report);
+            } catch (Exception e) {
                 e.printStackTrace();
             }
         }
 
-        if ( fail )
-        {
-            throw new RuntimeException( "couldn't assign reports as expected" 
);
-        }
+        if (fail) { throw new RuntimeException(
+                "couldn't assign reports as expected"); }
 
         return reports;
     }
 }
-
-

Modified: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/SurefireUtils.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/SurefireUtils.java?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/SurefireUtils.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/SurefireUtils.java
 Sat Feb 25 23:02:56 2006
@@ -1,6 +1,9 @@
 package org.apache.maven.surefire;
 
 import org.apache.maven.surefire.battery.JUnitBattery;
+import org.apache.maven.surefire.battery.TestNGBattery;
+import org.testng.internal.annotations.IAnnotationFinder;
+import org.testng.internal.TestNGClassFinder;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
@@ -11,6 +14,31 @@
  */
 public class SurefireUtils
 {
+  private static final IAnnotationFinder annotationFinder;
+
+    static
+    {
+        if ( System.getProperty( "java.version" ).indexOf( "1.5" ) > -1 )
+        {
+            annotationFinder = new 
org.testng.internal.annotations.JDK15AnnotationFinder();
+        }
+        else
+        {
+            System.out.println( "Using JDK14AnnotationFinder" );
+            annotationFinder = new 
org.testng.internal.annotations.JDK14AnnotationFinder();
+        }
+    }
+
+    /**
+     * For testng javadoc annotations, sets the test source directory source.
+     *
+     * @param testSourceDirectory
+     */
+    public static void setTestSourceDirectory( String testSourceDirectory )
+    {
+        annotationFinder.addSourceDirs( new String[]{testSourceDirectory} );
+}
+
     public static Object instantiateBattery( Object[] holder, ClassLoader 
loader )
         throws Exception
     {
@@ -33,9 +61,9 @@
         {
             return null;
         }
-
+        
         Object battery = null;
-
+        
         if ( batteryClass.isAssignableFrom( testClass ) )
         {
             if ( holder[1] != null )
@@ -57,6 +85,10 @@
             {
                 battery = testClass.newInstance();
             }
+        }
+        else if ( TestNGClassFinder.isTestNGClass( testClass, annotationFinder 
) )
+        {
+            battery = new TestNGBattery( testClass, loader );
         }
         else
         {

Modified: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/DirectoryBattery.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/DirectoryBattery.java?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/DirectoryBattery.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/DirectoryBattery.java
 Sat Feb 25 23:02:56 2006
@@ -16,25 +16,24 @@
  * limitations under the License.
  */
 
-import org.apache.maven.surefire.util.DirectoryScanner;
-import org.apache.maven.surefire.util.StringUtils;
-
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
-public class DirectoryBattery
-    extends AbstractBattery
-{
-    private static final String FS = System.getProperty( "file.separator" );
+import org.apache.maven.surefire.util.DirectoryScanner;
+import org.apache.maven.surefire.util.StringUtils;
+
+public class DirectoryBattery extends AbstractBattery {
+
+    private static final String FS = System.getProperty("file.separator");
 
     private File basedir;
 
     private List includes;
 
-    private List excludes ;
+    private List excludes;
 
-    public DirectoryBattery( File basedir, ArrayList includes, ArrayList 
excludes )
+    public DirectoryBattery(File basedir, ArrayList includes, ArrayList 
excludes)
         throws Exception
     {
         this.basedir = basedir;
@@ -45,64 +44,55 @@
 
         discoverBatteryClassNames();
     }
-
+    
     public void discoverBatteryClassNames()
         throws Exception
     {
-        String[] tests = collectTests( basedir, includes, excludes );
+        String[] tests = collectTests(basedir, includes, excludes);
 
-        if ( tests == null )
-        {
-            return;
-        }
-        
-        for ( int i = 0; i < tests.length; i++ )
-        {
+        if (tests == null) { return; }
+
+        for(int i = 0; i < tests.length; i++) {
             String s = tests[i];
 
-            s = s.substring( 0, s.indexOf( "." ) );
+            s = s.substring(0, s.indexOf("."));
 
-            s = s.replace( FS.charAt( 0 ), ".".charAt( 0 ) );
+            s = s.replace(FS.charAt(0), ".".charAt(0));
 
-            addSubBatteryClassName( s );
+            addSubBatteryClassName(s);
         }
     }
 
-    public String[] collectTests( File basedir, List includes, List excludes )
+    public String[] collectTests(File basedir, List includes, List excludes)
         throws Exception
     {
-        if ( !basedir.exists() )
-        {
-            return null;
-        }
+        if (!basedir.exists()) { return null; }
 
         DirectoryScanner scanner = new DirectoryScanner();
-        
-        scanner.setBasedir( basedir );
 
-        if ( includes != null )
-        {
+        scanner.setBasedir(basedir);
+
+        if (includes != null) {
             String[] incs = new String[includes.size()];
 
-            for ( int i = 0; i < incs.length; i++ )
-            {
-                incs[i] = StringUtils.replace( (String) includes.get( i ), 
"java", "class" );
+            for(int i = 0; i < incs.length; i++) {
+                incs[i] = StringUtils.replace((String)includes.get(i), "java",
+                        "class");
 
             }
 
-            scanner.setIncludes( incs );
+            scanner.setIncludes(incs);
         }
 
-        if ( excludes != null )
-        {
+        if (excludes != null) {
             String[] excls = new String[excludes.size()];
 
-            for ( int i = 0; i < excls.length; i++ )
-            {
-                excls[i] = StringUtils.replace( (String) excludes.get( i ), 
"java", "class" );
+            for(int i = 0; i < excls.length; i++) {
+                excls[i] = StringUtils.replace((String)excludes.get(i), "java",
+                        "class");
             }
 
-            scanner.setExcludes( excls );
+            scanner.setExcludes(excls);
         }
 
         scanner.scan();

Modified: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java
 Sat Feb 25 23:02:56 2006
@@ -198,7 +198,7 @@
         }
     }
 
-    protected Class getTestClass()
+    public Class getTestClass()
     {
         return testClass;
     }
@@ -291,8 +291,9 @@
     public String getBatteryName()
     {
         return testClass.getName();
+        //return testClass.getPackage().getName();
     }
-
+    
     protected Constructor getTestConstructor( Class testClass )
         throws NoSuchMethodException
     {

Added: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java?rev=381066&view=auto
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java
 (added)
+++ 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java
 Sat Feb 25 23:02:56 2006
@@ -0,0 +1,130 @@
+package org.apache.maven.surefire.battery;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.surefire.report.ReporterManager;
+
+/**
+ * Main plugin point for running testng tests within the Surefire runtime
+ * infrastructure.
+ * 
+ * @author jkuhnert
+ */
+public class TestNGBattery implements Battery {
+       
+    protected List testMethods;
+    
+    protected List subBatteryClassNames;
+    
+    private Class testClass;
+       
+    /**
+     * Creates a new test battery that will process the class being
+     * passed in to determine the testing configuration.
+     * @param testClass
+     * @param loader
+     * @throws Exception
+     */
+       public TestNGBattery(final Class testClass, ClassLoader loader)
+                       throws Exception {
+               processTestClass(testClass, loader);
+       }
+       
+       /**
+        * Parses and configures this battery based on the test class
+        * being passed in.
+        * @param testClass
+        * @param loader
+        * @throws Exception
+        */
+       public void processTestClass(final Class testClass, ClassLoader loader)
+                       throws Exception {
+               if (testClass == null) {
+                       throw new NullPointerException("testClass is null");
+               }
+               
+               if (loader == null) {
+                       throw new NullPointerException("classLoader is null");
+               }
+               
+               this.testClass = testClass;
+       }
+       
+    public Class getTestClass() 
+    {
+        return testClass;
+    }
+    
+       protected void discoverTestMethods()
+    {
+        if ( testMethods != null )
+        {
+            return;
+        }
+        
+        testMethods = new ArrayList();
+               
+        Method[] methods = testClass.getMethods();
+        
+        for ( int i = 0; i < methods.length; ++i )
+        {
+            Method m = methods[i];
+            
+            Class[] paramTypes = m.getParameterTypes();
+            
+            boolean isInstanceMethod = !Modifier.isStatic( m.getModifiers() );
+
+            boolean returnsVoid = m.getReturnType() == void.class;
+
+            boolean hasNoParams = paramTypes.length == 0;
+
+            if ( isInstanceMethod && returnsVoid && hasNoParams )
+            {
+                String simpleName = m.getName();
+
+                if ( simpleName.length() <= 4 )
+                {
+                    // name must have 5 or more chars
+                    continue;
+                }
+                
+                testMethods.add( m );
+            }
+        }
+    }
+       
+       public void discoverBatteryClassNames() throws Exception {
+       }
+
+       public void execute(ReporterManager reportManager) throws Exception {
+               // TODO Auto-generated method stub
+       }
+       
+       public String getBatteryName() {
+               return testClass.getName();
+       }
+       
+       public void addSubBatteryClassName( String batteryClassName )
+    {
+        getSubBatteryClassNames().add( batteryClassName );
+    }
+       
+    public List getSubBatteryClassNames()
+    {
+        if ( subBatteryClassNames == null )
+        {
+            subBatteryClassNames = new ArrayList();
+        }
+
+        return subBatteryClassNames;
+    }
+    
+       public int getTestCount() {
+               discoverTestMethods();
+               
+        return testMethods.size();
+       }
+}

Propchange: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGBattery.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java?rev=381066&view=auto
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java
 (added)
+++ 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java
 Sat Feb 25 23:02:56 2006
@@ -0,0 +1,109 @@
+/**
+ * 
+ */
+package org.apache.maven.surefire.battery;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.maven.surefire.report.ReporterManager;
+import org.apache.maven.surefire.report.TestNGReporter;
+import org.testng.ISuiteListener;
+import org.testng.ITestListener;
+import org.testng.TestNG;
+import org.testng.xml.Parser;
+import org.testng.xml.XmlSuite;
+import org.xml.sax.SAXException;
+
+
+/**
+ * Handles suite xml file definitions for TestNG.
+ * 
+ * @author jkuhnert
+ */
+public class TestNGXMLBattery implements Battery {
+    
+    protected File suiteFile;
+    protected TestNG testRunner;
+    protected int m_testCount = 0;
+    protected String m_suiteName = "TestNG XML Suite";
+    
+    /**
+     * Creates a testng battery to be configured by the specified
+     * xml file.
+     */
+    public TestNGXMLBattery(File suiteFile)
+    {
+        this.suiteFile = suiteFile;
+        parseSuite();
+    }
+    
+    public void discoverBatteryClassNames() throws Exception {
+    }
+    
+    public void execute(ReporterManager reportManager) throws Exception {
+        testRunner.runSuitesLocally();
+    }
+    
+    public String getBatteryName() {
+        return m_suiteName;
+    }
+    
+    public List getSubBatteryClassNames()
+    {
+        return Collections.EMPTY_LIST;
+    }
+    
+    public int getTestCount() {
+        return m_testCount;
+    }
+    
+    public void setOutputDirectory(String reportsDirectory)
+    {
+        testRunner.setOutputDirectory(reportsDirectory);
+    }
+    
+    public void setReporter(TestNGReporter reporter)
+    {
+        testRunner.addListener((ITestListener)reporter);
+        testRunner.addListener((ISuiteListener)reporter);
+    }
+    
+    /**
+     * Instantiates and partially configures testng suite
+     */
+    protected void parseSuite()
+    {
+        testRunner = new TestNG();
+        List suites = new ArrayList();
+        
+        try {
+            XmlSuite s = new Parser(suiteFile.getAbsolutePath()).parse();
+            m_suiteName = s.getName();
+            m_testCount += s.getTests().size();
+            suites.add(s);
+        }
+        catch(FileNotFoundException fne) {
+            System.err.println("File not found: " + 
suiteFile.getAbsolutePath() + " Ignoring.");
+        }
+        catch(IOException e) {
+            e.printStackTrace();
+        }
+        catch(ParserConfigurationException e) {
+            e.printStackTrace();
+        }
+        catch(SAXException e) {
+            e.printStackTrace();
+        }
+        
+        testRunner.setXmlSuites(suites);
+        // TODO: return when TestNG brings it back
+//        testRunner.setReportResults(false);
+    }
+}

Propchange: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/battery/TestNGXMLBattery.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ReportEntry.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ReportEntry.java?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ReportEntry.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/ReportEntry.java
 Sat Feb 25 23:02:56 2006
@@ -22,12 +22,19 @@
 
     private String name;
 
+    private String group;
+    
     private String message;
 
     private Throwable throwable;
 
     public ReportEntry( Object source, String name, String message )
     {
+       this(source, name, null, message);
+    }
+
+    public ReportEntry( Object source, String name, String group, String 
message )
+    {
         if ( source == null )
         {
             throw new NullPointerException( "source is null" );
@@ -40,16 +47,23 @@
         {
             throw new NullPointerException( "message is null" );
         }
-
+        
         this.source = source;
-
+        
         this.name = name;
-
+        
+        this.group = group;
+        
         this.message = message;
     }
-
+    
     public ReportEntry( Object source, String name, String message, Throwable 
throwable )
     {
+        this(source, name, null, message, throwable);
+    }
+
+    public ReportEntry( Object source, String name, String group, String 
message, Throwable throwable )
+    {
         if ( source == null )
         {
             throw new NullPointerException( "source is null" );
@@ -71,11 +85,13 @@
 
         this.name = name;
 
+        this.group = group;
+        
         this.message = message;
 
         this.throwable = throwable;
     }
-
+    
     public Object getSource()
     {
         return source;
@@ -86,6 +102,11 @@
         return name;
     }
 
+    public String getGroup()
+    {
+        return group;
+    }
+    
     public String getMessage()
     {
         return message;

Added: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java?rev=381066&view=auto
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java
 (added)
+++ 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java
 Sat Feb 25 23:02:56 2006
@@ -0,0 +1,197 @@
+/**
+ * 
+ */
+package org.apache.maven.surefire.report;
+
+import org.apache.maven.surefire.Surefire;
+import org.testng.ISuite;
+import org.testng.ISuiteListener;
+import org.testng.ITestContext;
+import org.testng.ITestListener;
+import org.testng.ITestResult;
+import org.testng.TestNG;
+
+/**
+ * Listens for and provides and adaptor layer so that
+ * TestNG tests can report their status to the current
+ * [EMAIL PROTECTED] ReporterManager}.
+ * 
+ * @author jkuhnert
+ */
+public class TestNGReporter implements ITestListener, ISuiteListener {
+    
+    /** core Surefire reporting */
+    protected ReporterManager reportManager;
+    /** core Surefire instance */
+    protected Surefire surefire;
+    
+    /**
+     * Constructs a new instance that will listen to
+     * test updates from a [EMAIL PROTECTED] TestNG} class instance. 
+     * 
+     * <p/>It is assumed that the requisite [EMAIL PROTECTED] 
TestNG#addListener(ITestListener)} 
+     * method call has already associated with this instance <i>before</i> the 
test 
+     * suite is run.
+     * 
+     * @param reportManager Instance to report suite status to
+     * @param surefire Main instance that provides resources messages,etc.
+     */
+    public TestNGReporter(ReporterManager reportManager, Surefire surefire)
+    {
+        this.reportManager = reportManager;
+        this.surefire = surefire;
+        
+        if (reportManager == null)
+            throw new IllegalArgumentException("ReportManager passed in was 
null.");
+        if (surefire == null)
+            throw new IllegalArgumentException("Surefire passed in was null.");
+    }
+    
+    /* (non-Javadoc)
+     * @see org.testng.ITestListener#onTestStart(org.testng.ITestResult)
+     */
+    public void onTestStart(ITestResult result)
+    {
+        String rawString = Surefire.getResources().getString("testStarting");
+        ReportEntry report = new ReportEntry(surefire,
+                result.getTestClass().getName() + "#" + 
result.getMethod().getMethodName(),
+                resultGroup(result),
+                rawString);
+        
+        reportManager.testStarting(report);
+        
+        
+    }
+
+    /* (non-Javadoc)
+     * @see org.testng.ITestListener#onTestSuccess(org.testng.ITestResult)
+     */
+    public void onTestSuccess(ITestResult result)
+    {
+        String rawString = Surefire.getResources().getString("testSuccessful");
+        
+        ReportEntry report = new ReportEntry(surefire, result.getName(),
+                rawString);
+        
+        reportManager.testSucceeded(report);
+    }
+
+    /* (non-Javadoc)
+     * @see org.testng.ITestListener#onTestFailure(org.testng.ITestResult)
+     */
+    public void onTestFailure(ITestResult result)
+    {
+        String rawString = 
Surefire.getResources().getString("executeException");
+
+        // TODO: almost certainly not correct: 
result.getMethod().getExtraOutput().getParameterOutput()
+        ReportEntry report = new ReportEntry(surefire, result.getName(),
+                rawString + 
result.getMethod().getExtraOutput().getParameterOutput(), 
result.getThrowable());
+        
+        reportManager.testFailed(report);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.testng.ITestListener#onTestSkipped(org.testng.ITestResult)
+     */
+    public void onTestSkipped(ITestResult result)
+    {
+        String rawString = Surefire.getResources().getString("testSkipped");
+        
+        ReportEntry report = new ReportEntry(surefire, result.getName(),
+                rawString);
+        
+        reportManager.testSucceeded(report);
+    }
+
+    /* (non-Javadoc)
+     * @see 
org.testng.ITestListener#onTestFailedButWithinSuccessPercentage(org.testng.ITestResult)
+     */
+    public void onTestFailedButWithinSuccessPercentage(ITestResult result)
+    {
+        String rawString = 
Surefire.getResources().getString("executeException");
+        
+        // TODO: almost certainly not correct: 
result.getMethod().getExtraOutput().getParameterOutput()
+        ReportEntry report = new ReportEntry(surefire, result.getName(),
+                rawString + result.getMethod().getExtraOutput(), 
result.getThrowable());
+        
+        reportManager.testError(report);
+    }
+
+    /* (non-Javadoc)
+     * @see org.testng.ITestListener#onStart(org.testng.ITestContext)
+     */
+    public void onStart(ITestContext context)
+    {
+        String rawString = Surefire.getResources().getString(
+        "suiteExecutionStarting");
+        
+        String group = groupString(context.getIncludedGroups());
+        if (group == null) group = context.getName();
+        
+        ReportEntry report = new ReportEntry(surefire,
+                context.getName(), group, rawString);
+        
+        reportManager.batteryStarting(report);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.testng.ITestListener#onFinish(org.testng.ITestContext)
+     */
+    public void onFinish(ITestContext context)
+    {
+       String rawString = 
Surefire.getResources().getString("suiteCompletedNormally");
+        
+        ReportEntry report = new ReportEntry(surefire, 
+                context.getName(),
+                groupString(context.getIncludedGroups()),
+                rawString);
+        
+        reportManager.batteryCompleted(report);
+        
+        reportManager.runCompleted();
+        
+        reportManager.dispose();
+    }
+    
+    public void onFinish(ISuite suite)
+    {
+    }
+    
+    public void onStart(ISuite suite)
+    {
+    }
+    
+    /**
+     * Creates a string out of the list of testng groups in the 
+     * form of <pre>"group1,group2,group3"</pre>. 
+     * @param groups
+     */
+    public static String groupString(String[] groups)
+    {
+        if (groups != null && groups.length > 0) {
+            StringBuffer str = new StringBuffer();
+            for (int i = 0; i < groups.length; i++) {
+                str.append(groups[i]);
+                if ((i + 1) < groups.length)
+                    str.append(",");
+            }
+            return str.toString();
+        } else
+            return null;
+    }
+    
+    /**
+     * Utility to report back with either the test class name
+     * run, or the group(s) method belongs to.
+     * @param result 
+     * @return Valid string
+     */
+    public static String resultGroup(ITestResult result)
+    {
+        String groupStr = groupString(result.getMethod().getGroups());
+        if (groupStr != null)
+            return groupStr;
+        else
+            return result.getTestClass().getName();
+    }
+}

Propchange: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/TestNGReporter.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
 Sat Feb 25 23:02:56 2006
@@ -80,7 +80,8 @@
         testSuite = new Xpp3Dom("testsuite");
          
         testSuite.setAttribute("name",  report.getName());
-        
+        if (report.getGroup() != null)
+            testSuite.setAttribute("group", report.getGroup());
         showProperties();
     }
 
@@ -124,6 +125,8 @@
         testCase = createElement(testSuite, "testcase");
         
         testCase.setAttribute("name", reportName);
+        if (report.getGroup() != null)
+            testCase.setAttribute("group", report.getGroup());
     }
 
     public void testSucceeded( ReportEntry report )

Modified: 
maven/surefire/branches/surefire-testng/surefire/src/main/resources/org/apache/maven/surefire/surefire.properties
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire/src/main/resources/org/apache/maven/surefire/surefire.properties?rev=381066&r1=381065&r2=381066&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire/src/main/resources/org/apache/maven/surefire/surefire.properties
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire/src/main/resources/org/apache/maven/surefire/surefire.properties
 Sat Feb 25 23:02:56 2006
@@ -5,4 +5,7 @@
 suiteExecutionStarting=The execute method of a subsuite is about to be invoked.
 executeException=Exception encountered when invoking execute on a subsuite.
 suiteCompletedNormally=The execute method of a subsuite returned normally.
-bigProblems=An exception or error caused a run to abort.
\ No newline at end of file
+bigProblems=An exception or error caused a run to abort.
+testStarting=Test starting.
+testSuccessful=Test completed successfully.
+testSkipped=Test skipped.
\ No newline at end of file


Reply via email to