View Javadoc
1   package org.apache.maven.surefire.its;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.lang3.JavaVersion;
23  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
24  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
25  import org.junit.Test;
26  import org.junit.runner.RunWith;
27  import org.junit.runners.Parameterized;
28  
29  import java.util.Arrays;
30  import java.util.Collection;
31  
32  import static org.apache.commons.lang3.JavaVersion.JAVA_1_5;
33  import static org.apache.commons.lang3.JavaVersion.JAVA_1_7;
34  import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion;
35  import static org.junit.runners.Parameterized.Parameter;
36  import static org.junit.runners.Parameterized.Parameters;
37  
38  /**
39   * Test simple TestNG listener and reporter
40   *
41   * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
42   * @author <a href="mailto:krosenvold@apache.org">Kristian Rosenvold</a>
43   */
44  @RunWith( Parameterized.class )
45  public class CheckTestNgListenerReporterIT
46      extends SurefireJUnit4IntegrationTestCase
47  {
48      @Parameters( name = "{index}: TestNG {0}" )
49      public static Collection<Object[]> data()
50      {
51          return Arrays.asList(new Object[][] {
52              { "5.6", "jdk15", JAVA_1_5 }, // First TestNG version with reporter support
53              { "5.7", "jdk15", JAVA_1_5 }, // default version from pom of the test case
54              { "5.10", "jdk15", JAVA_1_5 },
55              { "5.13", null, JAVA_1_5 }, // "reporterslist" param becomes String instead of List<ReporterConfig>
56                          // "listener" param becomes String instead of List<Class>
57  
58                  // configure(Map) in 5.14.1 and 5.14.2 is transforming List<Class> into a String with a space as separator.
59                  // Then configure(CommandLineArgs) splits this String into a List<String> with , or ; as separator => fail.
60                  // If we used configure(CommandLineArgs), we would not have the problem with white spaces.
61              //{ "5.14.1", null, "1.5" }, // "listener" param becomes List instead of String
62                              // Fails: Issue with 5.14.1 and 5.14.2 => join with <space>, split with ","
63                              // TODO will work with "configure(CommandLineArgs)"
64              //{ "5.14.2", null, "1.5" }, // ReporterConfig is not available
65  
66              //{ "5.14.3", null, "1.5" }, // TestNG uses "reporter" instead of "reporterslist"
67                            // Both String or List are possible for "listener"
68                            // Fails: not able to test due to system dependency org.testng:guice missed the path and use to break CI
69                            // ClassNotFoundException: com.beust.jcommander.ParameterException
70  
71              //{ "5.14.4", null, "1.5" }, { "5.14.5", null, "1.5" }, // Fails: not able to test due to system dependency org.testng:guice missed the path and use to break CI
72                                          // ClassNotFoundException: com.beust.jcommander.ParameterException
73  
74              { "5.14.6", null, JAVA_1_5 }, // Usage of org.testng:guice removed
75              { "5.14.9", null, JAVA_1_5 }, // Latest 5.14.x TestNG version
76              { "6.0", null, JAVA_1_5 },
77              { "6.9.9", null, JAVA_1_7 } // Currently latest TestNG version
78          });
79      }
80  
81      @Parameter
82      public String version;
83  
84      @Parameter(1)
85      public String classifier;
86  
87      @Parameter(2)
88      public JavaVersion javaVersion;
89  
90      @Test
91      public void testNgListenerReporter()
92      {
93          assumeJavaVersion( javaVersion );
94          final SurefireLauncher launcher = unpack( "testng-listener-reporter", "_" + version )
95                                                    .sysProp( "testNgVersion", version );
96  
97          if ( classifier != null )
98          {
99              launcher.sysProp( "testNgClassifier", "jdk15" );
100         }
101 
102         launcher.executeTest()
103                 .verifyErrorFree( 1 )
104                 .getTargetFile( "resultlistener-output.txt" ).assertFileExists()
105                 .getTargetFile( "suitelistener-output.txt" ).assertFileExists()
106                 .getTargetFile( "reporter-output.txt" ).assertFileExists();
107     }
108 }