1 package org.apache.maven.surefire.its;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.util.List;
25 import java.util.Properties;
26
27 import org.apache.maven.it.Verifier;
28 import org.apache.maven.it.util.ResourceExtractor;
29 import org.apache.maven.surefire.its.misc.HelperAssertions;
30
31
32
33
34
35
36 public class WorkingDirectoryIT
37 extends AbstractSurefireIntegrationTestClass
38 {
39
40 private File testDir;
41
42 private File childTestDir;
43
44 private File targetDir;
45
46 private File outFile;
47
48 public void setUp()
49 throws IOException
50 {
51 testDir = ResourceExtractor.simpleExtractResources( getClass(), "/working-directory" );
52 childTestDir = new File( testDir, "child" );
53 targetDir = new File( childTestDir, "target" );
54 outFile = new File( targetDir, "out.txt" );
55 outFile.delete();
56 }
57
58 public void testWorkingDirectory()
59 throws Exception
60 {
61 Verifier verifier = new Verifier( testDir.getAbsolutePath() );
62 this.executeGoal( verifier, "test" );
63 verifier.verifyErrorFreeLog();
64 verifier.resetStreams();
65
66 HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, childTestDir );
67 verifyOutputDirectory( childTestDir );
68 }
69
70 public void verifyOutputDirectory( File childTestDir )
71 throws IOException
72 {
73 assertTrue( "out.txt doesn't exist: " + outFile.getAbsolutePath(), outFile.exists() );
74 Properties p = new Properties();
75 FileInputStream is = new FileInputStream( outFile );
76 p.load( is );
77 is.close();
78 String userDirPath = p.getProperty( "user.dir" );
79 assertNotNull( "user.dir was null in property file", userDirPath );
80 File userDir = new File( userDirPath );
81
82 if ( childTestDir.getCanonicalFile().equals( childTestDir.getAbsoluteFile() ) )
83 {
84 assertEquals( "wrong user.dir ! symlink ", childTestDir.getAbsolutePath(), userDir.getAbsolutePath() );
85 }
86 else
87 {
88 assertEquals( "wrong user.dir symlink ", childTestDir.getCanonicalPath(), userDir.getCanonicalPath() );
89 }
90 }
91
92 public void testWorkingDirectoryNoFork()
93 throws Exception
94 {
95 Verifier verifier = new Verifier( testDir.getAbsolutePath() );
96 List<String> goals = this.getInitialGoals();
97 goals.add( "test" );
98 goals.add( "-DforkMode=never" );
99 executeGoals( verifier, goals );
100 verifier.verifyErrorFreeLog();
101 verifier.resetStreams();
102
103 HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, childTestDir );
104 verifyOutputDirectory( childTestDir );
105 }
106
107 public void testWorkingDirectoryChildOnly()
108 throws Exception
109 {
110 Verifier verifier = new Verifier( childTestDir.getAbsolutePath() );
111 this.executeGoal( verifier, "test" );
112 verifier.verifyErrorFreeLog();
113 verifier.resetStreams();
114
115 HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, childTestDir );
116 verifyOutputDirectory( childTestDir );
117 }
118
119 public void testWorkingDirectoryChildOnlyNoFork()
120 throws Exception
121 {
122
123 Verifier verifier = new Verifier( childTestDir.getAbsolutePath() );
124 List<String> goals = this.getInitialGoals();
125 goals.add( "test" );
126 goals.add( "-DforkMode=never" );
127 executeGoals( verifier, goals );
128 verifier.verifyErrorFreeLog();
129 verifier.resetStreams();
130
131 HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, childTestDir );
132 verifyOutputDirectory( childTestDir );
133 }
134 }