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.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.IOException;
29  
30  import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS;
31  import static org.fest.assertions.Assertions.assertThat;
32  import static org.hamcrest.CoreMatchers.containsString;
33  import static org.hamcrest.CoreMatchers.is;
34  import static org.junit.Assume.assumeTrue;
35  
36  /**
37   * Testing long path of base.dir where Windows CLI crashes.
38   * <br>
39   * Integration test for <a href="https://issues.apache.org/jira/browse/SUREFIRE-1400">SUREFIRE-1400</a>.
40   *
41   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
42   * @since 2.20.1
43   */
44  public class LongWindowsPathIT
45          extends SurefireJUnit4IntegrationTestCase
46  {
47      private static final String PROJECT_DIR = "long-windows-path";
48      private static final String LONG_PATH = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
49  
50      // the IT engine crashes using long path
51      private static final String LONG_DIR = LONG_PATH + LONG_PATH + LONG_PATH;
52  
53      @Test
54      public void shouldRunInSystemTmp() throws Exception
55      {
56          assumeTrue( IS_OS_WINDOWS );
57  
58          OutputValidator validator = unpack().setForkJvm()
59                                              .showErrorStackTraces()
60                                              .executeTest()
61                                              .verifyErrorFreeLog();
62  
63          validator.assertThatLogLine( containsString( "SUREFIRE-1400 user.dir=" ), is( 1 ) )
64                  .assertThatLogLine( containsString( "SUREFIRE-1400 surefire.real.class.path=" ), is( 1 ) );
65  
66          for ( String line : validator.loadLogLines() )
67          {
68              if ( line.contains( "SUREFIRE-1400 user.dir=" ) )
69              {
70                  File buildDir = new File( System.getProperty( "user.dir" ), "target" );
71                  File itBaseDir = new File( buildDir, "LongWindowsPathIT_shouldRunInSystemTmp" );
72  
73                  assertThat( line )
74                          .contains( itBaseDir.getAbsolutePath() );
75              }
76              else if ( line.contains( "SUREFIRE-1400 surefire.real.class.path=" ) )
77              {
78                  assertThat( line )
79                          .contains( System.getProperty( "java.io.tmpdir" ) );
80              }
81          }
82      }
83  
84      private SurefireLauncher unpack() throws IOException
85      {
86          return unpack( PROJECT_DIR/*, "_" + LONG_DIR*/ );
87      }
88  }