View Javadoc

1   package org.apache.maven.plugin.surefire.booterclient;
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 java.io.File;
23  import java.io.IOException;
24  import java.util.Collections;
25  
26  import org.apache.maven.shared.utils.StringUtils;
27  import org.apache.maven.shared.utils.cli.Commandline;
28  import org.apache.maven.surefire.booter.Classpath;
29  import org.apache.maven.surefire.booter.SurefireBooterForkException;
30  
31  import junit.framework.TestCase;
32  
33  public class ForkConfigurationTest
34      extends TestCase
35  {
36  
37      public void testCreateCommandLine_UseSystemClassLoaderForkOnce_ShouldConstructManifestOnlyJar()
38          throws IOException, SurefireBooterForkException
39      {
40          ForkConfiguration config = getForkConfiguration( null, "java" );
41          File cpElement = getTempClasspathFile();
42  
43          Commandline cli =
44              config.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath() ), true, false, null, 1 );
45  
46          String line = StringUtils.join( cli.getCommandline(), " " );
47          assertTrue( line.contains( "-jar" ) );
48      }
49  
50      public void testArglineWithNewline()
51          throws IOException, SurefireBooterForkException
52      {
53          // SUREFIRE-657
54          File cpElement = getTempClasspathFile();
55          ForkConfiguration forkConfiguration = getForkConfiguration( "abc\ndef", null );
56  
57          final Commandline commandLine =
58              forkConfiguration.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath() ), false, false,
59                                                   null, 1 );
60          assertTrue( commandLine.toString().contains( "abc def" ) );
61      }
62  
63      private File getTempClasspathFile()
64          throws IOException
65      {
66          File cpElement = File.createTempFile( "ForkConfigurationTest.", ".file" );
67          cpElement.deleteOnExit();
68          return cpElement;
69      }
70  
71      public static ForkConfiguration getForkConfiguration( String argLine, String jvm )
72          throws IOException
73      {
74          return new ForkConfiguration( Classpath.emptyClasspath(), null, null, jvm, new File( "." ).getCanonicalFile(), argLine,
75                                        null, false, 1, false );
76      }
77  
78  }