1 package org.apache.maven.plugin.surefire.booterclient;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23 import org.apache.maven.surefire.booter.Classpath;
24 import org.apache.maven.surefire.booter.SurefireBooterForkException;
25 import org.codehaus.plexus.util.StringUtils;
26 import org.codehaus.plexus.util.cli.Commandline;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.util.Collections;
31
32 public class ForkConfigurationTest
33 extends TestCase
34 {
35
36 public void testCreateCommandLine_UseSystemClassLoaderForkOnce_ShouldConstructManifestOnlyJar()
37 throws IOException, SurefireBooterForkException
38 {
39 ForkConfiguration config = getForkConfiguration();
40 File cpElement = getTempClasspathFile();
41 config.setJvmExecutable( "java" );
42
43 Commandline cli = config.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath() ), true,
44 false );
45
46 String line = StringUtils.join( cli.getCommandline(), " " );
47 assertTrue( line.indexOf( "-jar" ) > -1 );
48 }
49
50 public void testArglineWithNewline()
51 throws IOException, SurefireBooterForkException
52 {
53
54 File cpElement = getTempClasspathFile();
55 ForkConfiguration forkConfiguration = getForkConfiguration();
56
57 forkConfiguration.setArgLine( "abc\ndef" );
58
59 final Commandline commandLine =
60 forkConfiguration.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath() ), false,
61 false );
62 assertTrue( commandLine.toString().contains( "abc def" ) );
63 }
64
65 private File getTempClasspathFile()
66 throws IOException
67 {
68 File cpElement = File.createTempFile( "ForkConfigurationTest.", ".file" );
69 cpElement.deleteOnExit();
70 return cpElement;
71 }
72
73 public static ForkConfiguration getForkConfiguration()
74 throws IOException
75 {
76 ForkConfiguration forkConfiguration = new ForkConfiguration( new Classpath(), ForkConfiguration.FORK_ONCE, null );
77 forkConfiguration.setWorkingDirectory( new File( "." ).getCanonicalFile() );
78 return forkConfiguration;
79 }
80
81 }