Build fix (linux-jdk12-maven3.2.x) Surefire1535TestNGParallelSuitesIT.forks2Redirecte...
authorTibor17 <tibordigana@apache.org>
Wed, 19 Dec 2018 00:01:36 +0000 (01:01 +0100)
committerTibor17 <tibordigana@apache.org>
Wed, 19 Dec 2018 04:54:05 +0000 (05:54 +0100)
surefire-its/src/test/java/org/apache/maven/surefire/its/fixture/TestFile.java
surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1535TestNGParallelSuitesIT.java
surefire-its/src/test/resources/surefire-1535-parallel-testng/pom.xml

index 29e8038..f7f05f7 100644 (file)
@@ -23,8 +23,8 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.net.URI;
 import java.nio.charset.Charset;
 import java.util.List;
@@ -33,6 +33,7 @@ import org.apache.commons.io.FileUtils;
 import junit.framework.Assert;
 import org.hamcrest.Matcher;
 
+import static java.nio.charset.Charset.defaultCharset;
 import static junit.framework.Assert.assertTrue;
 import static org.hamcrest.Matchers.containsString;
 
@@ -49,7 +50,7 @@ public class TestFile
 
     public TestFile( File file, OutputValidator surefireVerifier )
     {
-        this( file, Charset.defaultCharset(), surefireVerifier);
+        this( file, defaultCharset(), surefireVerifier);
     }
 
     public TestFile( File file, Charset charset, OutputValidator surefireVerifier )
@@ -57,7 +58,7 @@ public class TestFile
         try
         {
             this.file = file.getCanonicalFile();
-            this.encoding = charset == null ? Charset.defaultCharset() : charset;
+            this.encoding = charset == null ? defaultCharset() : charset;
             this.surefireVerifier = surefireVerifier;
         }
         catch ( IOException e )
@@ -103,7 +104,7 @@ public class TestFile
     public String slurpFile()
     {
         StringBuilder sb = new StringBuilder();
-        try ( BufferedReader reader = new BufferedReader( new FileReader( file ) ) )
+        try ( BufferedReader reader = new BufferedReader( new InputStreamReader( getFileInputStream(), encoding ) ) )
         {
             for ( String line = reader.readLine(); line != null; line = reader.readLine() )
             {
@@ -121,7 +122,7 @@ public class TestFile
     {
         try
         {
-            return FileUtils.readFileToString( file );
+            return FileUtils.readFileToString( file, encoding );
         }
         catch ( IOException e )
         {
index ec6ea34..b6e534e 100644 (file)
@@ -31,6 +31,7 @@ import java.nio.charset.Charset;
 import static org.hamcrest.CoreMatchers.anyOf;
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.is;
+import static org.fest.assertions.Assertions.assertThat;
 
 public class Surefire1535TestNGParallelSuitesIT
         extends SurefireJUnit4IntegrationTestCase
@@ -38,8 +39,8 @@ public class Surefire1535TestNGParallelSuitesIT
     private static final Charset UTF8 = Charset.forName( "UTF-8" );
     private static final String TEST_RESULT_1 = platformEncoding( "Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, " );
     private static final String TEST_RESULT_2 = platformEncoding( "Tests run: 2, Failures: 0, Errors: 0, Skipped: 0" );
-    private static final String SUITE1 = platformEncoding( "Suite1.xml" );
-    private static final String SUITE2 = platformEncoding( "Suite2.xml" );
+    private static final String SUITE1 = platformEncoding( "Suite1" );
+    private static final String SUITE2 = platformEncoding( "Suite2" );
     private static final String TEST1 = platformEncoding( "test 1" );
     private static final String TEST2 = platformEncoding( "test 2" );
     private static final String TEST_SUITE = platformEncoding( "Running TestSuite" );
@@ -55,10 +56,23 @@ public class Surefire1535TestNGParallelSuitesIT
         TestFile testFile = validator.getSurefireReportsFile( "../surefire-reports-1/TEST-TestSuite.xml", UTF8 );
         testFile.assertFileExists();
         testFile.assertContainsText( "<testcase name=\"test\" classname=\"it.ParallelTest" );
+        String xml = testFile.readFileToString();
+        boolean parallelTest11 = xml.contains( "<testcase name=\"test\" classname=\"it.ParallelTest1\"" );
+        boolean parallelTest12 = xml.contains( "<testcase name=\"test\" classname=\"it.ParallelTest2\"" );
+        assertThat( parallelTest11 ^ parallelTest12 )
+                .isTrue();
 
         testFile = validator.getSurefireReportsFile( "../surefire-reports-2/TEST-TestSuite.xml", UTF8 );
         testFile.assertFileExists();
         testFile.assertContainsText( "<testcase name=\"test\" classname=\"it.ParallelTest" );
+        xml = testFile.readFileToString();
+        boolean parallelTest21 = xml.contains( "<testcase name=\"test\" classname=\"it.ParallelTest1\"" );
+        boolean parallelTest22 = xml.contains( "<testcase name=\"test\" classname=\"it.ParallelTest2\"" );
+        assertThat( parallelTest21 ^ parallelTest22 )
+                .isTrue();
+
+        assertThat( parallelTest11 && parallelTest22 || parallelTest12 && parallelTest21 )
+                .isTrue();
 
         validator.assertThatLogLine( containsString( TEST_RESULT_2 ), is( 1 ) )
                 .assertThatLogLine( containsString( TEST_RESULT_1 ), is( 2 ) )
@@ -81,10 +95,43 @@ public class Surefire1535TestNGParallelSuitesIT
         TestFile testFile = validator.getSurefireReportsFile( "../surefire-reports-1/TEST-TestSuite.xml", UTF8 );
         testFile.assertFileExists();
         testFile.assertContainsText( "<testcase name=\"test\" classname=\"it.ParallelTest" );
+        String xml = testFile.readFileToString();
+        boolean parallelTest11 = xml.contains( "<testcase name=\"test\" classname=\"it.ParallelTest1\"" );
+        boolean parallelTest12 = xml.contains( "<testcase name=\"test\" classname=\"it.ParallelTest2\"" );
+        assertThat( parallelTest11 ^ parallelTest12 )
+                .isTrue();
+        String log = validator.getSurefireReportsFile( "../surefire-reports-1/TestSuite-output.txt", UTF8 )
+                .readFileToString();
+        assertThat( log.contains( TEST1 ) )
+                .isEqualTo( parallelTest11 );
+        assertThat( log.contains( SUITE1 ) )
+                .isEqualTo( parallelTest11 );
+        assertThat( log.contains( TEST2 ) )
+                .isEqualTo( parallelTest12 );
+        assertThat( log.contains( SUITE2 ) )
+                .isEqualTo( parallelTest12 );
 
         testFile = validator.getSurefireReportsFile( "../surefire-reports-2/TEST-TestSuite.xml", UTF8 );
         testFile.assertFileExists();
         testFile.assertContainsText( "<testcase name=\"test\" classname=\"it.ParallelTest" );
+        xml = testFile.readFileToString();
+        boolean parallelTest21 = xml.contains( "<testcase name=\"test\" classname=\"it.ParallelTest1\"" );
+        boolean parallelTest22 = xml.contains( "<testcase name=\"test\" classname=\"it.ParallelTest2\"" );
+        assertThat( parallelTest21 ^ parallelTest22 )
+                .isTrue();
+        log = validator.getSurefireReportsFile( "../surefire-reports-2/TestSuite-output.txt", UTF8 )
+                .readFileToString();
+        assertThat( log.contains( TEST1 ) )
+                .isEqualTo( parallelTest21 );
+        assertThat( log.contains( SUITE1 ) )
+                .isEqualTo( parallelTest21 );
+        assertThat( log.contains( TEST2 ) )
+                .isEqualTo( parallelTest22 );
+        assertThat( log.contains( SUITE2 ) )
+                .isEqualTo( parallelTest22 );
+
+        assertThat( parallelTest11 && parallelTest22 || parallelTest12 && parallelTest21 )
+                .isTrue();
 
         validator.assertThatLogLine( containsString( TEST_RESULT_2 ), is( 1 ) )
                 .assertThatLogLine( containsString( TEST_RESULT_1 ), is( 2 ) )
index 4fcc715..6aa6599 100644 (file)
@@ -37,8 +37,8 @@
         <dependency>
             <groupId>org.testng</groupId>
             <artifactId>testng</artifactId>
-            <version>5.7</version>
-            <classifier>jdk15</classifier>
+            <version>6.13.1</version>
+            <scope>test</scope>
         </dependency>
     </dependencies>
 
                         <suiteXmlFile>src/test/resources/Suite1.xml</suiteXmlFile>
                         <suiteXmlFile>src/test/resources/Suite2.xml</suiteXmlFile>
                     </suiteXmlFiles>
+                    <properties>
+                        <property>
+                            <name>surefire.testng.verbose</name>
+                            <value>1</value>
+                        </property>
+                    </properties>
                 </configuration>
             </plugin>
         </plugins>