View Javadoc
1   package org.apache.maven.surefire.its.jiras;
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.maven.surefire.its.fixture.OutputValidator;
23  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
24  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
25  import org.junit.Test;
26  
27  import java.io.File;
28  import java.io.FilenameFilter;
29  
30  import static org.fest.assertions.Assertions.assertThat;
31  
32  /**
33   * @author Kristian Rosenvold
34   */
35  public class Surefire735ForkFailWithRedirectConsoleOutputIT
36          extends SurefireJUnit4IntegrationTestCase
37  {
38  
39      @Test
40      public void vmStartFail()
41              throws Exception
42      {
43          OutputValidator outputValidator = unpack().failNever().executeTest();
44          assertJvmCrashed( outputValidator );
45      }
46  
47      @Test
48      public void vmStartFailShouldFailBuildk()
49              throws Exception
50      {
51          OutputValidator outputValidator = unpack().maven().withFailure().executeTest();
52          assertJvmCrashed( outputValidator );
53      }
54  
55      private SurefireLauncher unpack()
56      {
57          return unpack( "fork-fail" );
58      }
59  
60      private static void assertJvmCrashed( OutputValidator outputValidator )
61      {
62          File reportDir = outputValidator.getSurefireReportsDirectory();
63          String[] dumpFiles = reportDir.list( new FilenameFilter()
64                                               {
65                                                   @Override
66                                                   public boolean accept( File dir, String name )
67                                                   {
68                                                       return name.endsWith( ".dumpstream" );
69                                                   }
70                                               }
71          );
72          assertThat( dumpFiles ).isNotEmpty();
73          for ( String dump : dumpFiles )
74          {
75              outputValidator.getSurefireReportsFile( dump )
76                      .assertContainsText( "Invalid maximum heap size: -Xmxxxx712743m" );
77          }
78      }
79  
80  }