119 "JVM process should have exit value '%d'.%n%s", |
119 "JVM process should have exit value '%d'.%n%s", |
120 exitCode.value, exitErrorMessage); |
120 exitCode.value, exitErrorMessage); |
121 throw new AssertionError(errorMessage, e); |
121 throw new AssertionError(errorMessage, e); |
122 } |
122 } |
123 |
123 |
124 |
124 verifyOutput(expectedMessages, unexpectedMessages, |
|
125 wrongWarningMessage, outputAnalyzer); |
|
126 } |
|
127 |
|
128 /** |
|
129 * Verifies that JVM startup behavior matches our expectations. |
|
130 * |
|
131 * @param expectedMessages an array of patterns that should occur in JVM |
|
132 * output. If {@code null} then |
|
133 * JVM output could be empty. |
|
134 * @param unexpectedMessages an array of patterns that should not occur |
|
135 * in JVM output. If {@code null} then |
|
136 * JVM output could be empty. |
|
137 * @param wrongWarningMessage message that will be shown if messages are |
|
138 * not as expected. |
|
139 * @param outputAnalyzer OutputAnalyzer instance |
|
140 * @throws AssertionError if verification fails. |
|
141 */ |
|
142 public static void verifyOutput(String[] expectedMessages, |
|
143 String[] unexpectedMessages, String wrongWarningMessage, |
|
144 OutputAnalyzer outputAnalyzer) { |
125 if (expectedMessages != null) { |
145 if (expectedMessages != null) { |
126 for (String expectedMessage : expectedMessages) { |
146 for (String expectedMessage : expectedMessages) { |
127 try { |
147 try { |
128 outputAnalyzer.shouldMatch(expectedMessage); |
148 outputAnalyzer.shouldMatch(expectedMessage); |
129 } catch (RuntimeException e) { |
149 } catch (RuntimeException e) { |
197 * @throws Throwable if verification fails or some other issues occur. |
217 * @throws Throwable if verification fails or some other issues occur. |
198 */ |
218 */ |
199 public static void verifyOptionValue(String optionName, |
219 public static void verifyOptionValue(String optionName, |
200 String expectedValue, String optionErrorString, |
220 String expectedValue, String optionErrorString, |
201 String... additionalVMOpts) throws Throwable { |
221 String... additionalVMOpts) throws Throwable { |
202 verifyOptionValue(optionName, expectedValue, optionErrorString, |
222 verifyOptionValue(optionName, expectedValue, optionErrorString, |
203 true, additionalVMOpts); |
223 true, additionalVMOpts); |
204 } |
224 } |
205 |
225 |
206 /** |
226 /** |
207 * Verifies that value of specified JVM option is the same as |
227 * Verifies that value of specified JVM option is the same as |
245 String errorMessage = String.format( |
265 String errorMessage = String.format( |
246 "JVM should start with option '%s' without errors.", |
266 "JVM should start with option '%s' without errors.", |
247 optionName); |
267 optionName); |
248 throw new AssertionError(errorMessage, e); |
268 throw new AssertionError(errorMessage, e); |
249 } |
269 } |
|
270 verifyOptionValue(optionName, expectedValue, optionErrorString, |
|
271 outputAnalyzer); |
|
272 } |
|
273 |
|
274 /** |
|
275 * Verifies that value of specified JVM option is the same as |
|
276 * expected value. |
|
277 * |
|
278 * @param optionName a name of tested option. |
|
279 * @param expectedValue expected value of tested option. |
|
280 * @param optionErrorString message will be shown if option value is not |
|
281 * as expected. |
|
282 * @param outputAnalyzer OutputAnalyzer instance |
|
283 * @throws AssertionError if verification fails |
|
284 */ |
|
285 public static void verifyOptionValue(String optionName, |
|
286 String expectedValue, String optionErrorString, |
|
287 OutputAnalyzer outputAnalyzer) { |
250 try { |
288 try { |
251 outputAnalyzer.shouldMatch(String.format( |
289 outputAnalyzer.shouldMatch(String.format( |
252 CommandLineOptionTest.PRINT_FLAGS_FINAL_FORMAT, |
290 CommandLineOptionTest.PRINT_FLAGS_FINAL_FORMAT, |
253 optionName, expectedValue)); |
291 optionName, expectedValue)); |
254 } catch (RuntimeException e) { |
292 } catch (RuntimeException e) { |
255 String errorMessage = String.format( |
293 String errorMessage = String.format( |
256 "Option '%s' is expected to have '%s' value%n%s", |
294 "Option '%s' is expected to have '%s' value%n%s", |
257 optionName, expectedValue, |
295 optionName, expectedValue, |
258 optionErrorString); |
296 optionErrorString); |
259 throw new AssertionError(errorMessage, e); |
297 throw new AssertionError(errorMessage, e); |
260 } |
298 } |