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.jiras;
20
21 import java.io.File;
22 import java.io.FilenameFilter;
23
24 import org.apache.maven.surefire.its.fixture.OutputValidator;
25 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
26 import org.apache.maven.surefire.its.fixture.SurefireVerifierException;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29
30 import static org.assertj.core.api.Assertions.assertThat;
31
32
33
34
35
36
37 public class Surefire141PluggableProvidersIT extends SurefireJUnit4IntegrationTestCase {
38 @BeforeClass
39 public static void installProvider() {
40 unpack(Surefire141PluggableProvidersIT.class, "surefire-141-pluggableproviders-provider", "prov")
41 .executeInstall();
42 }
43
44 @Test
45 public void pluggableProviderPresent() {
46 unpack("surefire-141-pluggableproviders")
47 .setForkJvm()
48 .maven()
49 .showExceptionMessages()
50 .debugLogging()
51 .executeTest()
52 .verifyTextInLog("Using configured provider org.apache.maven.surefire.testprovider.TestProvider")
53 .verifyTextInLog("Using configured provider org.apache.maven.surefire.junit.JUnit3Provider")
54 .verifyErrorFreeLog();
55 }
56
57 @Test
58 public void invokeRuntimeException() {
59 final String errorText = "Let's fail with a runtimeException";
60
61 OutputValidator validator = unpack("surefire-141-pluggableproviders")
62 .setForkJvm()
63 .sysProp("invokeCrash", "runtimeException")
64 .maven()
65 .withFailure()
66 .executeTest();
67
68 assertErrorMessage(validator, errorText);
69
70 boolean hasErrorInLog = verifiedErrorInLog(validator, "There was an error in the forked process");
71 boolean verifiedInLog = verifiedErrorInLog(validator, errorText);
72 assertThat(hasErrorInLog && verifiedInLog)
73 .describedAs("'" + errorText + "' could not be verified in log.txt nor *.dump file. (" + hasErrorInLog
74 + ", " + verifiedInLog + ")")
75 .isTrue();
76 }
77
78 @Test
79 public void invokeReporterException() {
80 final String errorText = "Let's fail with a reporterexception";
81
82 OutputValidator validator = unpack("surefire-141-pluggableproviders")
83 .setForkJvm()
84 .sysProp("invokeCrash", "reporterException")
85 .maven()
86 .withFailure()
87 .executeTest();
88
89 assertErrorMessage(validator, errorText);
90
91 boolean hasErrorInLog = verifiedErrorInLog(validator, "There was an error in the forked process");
92 boolean verifiedInLog = verifiedErrorInLog(validator, errorText);
93 assertThat(hasErrorInLog && verifiedInLog)
94 .describedAs("'" + errorText + "' could not be verified in log.txt nor *.dump file. (" + hasErrorInLog
95 + ", " + verifiedInLog + ")")
96 .isTrue();
97 }
98
99 @Test
100 public void constructorRuntimeException() {
101 final String errorText = "Let's fail with a runtimeException";
102
103 OutputValidator validator = unpack("surefire-141-pluggableproviders")
104 .setForkJvm()
105 .sysProp("constructorCrash", "runtimeException")
106 .maven()
107 .withFailure()
108 .executeTest();
109
110 assertErrorMessage(validator, errorText);
111
112 boolean hasErrorInLog = verifiedErrorInLog(validator, "There was an error in the forked process");
113 boolean verifiedInLog = verifiedErrorInLog(validator, errorText);
114 assertThat(hasErrorInLog && verifiedInLog)
115 .describedAs("'" + errorText + "' could not be verified in log.txt nor *.dump file. (" + hasErrorInLog
116 + ", " + verifiedInLog + ")")
117 .isTrue();
118 }
119
120 private static void assertErrorMessage(OutputValidator validator, String message) {
121 File reportDir = validator.getSurefireReportsDirectory();
122 String[] dumpFiles = reportDir.list(new FilenameFilter() {
123 @Override
124 public boolean accept(File dir, String name) {
125 return name.endsWith("-jvmRun1.dump");
126 }
127 });
128 assertThat(dumpFiles).isNotNull().isNotEmpty();
129 for (String dump : dumpFiles) {
130 validator.getSurefireReportsFile(dump).assertContainsText(message);
131 }
132 }
133
134 private static boolean verifiedErrorInLog(OutputValidator validator, String errorText) {
135 try {
136 validator.verifyTextInLog(errorText);
137 return true;
138 } catch (SurefireVerifierException e) {
139 return false;
140 }
141 }
142 }