Author: jkuhnert Date: Sat Mar 17 15:59:37 2007 New Revision: 519470 URL: http://svn.apache.org/viewvc?view=rev&rev=519470 Log: Modified maven-surefire-plugin test8 to use TestNG version 5.5 and modified relevant source calls so that it all works with version 5.1 or 5.5 of TestNG.
Modified: maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/pom.xml maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/src/test/java/TestNGTest.java maven/sandbox/branches/surefire/surefire-collaboration/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.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/TestNGReporter.java Modified: maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/pom.xml URL: http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/pom.xml?view=diff&rev=519470&r1=519469&r2=519470 ============================================================================== --- maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/pom.xml (original) +++ maven/sandbox/branches/surefire/surefire-collaboration/maven-surefire-plugin/src/it/test8/pom.xml Sat Mar 17 15:59:37 2007 @@ -26,14 +26,14 @@ <groupId>org.apache.maven.plugins.surefire</groupId> <artifactId>test8</artifactId> <version>1.0-SNAPSHOT</version> - <name>TestNG 5.1 tests</name> - <description>Tests TestNG 5.1 dependency</description> + <name>TestNG 5.5 tests</name> + <description>Tests TestNG 5.5 dependency</description> <dependencies> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> - <version>5.1</version> + <version>5.5</version> <classifier>jdk15</classifier> <scope>test</scope> </dependency> 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=519470&r1=519469&r2=519470 ============================================================================== --- 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 Sat Mar 17 15:59:37 2007 @@ -49,4 +49,4 @@ { assert false == true : "Group specified by test shouldnt be run."; } -} \ No newline at end of file +} Modified: maven/sandbox/branches/surefire/surefire-collaboration/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java URL: http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collaboration/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java?view=diff&rev=519470&r1=519469&r2=519470 ============================================================================== --- maven/sandbox/branches/surefire/surefire-collaboration/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java (original) +++ maven/sandbox/branches/surefire/surefire-collaboration/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java Sat Mar 17 15:59:37 2007 @@ -144,7 +144,7 @@ { String suiteClass = (String) definition[0]; Object[] params = (Object[]) definition[1]; -System.out.println("createSuiteFromDefinintion() : suiteClass " + suiteClass); + SurefireTestSuite suite = instantiateSuite( suiteClass, params, surefireClassLoader ); suite.locateTestSets( testsClassLoader ); 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=519470&r1=519469&r2=519470 ============================================================================== --- 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 Sat Mar 17 15:59:37 2007 @@ -27,7 +27,6 @@ import org.testng.ISuiteListener; import org.testng.ITestListener; import org.testng.TestNG; -import org.testng.internal.annotations.AnnotationConfiguration; import org.testng.xml.XmlClass; import org.testng.xml.XmlSuite; import org.testng.xml.XmlTest; @@ -104,9 +103,19 @@ } XmlSuite suite = new XmlSuite(); - suite.setParallel( parallel ); - suite.setThreadCount( threadCount ); + + suite.setThreadCount(threadCount); + + // have to invoke via reflection because TestNG version 5.5 broke things + + try { + + TestNGExecutor.execute(suite, "setParallel", Boolean.valueOf(parallel)); + } catch (Throwable t) { + throw new RuntimeException("Failed to configure TestNG properly", t); + } + createXmlTest( suite, testSet ); executeTestNG( suite, reporterManager, classLoader ); @@ -121,8 +130,18 @@ } XmlSuite suite = new XmlSuite(); - suite.setParallel( parallel ); - suite.setThreadCount( threadCount ); + + suite.setThreadCount(threadCount); + + // have to invoke via reflection because TestNG version 5.5 broke things + + try { + + TestNGExecutor.execute(suite, "setParallel", Boolean.valueOf(parallel)); + + } catch (Throwable t) { + throw new RuntimeException("Failed to configure TestNG properly", t); + } for ( Iterator i = testSets.values().iterator(); i.hasNext(); ) { @@ -183,13 +202,7 @@ testNG.addListener( (ITestListener) reporter ); testNG.addListener( (ISuiteListener) reporter ); - String jre = System.getProperty("java.vm.version"); - if (jre.indexOf("1.4") > -1) { - AnnotationConfiguration.getInstance().initialize(AnnotationConfiguration.JVM_14_CONFIG); - AnnotationConfiguration.getInstance().getAnnotationFinder().addSourceDirs(new String[]{testSourceDirectory}); - } else { - AnnotationConfiguration.getInstance().initialize(AnnotationConfiguration.JVM_15_CONFIG); - } + TestNGExecutor.configureJreType(testNG, testSourceDirectory); // Set source path so testng can find javadoc annotations if not in 1.5 jvm if ( testSourceDirectory != null ) 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=519470&r1=519469&r2=519470 ============================================================================== --- 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 Sat Mar 17 15:59:37 2007 @@ -27,6 +27,7 @@ import org.testng.internal.annotations.AnnotationConfiguration; import org.testng.xml.XmlSuite; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; @@ -41,6 +42,61 @@ { } + static void 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 }); + } else if (m.getParameterTypes()[0] == String.class) { + + m.invoke(target, new Object[] { param.toString() }); + } + } + + static Method getMethod(Class clazz, String name, int argCount) + { + Method[] methods = clazz.getMethods(); + for (int i = 0; i < methods.length; i++) { + if (methods[i].getName().equals(name) && methods[i].getParameterTypes().length == argCount) + return methods[i]; + } + + return null; + } + + static void configureJreType(TestNG testNG, String testSourceDirectory) + { + try { + + String jre = System.getProperty("java.vm.version"); + + Method annotType = TestNGExecutor.getMethod(testNG.getClass(), "setAnnotations", 1); + if (annotType != null) { + + annotType.invoke(testNG, new Object[]{ jre.indexOf("1.4") > -1 ? "javadoc" : "jdk"}); + + Method init = testNG.getClass().getDeclaredMethod("initializeAnnotationFinders", new Class[0]); + init.setAccessible(true); + init.invoke(testNG, new Object[0]); + + } else if (Class.forName("org.testng.internal.annotations.AnnotationConfiguration") != null + && AnnotationConfiguration.class.getMethod("getInstance", new Class[0]) != null) { + + if (jre.indexOf("1.4") > -1) { + AnnotationConfiguration.getInstance().initialize(AnnotationConfiguration.JVM_14_CONFIG); + AnnotationConfiguration.getInstance().getAnnotationFinder().addSourceDirs(new String[]{testSourceDirectory}); + } else { + AnnotationConfiguration.getInstance().initialize(AnnotationConfiguration.JVM_15_CONFIG); + } + } + } catch (Throwable t) { + throw new RuntimeException(t); + } + } + static void executeTestNG( SurefireTestSuite surefireSuite, String testSourceDirectory, XmlSuite suite, ReporterManager reporterManager ) { @@ -57,13 +113,7 @@ testNG.addListener( (ITestListener) reporter ); testNG.addListener( (ISuiteListener) reporter ); - String jre = System.getProperty("java.vm.version"); - if (jre.indexOf("1.4") > -1) { - AnnotationConfiguration.getInstance().initialize(AnnotationConfiguration.JVM_14_CONFIG); - AnnotationConfiguration.getInstance().getAnnotationFinder().addSourceDirs(new String[]{testSourceDirectory}); - } else { - AnnotationConfiguration.getInstance().initialize(AnnotationConfiguration.JVM_15_CONFIG); - } + configureJreType(testNG, testSourceDirectory); // Set source path so testng can find javadoc annotations if not in 1.5 jvm if ( testSourceDirectory != null ) Modified: maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.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/TestNGReporter.java?view=diff&rev=519470&r1=519469&r2=519470 ============================================================================== --- maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java (original) +++ maven/sandbox/branches/surefire/surefire-collaboration/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java Sat Mar 17 15:59:37 2007 @@ -24,6 +24,7 @@ import org.apache.maven.surefire.report.ReporterException; import org.apache.maven.surefire.report.ReporterManager; import org.apache.maven.surefire.suite.SurefireTestSuite; +import org.testng.IResultMap; import org.testng.ISuite; import org.testng.ISuiteListener; import org.testng.ITestContext; @@ -31,6 +32,8 @@ import org.testng.ITestResult; import org.testng.TestNG; +import java.lang.reflect.Method; +import java.util.Iterator; import java.util.ResourceBundle; /** @@ -101,7 +104,6 @@ // because they are considered configuration methods, but if one of them fails we need to change the // test count and start it in case it wasn't already started so that all failures / tests are properly // reported - if (!testStarted) { onTestStart(result); @@ -181,8 +183,24 @@ */ public void cleanupAfterTestsRun() { + Method failed = TestNGExecutor.getMethod(_finishContext.getClass(), "getFailedConfigurations", 0); + if (failed != null) { + try { + + IResultMap map = (IResultMap) failed.invoke(_finishContext, new Object[0]); + + Iterator results = map.getAllResults().iterator(); + while (results.hasNext()) { + + ITestResult result = (ITestResult) results.next(); + onTestFailure(result); + } + + } catch (Throwable t) { t.printStackTrace(); } + } + String rawString = bundle.getString( "testSetCompletedNormally" ); - + ReportEntry report = new ReportEntry( source, _finishContext.getName(), groupString( _finishContext.getIncludedGroups(), null ), rawString );