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