1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.its;
20
21 import java.util.ArrayList;
22
23 import org.apache.maven.surefire.its.fixture.OutputValidator;
24 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
25 import org.apache.maven.surefire.its.fixture.SurefireLauncher;
26 import org.apache.maven.surefire.its.fixture.TestFile;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.Parameterized;
30 import org.junit.runners.Parameterized.Parameter;
31 import org.junit.runners.Parameterized.Parameters;
32
33 import static java.nio.charset.StandardCharsets.UTF_8;
34 import static org.hamcrest.Matchers.containsString;
35 import static org.hamcrest.Matchers.equalTo;
36
37
38
39
40
41
42 @RunWith(Parameterized.class)
43 public class ConsoleOutputIT extends SurefireJUnit4IntegrationTestCase {
44 private static final String LEGACY_FORK_NODE = "org.apache.maven.plugin.surefire.extensions.LegacyForkNodeFactory";
45
46 private static final String SUREFIRE_FORK_NODE =
47 "org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory";
48
49 @Parameters
50 public static Iterable<Object[]> data() {
51 ArrayList<Object[]> args = new ArrayList<>();
52 args.add(new Object[] {"tcp"});
53 args.add(new Object[] {null});
54 return args;
55 }
56
57 @Parameter
58 @SuppressWarnings("checkstyle:visibilitymodifier")
59 public String profileId;
60
61 @Test
62 public void properNewlinesAndEncodingWithDefaultEncodings() throws Exception {
63 OutputValidator outputValidator = unpack().forkOnce().executeTest();
64 validate(outputValidator, true);
65 }
66
67 @Test
68 public void properNewlinesAndEncodingWithDifferentEncoding() throws Exception {
69 OutputValidator outputValidator =
70 unpack().forkOnce().argLine("-Dfile.encoding=UTF-16").executeTest();
71 validate(outputValidator, true);
72 }
73
74 @Test
75 public void properNewlinesAndEncodingWithoutFork() throws Exception {
76 OutputValidator outputValidator = unpack().forkNever().executeTest();
77 validate(outputValidator, false);
78 }
79
80 private SurefireLauncher unpack() {
81 SurefireLauncher launcher = unpack("/consoleOutput", profileId == null ? "" : "-" + profileId)
82 .debugLogging();
83
84 if (profileId != null) {
85 launcher.activateProfile(profileId);
86 }
87
88 return launcher;
89 }
90
91 private void validate(final OutputValidator outputValidator, boolean canFork) throws Exception {
92 TestFile xmlReportFile = outputValidator.getSurefireReportsXmlFile("TEST-consoleOutput.Test1.xml");
93 xmlReportFile.assertContainsText("SoutLine");
94 xmlReportFile.assertContainsText("äöüß");
95 xmlReportFile.assertContainsText("failing with ü");
96
97 TestFile outputFile = outputValidator.getSurefireReportsFile("consoleOutput.Test1-output.txt", UTF_8);
98 outputFile.assertContainsText("SoutAgain");
99 outputFile.assertContainsText("SoutLine");
100 outputFile.assertContainsText("äöüß");
101
102 String cls = profileId == null ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
103
104 if (canFork) {
105 outputValidator.assertThatLogLine(
106 containsString("Found implementation of fork node factory: " + cls), equalTo(1));
107 }
108 }
109
110 @Test
111 public void largerSoutThanMemory() throws Exception {
112 SurefireLauncher launcher = unpackNoisy().setMavenOpts("-Xmx64m").sysProp("thousand", "32000");
113
114 String cls = profileId == null ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
115
116 launcher.executeTest()
117 .verifyErrorFreeLog()
118 .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
119 }
120
121 private SurefireLauncher unpackNoisy() {
122 SurefireLauncher launcher = unpack("consoleoutput-noisy", profileId == null ? "" : "-" + profileId)
123 .debugLogging();
124
125 if (profileId != null) {
126 launcher.activateProfile(profileId);
127 }
128
129 return launcher;
130 }
131 }