Repository: maven-surefire Updated Branches: refs/heads/master af4414138 -> 2261bcea6
[SUREFIRE-1194] reporter argument does not work for TestNG 5.14.3 and later Improve tests Change type for the reporter param Run unit tests for TestNG Typo in TestNG513ConfiguratorTest Fix tests Update documentation Fail or warn with bad TestNG versions Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/7fe7a2a3 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/7fe7a2a3 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/7fe7a2a3 Branch: refs/heads/master Commit: 7fe7a2a3b7c725a6d1e9f920dffcbd05013ade03 Parents: af44141 Author: Julien Herr <jul...@herr.fr> Authored: Fri Nov 20 22:56:52 2015 +0100 Committer: Tibor17 <tibo...@lycos.com> Committed: Tue Dec 15 01:29:31 2015 +0100 ---------------------------------------------------------------------- .../plugin/surefire/AbstractSurefireMojo.java | 31 +++++++- .../src/site/apt/examples/testng.apt.vm | 10 +++ .../its/CheckTestNgListenerReporterIT.java | 50 +++++++++++-- .../resources/testng-listener-reporter/pom.xml | 7 ++ surefire-providers/surefire-testng/pom.xml | 11 --- .../testng/conf/TestNG513Configurator.java | 64 ++++++++++++++++ .../testng/conf/TestNG5141Configurator.java | 38 ++++++++++ .../testng/conf/TestNG5143Configurator.java | 58 +++++++++++++++ .../testng/conf/TestNG60Configurator.java | 2 +- .../testng/conf/TestNGMapConfigurator.java | 12 ++- .../testng/conf/TestNG513ConfiguratorTest.java | 72 ++++++++++++++++++ .../testng/conf/TestNG5141ConfiguratorTest.java | 78 ++++++++++++++++++++ .../testng/conf/TestNG5143ConfiguratorTest.java | 72 ++++++++++++++++++ .../testng/conf/TestNGMapConfiguratorTest.java | 14 +++- 14 files changed, 493 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java index ca3a4be..3e0d840 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java @@ -1116,11 +1116,12 @@ public abstract class AbstractSurefireMojo if ( testNgArtifact != null ) { DefaultArtifactVersion defaultArtifactVersion = new DefaultArtifactVersion( testNgArtifact.getVersion() ); - getProperties().setProperty( "testng.configurator", getConfiguratorName( defaultArtifactVersion ) ); + getProperties().setProperty( "testng.configurator", getConfiguratorName( defaultArtifactVersion, + getLog() ) ); } } - private static String getConfiguratorName( ArtifactVersion version ) + private static String getConfiguratorName( ArtifactVersion version, Log log ) throws MojoExecutionException { try @@ -1140,11 +1141,35 @@ public abstract class AbstractSurefireMojo { return "org.apache.maven.surefire.testng.conf.TestNGMapConfigurator"; } - range = VersionRange.createFromVersionSpec( "[5.10,6.5)" ); + range = VersionRange.createFromVersionSpec( "[5.10,5.13)" ); if ( range.containsVersion( version ) ) { return "org.apache.maven.surefire.testng.conf.TestNG510Configurator"; } + range = VersionRange.createFromVersionSpec( "[5.13,5.14.1)" ); + if ( range.containsVersion( version ) ) + { + return "org.apache.maven.surefire.testng.conf.TestNG513Configurator"; + } + range = VersionRange.createFromVersionSpec( "[5.14.1,5.14.3)" ); + if ( range.containsVersion( version ) ) + { + return "org.apache.maven.surefire.testng.conf.TestNG5141Configurator"; + } + range = VersionRange.createFromVersionSpec( "[5.14.3,6.0)" ); + if ( range.containsVersion( version ) ) + { + if ( version.equals( new DefaultArtifactVersion( "5.14.3" ) ) ) + { + throw new MojoExecutionException( "Due to a bad formatted pom.xml, " + + "TestNG 5.14.3 is not supported" ); + } + if ( VersionRange.createFromVersionSpec( "[5.14.4,5.14.5]" ).containsVersion( version ) ) + { + log.warn( "Due to a bad formatted pom.xml, TestNG 5.14.4 and 5.14.5 may not work" ); + } + return "org.apache.maven.surefire.testng.conf.TestNG5143Configurator"; + } range = VersionRange.createFromVersionSpec( "[6.0,)" ); if ( range.containsVersion( version ) ) { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm ---------------------------------------------------------------------- diff --git a/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm b/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm index be19905..85a6349 100644 --- a/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm +++ b/maven-surefire-plugin/src/site/apt/examples/testng.apt.vm @@ -28,6 +28,11 @@ Using TestNG +* Unsupported TestNG versions + + - TestNG 5.14.3: Bad formatted pom.xml. + - TestNG 5.14.4 and 5.14.5: TestNG is using a missing dependency (org.testng:guice:2.0). Excluding it, may break some features. + * Configuring TestNG To get started with TestNG, include the following dependency in your project (replacing the version with the one you wish to use): @@ -230,6 +235,11 @@ Using TestNG TestNG provides support for attaching custom listeners, reporters, annotation transformers and method interceptors to your tests. By default, TestNG attaches a few basic listeners to generate HTML and XML reports. + Unsupported versions: + - TestNG 5.14.1 and 5.14.2: Due to an internal TestNG issue, listeners and reporters are not working with TestNG. + Please upgrade TestNG to version 5.14.9 or higher. + Note: It may be fixed in a future surefire version. + You can configure multiple custom listeners like this: +---+ http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenerReporterIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenerReporterIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenerReporterIT.java index af46906..8e25e5d 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenerReporterIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenerReporterIT.java @@ -21,7 +21,13 @@ package org.apache.maven.surefire.its; import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.apache.maven.surefire.its.fixture.SurefireLauncher; +import org.junit.After; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.Collection; /** * Test simple TestNG listener and reporter @@ -29,16 +35,48 @@ import org.junit.Test; * @author <a href="mailto:dfabul...@apache.org">Dan Fabulich</a> * @author <a href="mailto:krosenv...@apache.org">Kristian Rosenvold</a> */ +@RunWith(Parameterized.class) public class CheckTestNgListenerReporterIT extends SurefireJUnit4IntegrationTestCase { - @Test - public void TestNgListenerReporter() + + @Parameterized.Parameters(name = "{index}: TestNG {0}") + public static Collection<Object[]> data() { - final SurefireLauncher verifierStarter = unpack( "testng-listener-reporter" ); - verifierStarter.executeTest().verifyErrorFree( 1 ).getTargetFile( - "resultlistener-output.txt" ).assertFileExists().getTargetFile( - "suitelistener-output.txt" ).assertFileExists().getTargetFile( "reporter-output.txt" ).assertFileExists(); + return Arrays.asList(new Object[][] { + { "5.6" }, // First TestNG version with reporter support + { "5.7" }, // default version from pom of the test case + { "5.10" }, + { "5.13" }, // "reporterslist" param becomes String instead of List<ReporterConfig> + // "listener" param becomes String instead of List<Class> + //{ "5.14.1" }, // "listener" param becomes List instead of String + // Fails: Issue with 5.14.1 and 5.14.2 => join with <space>, split with "," + // TODO will work with "configure(CommandLineArgs)" + //{ "5.14.2" }, // ReporterConfig is not available + //{ "5.14.3" }, // TestNG uses "reporter" instead of "reporterslist" + // Both String or List are possible for "listener" + // Fails: Bad formatted pom => transitive dependencies are missing + { "5.14.4" }, // Usage of org.testng:guice + // Caution: Some TestNG features may fail with 5.14.4 and 5.14.5 due to missing dependency + { "5.14.6" }, // Usage of org.testng:guice removed + { "5.14.9" }, // Latest 5.14.x TestNG version + { "6.0" }, + { "6.9.9" } // Current latest TestNG version + }); } + @Parameterized.Parameter + public String version; + private SurefireLauncher verifierStarter; + + @Test + public void testNgListenerReporter() + { + verifierStarter = unpack( "testng-listener-reporter", "_" + version ); + verifierStarter.resetInitialGoals( version ); + verifierStarter.executeTest().verifyErrorFree( 1 ) + .getTargetFile( "resultlistener-output.txt" ).assertFileExists() + .getTargetFile( "suitelistener-output.txt" ).assertFileExists() + .getTargetFile( "reporter-output.txt" ).assertFileExists(); + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-integration-tests/src/test/resources/testng-listener-reporter/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/testng-listener-reporter/pom.xml b/surefire-integration-tests/src/test/resources/testng-listener-reporter/pom.xml index 3235638..b39c11b 100644 --- a/surefire-integration-tests/src/test/resources/testng-listener-reporter/pom.xml +++ b/surefire-integration-tests/src/test/resources/testng-listener-reporter/pom.xml @@ -53,6 +53,13 @@ <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>${testNgVersion}</version> + <exclusions> + <exclusion> + <!-- Excluded for 5.14.3, 5.14.4 and 5.14.5 which depend on this artifact --> + <groupId>org.testng</groupId> + <artifactId>guice</artifactId> + </exclusion> + </exclusions> </dependency> </dependencies> </profile> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-providers/surefire-testng/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/pom.xml b/surefire-providers/surefire-testng/pom.xml index ebff6c4..baa9f76 100644 --- a/surefire-providers/surefire-testng/pom.xml +++ b/surefire-providers/surefire-testng/pom.xml @@ -64,16 +64,5 @@ <targetPath>META-INF</targetPath> </resource> </resources> - - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <!-- DGF There are no tests in this project currently, and this - resolves SUREFIRE-414 --> - <skipExec>true</skipExec> - </configuration> - </plugin> - </plugins> </build> </project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG513Configurator.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG513Configurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG513Configurator.java new file mode 100644 index 0000000..f38df08 --- /dev/null +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG513Configurator.java @@ -0,0 +1,64 @@ +package org.apache.maven.surefire.testng.conf; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.surefire.testset.TestSetFailedException; + +/** + * TestNG 5.13 configurator. Changed: "reporterslist" need String instead of List<ReporterConfig>. + */ +public class TestNG513Configurator + extends TestNG510Configurator +{ + + @Override + protected Object convertReporterConfig( String val ) + { + return val; + } + + @Override + protected Object convertListeners( String listenerClasses ) throws TestSetFailedException + { + return convertListenersString( listenerClasses ); + } + + static String convertListenersString( String listenerClasses ) + { + if ( listenerClasses == null || "".equals( listenerClasses.trim() ) ) + { + return listenerClasses; + } + + StringBuilder sb = new StringBuilder(); + String[] classNames = listenerClasses.split( "\\s*,\\s*(\\r?\\n)?\\s*" ); + for ( int i = 0; i < classNames.length; i++ ) + { + String className = classNames[i]; + sb.append( className ); + if ( i < classNames.length - 1 ) + { + sb.append( ',' ); + } + } + + return sb.toString(); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG5141Configurator.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG5141Configurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG5141Configurator.java new file mode 100644 index 0000000..49f0579 --- /dev/null +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG5141Configurator.java @@ -0,0 +1,38 @@ +package org.apache.maven.surefire.testng.conf; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.surefire.testset.TestSetFailedException; + +/** + * TestNG 5.14.1 configurator. Changed: "listener" use List instead of String. + */ +public class TestNG5141Configurator + extends TestNG513Configurator +{ + + @Override + protected Object convertListeners( String listenerClasses ) throws TestSetFailedException + { + // TODO "configure(CommandLineArgs)", which should replace "configure(Map)", doesn't have the issue + throw new TestSetFailedException( "Due to an internal TestNG issue, " + + "the listener feature of TestNG is not supported with 5.14.1 and 5.14.2" ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG5143Configurator.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG5143Configurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG5143Configurator.java new file mode 100644 index 0000000..5575ccf --- /dev/null +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG5143Configurator.java @@ -0,0 +1,58 @@ +package org.apache.maven.surefire.testng.conf; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Map; +import org.apache.maven.surefire.testset.TestSetFailedException; + +/** + * TestNG 5.14.3 configurator. Changed: "reporterslist" replaced by "reporter", + * and "listener" can use String instead of List<Class>. + */ +public class TestNG5143Configurator + extends TestNG5141Configurator +{ + + @Override + Map<String, Object> getConvertedOptions( Map<String, String> options ) + throws TestSetFailedException + { + Map<String, Object> convertedOptions = super.getConvertedOptions( options ); + for ( Map.Entry<String, Object> entry : convertedOptions.entrySet() ) + { + String key = entry.getKey(); + if ( "-reporterslist".equals( key ) ) + { + convertedOptions.remove( "-reporterslist" ); + Object value = entry.getValue(); + convertedOptions.put( "-reporter", value ); + break; + } + } + return convertedOptions; + } + + + @Override + protected Object convertListeners( String listenerClasses ) throws TestSetFailedException + { + return convertListenersString( listenerClasses ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG60Configurator.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG60Configurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG60Configurator.java index 531d85e..e374001 100644 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG60Configurator.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG60Configurator.java @@ -31,7 +31,7 @@ import org.apache.maven.surefire.testset.TestSetFailedException; * @since 2.13 */ public class TestNG60Configurator - extends TestNG510Configurator + extends TestNG5143Configurator { Map<String, Object> getConvertedOptions( Map<String, String> options ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java index 50c1047..fcf9a91 100755 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java @@ -77,7 +77,7 @@ public class TestNGMapConfigurator Object val = entry.getValue(); if ( "listener".equals( key ) ) { - val = AbstractDirectConfigurator.loadListenerClasses( entry.getValue() ); + val = convertListeners( entry.getValue() ); } else if ( "objectfactory".equals( key ) ) { @@ -89,8 +89,9 @@ public class TestNGMapConfigurator } else if ( "reporter".equals( key ) ) { + // for TestNG 5.6 or higher // TODO support multiple reporters? - val = convertReporterConfig( val ); + val = convertReporterConfig( entry.getValue() ); key = "reporterslist"; } else if ( "junit".equals( key ) ) @@ -141,7 +142,7 @@ public class TestNGMapConfigurator } // ReporterConfig only became available in later versions of TestNG - private Object convertReporterConfig( Object val ) + protected Object convertReporterConfig( String val ) { final String reporterConfigClassName = "org.testng.ReporterConfig"; try @@ -159,6 +160,11 @@ public class TestNGMapConfigurator } } + protected Object convertListeners( String listenerClasses ) throws TestSetFailedException + { + return AbstractDirectConfigurator.loadListenerClasses( listenerClasses ); + } + protected Object convert( Object val, Class<?> type ) { if ( val == null ) http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG513ConfiguratorTest.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG513ConfiguratorTest.java b/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG513ConfiguratorTest.java new file mode 100644 index 0000000..1fbcda1 --- /dev/null +++ b/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG513ConfiguratorTest.java @@ -0,0 +1,72 @@ +package org.apache.maven.surefire.testng.conf; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import junit.framework.TestCase; +import org.apache.maven.surefire.testset.TestSetFailedException; + +import java.util.HashMap; +import java.util.Map; + +import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.FIRST_LISTENER; +import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.LISTENER_PROP; +import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.SECOND_LISTENER; + +public class TestNG513ConfiguratorTest + extends TestCase +{ + + public void testListenersOnSeparateLines() + throws Exception + { + String listenersOnSeveralLines = String.format( "%s , %n %s", + FIRST_LISTENER, SECOND_LISTENER ); + Map convertedOptions = getConvertedOptions( LISTENER_PROP, listenersOnSeveralLines ); + String listeners = (String) convertedOptions.get( String.format( "-%s", LISTENER_PROP ) ); + assertEquals( FIRST_LISTENER + "," + SECOND_LISTENER, listeners ); + } + + public void testListenersOnTheSameLine() + throws Exception + { + String listenersOnSeveralLines = String.format( "%s,%s", + FIRST_LISTENER, SECOND_LISTENER ); + Map convertedOptions = getConvertedOptions( LISTENER_PROP, listenersOnSeveralLines ); + String listeners = (String) convertedOptions.get( String.format( "-%s", LISTENER_PROP ) ); + assertEquals( FIRST_LISTENER + "," + SECOND_LISTENER, listeners ); + } + + public void testReporter() + throws Exception + { + Map<String, Object> convertedOptions = getConvertedOptions( "reporter", "classname" ); + String reporter = (String) convertedOptions.get( "-reporterslist" ); + assertEquals( "classname", reporter ); + } + + private Map getConvertedOptions( String key, String value ) + throws TestSetFailedException + { + TestNGMapConfigurator testNGMapConfigurator = new TestNG513Configurator(); + Map<String, String> raw = new HashMap<String, String>(); + raw.put( key, value ); + return testNGMapConfigurator.getConvertedOptions( raw ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG5141ConfiguratorTest.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG5141ConfiguratorTest.java b/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG5141ConfiguratorTest.java new file mode 100644 index 0000000..e253f3f --- /dev/null +++ b/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG5141ConfiguratorTest.java @@ -0,0 +1,78 @@ +package org.apache.maven.surefire.testng.conf; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import junit.framework.TestCase; +import org.apache.maven.surefire.testset.TestSetFailedException; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.*; + +public class TestNG5141ConfiguratorTest + extends TestCase +{ + + public void testListenersOnSeparateLines() + throws Exception + { + try + { + String listenersOnSeveralLines = String.format("%s , %n %s", + FIRST_LISTENER, SECOND_LISTENER); + Map convertedOptions = getConvertedOptions(LISTENER_PROP, listenersOnSeveralLines); + List listeners = (List) convertedOptions.get(String.format("-%s", LISTENER_PROP)); + assertEquals(2, listeners.size()); + fail(); + } + catch ( TestSetFailedException e ) + { + // TODO remove it when surefire will use "configure(CommandLineArgs)" + } + } + + public void testListenersOnTheSameLine() + throws Exception + { + try { + String listenersOnSeveralLines = String.format("%s,%s", + FIRST_LISTENER, SECOND_LISTENER); + Map convertedOptions = getConvertedOptions(LISTENER_PROP, listenersOnSeveralLines); + List listeners = (List) convertedOptions.get(String.format("-%s", LISTENER_PROP)); + assertEquals(2, listeners.size()); + fail(); + } + catch ( TestSetFailedException e ) + { + // TODO remove it when surefire will use "configure(CommandLineArgs)" + } + } + + private Map getConvertedOptions( String key, String value ) + throws TestSetFailedException + { + TestNGMapConfigurator testNGMapConfigurator = new TestNG5141Configurator(); + Map<String, String> raw = new HashMap<String, String>(); + raw.put( key, value ); + return testNGMapConfigurator.getConvertedOptions( raw ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG5143ConfiguratorTest.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG5143ConfiguratorTest.java b/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG5143ConfiguratorTest.java new file mode 100644 index 0000000..2ea5398 --- /dev/null +++ b/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNG5143ConfiguratorTest.java @@ -0,0 +1,72 @@ +package org.apache.maven.surefire.testng.conf; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; +import org.apache.maven.surefire.testset.TestSetFailedException; + +import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.FIRST_LISTENER; +import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.LISTENER_PROP; +import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.SECOND_LISTENER; + +public class TestNG5143ConfiguratorTest + extends TestCase +{ + public void testListenersOnSeparateLines() + throws Exception + { + String listenersOnSeveralLines = String.format( "%s , %n %s", + FIRST_LISTENER, SECOND_LISTENER); + Map convertedOptions = getConvertedOptions(LISTENER_PROP, listenersOnSeveralLines); + String listeners = (String) convertedOptions.get( String.format("-%s", LISTENER_PROP)); + assertEquals(FIRST_LISTENER + "," + SECOND_LISTENER, listeners); + } + + public void testListenersOnTheSameLine() + throws Exception + { + String listenersOnSeveralLines = String.format( "%s,%s", + FIRST_LISTENER, SECOND_LISTENER); + Map convertedOptions = getConvertedOptions( LISTENER_PROP, listenersOnSeveralLines); + String listeners = (String) convertedOptions.get( String.format("-%s", LISTENER_PROP)); + assertEquals(FIRST_LISTENER + "," + SECOND_LISTENER, listeners); + } + + public void testReporter() + throws Exception + { + Map<String, Object> convertedOptions = getConvertedOptions( "reporter", "classname" ); + assertNull( "classname", convertedOptions.get( "-reporterslist" ) ); + String reporter = (String) convertedOptions.get("-reporter" ); + assertEquals( "classname", reporter ); + } + + private Map getConvertedOptions( String key, String value ) + throws TestSetFailedException + { + TestNGMapConfigurator testNGMapConfigurator = new TestNG5143Configurator(); + Map<String, String> raw = new HashMap<String, String>(); + raw.put( key, value ); + return testNGMapConfigurator.getConvertedOptions( raw ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7fe7a2a3/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNGMapConfiguratorTest.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNGMapConfiguratorTest.java b/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNGMapConfiguratorTest.java index 06cf30d..28bba7c 100755 --- a/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNGMapConfiguratorTest.java +++ b/surefire-providers/surefire-testng/src/test/java/org/apache/maven/surefire/testng/conf/TestNGMapConfiguratorTest.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.maven.surefire.testset.TestSetFailedException; import junit.framework.TestCase; +import org.testng.ReporterConfig; /** * @author Kristian Rosenvold @@ -33,8 +34,8 @@ import junit.framework.TestCase; public class TestNGMapConfiguratorTest extends TestCase { - private static final String FIRST_LISTENER = "org.testng.TestListenerAdapter"; - private static final String SECOND_LISTENER = "org.testng.reporters.ExitCodeListener"; + public static final String FIRST_LISTENER = "org.testng.TestListenerAdapter"; + public static final String SECOND_LISTENER = "org.testng.reporters.ExitCodeListener"; public static final String LISTENER_PROP = "listener"; public void testGetConvertedOptions() @@ -73,6 +74,15 @@ public class TestNGMapConfiguratorTest assertTrue( bool ); } + public void testReporter() + throws Exception + { + Map<String, Object> convertedOptions = getConvertedOptions( "reporter", "classname" ); + List<ReporterConfig> reporter = (List) convertedOptions.get( "-reporterslist" ); + ReporterConfig reporterConfig = reporter.get( 0 ); + assertEquals( "classname", reporterConfig.getClassName() ); + } + private Map getConvertedOptions( String key, String value ) throws TestSetFailedException {