194 Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); 195 if (!matcher.find()) { 196 reportDiagnosticSummary(); 197 throw new RuntimeException("'" + pattern 198 + "' missing from stderr \n"); 199 } 200 } 201 202 /** 203 * Verify that the stdout and stderr contents of output buffer does not 204 * match the pattern 205 * 206 * @param pattern 207 * @throws RuntimeException If the pattern was found 208 */ 209 public void shouldNotMatch(String pattern) { 210 Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); 211 if (matcher.find()) { 212 reportDiagnosticSummary(); 213 throw new RuntimeException("'" + pattern 214 + "' found in stdout \n"); 215 } 216 matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); 217 if (matcher.find()) { 218 reportDiagnosticSummary(); 219 throw new RuntimeException("'" + pattern 220 + "' found in stderr \n"); 221 } 222 } 223 224 /** 225 * Verify that the stdout contents of output buffer does not match the 226 * pattern 227 * 228 * @param pattern 229 * @throws RuntimeException If the pattern was found 230 */ 231 public void stdoutShouldNotMatch(String pattern) { 232 Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); 233 if (matcher.find()) { 234 reportDiagnosticSummary(); 235 throw new RuntimeException("'" + pattern 236 + "' found in stdout \n"); 237 } 238 } 239 240 /** 241 * Verify that the stderr contents of output buffer does not match the 242 * pattern 243 * 244 * @param pattern 245 * @throws RuntimeException If the pattern was found 246 */ 247 public void stderrShouldNotMatch(String pattern) { 248 Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); 249 if (matcher.find()) { 250 reportDiagnosticSummary(); 251 throw new RuntimeException("'" + pattern 252 + "' found in stderr \n"); 253 } 254 } 255 256 /** 257 * Verify the exit value of the process 258 * 259 * @param expectedExitValue Expected exit value from process 260 * @throws RuntimeException If the exit value from the process did not match the expected value 261 */ 262 public void shouldHaveExitValue(int expectedExitValue) { 263 if (getExitValue() != expectedExitValue) { 264 reportDiagnosticSummary(); 265 throw new RuntimeException("Expected to get exit value of [" 266 + expectedExitValue + "]\n"); 267 } 268 } 269 270 271 /** 272 * Report summary that will help to diagnose the problem 273 * Currently includes: | 194 Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); 195 if (!matcher.find()) { 196 reportDiagnosticSummary(); 197 throw new RuntimeException("'" + pattern 198 + "' missing from stderr \n"); 199 } 200 } 201 202 /** 203 * Verify that the stdout and stderr contents of output buffer does not 204 * match the pattern 205 * 206 * @param pattern 207 * @throws RuntimeException If the pattern was found 208 */ 209 public void shouldNotMatch(String pattern) { 210 Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); 211 if (matcher.find()) { 212 reportDiagnosticSummary(); 213 throw new RuntimeException("'" + pattern 214 + "' found in stdout: '" + matcher.group() + "' \n"); 215 } 216 matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); 217 if (matcher.find()) { 218 reportDiagnosticSummary(); 219 throw new RuntimeException("'" + pattern 220 + "' found in stderr: '" + matcher.group() + "' \n"); 221 } 222 } 223 224 /** 225 * Verify that the stdout contents of output buffer does not match the 226 * pattern 227 * 228 * @param pattern 229 * @throws RuntimeException If the pattern was found 230 */ 231 public void stdoutShouldNotMatch(String pattern) { 232 Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); 233 if (matcher.find()) { 234 reportDiagnosticSummary(); 235 throw new RuntimeException("'" + pattern 236 + "' found in stdout \n"); 237 } 238 } 239 240 /** 241 * Verify that the stderr contents of output buffer does not match the 242 * pattern 243 * 244 * @param pattern 245 * @throws RuntimeException If the pattern was found 246 */ 247 public void stderrShouldNotMatch(String pattern) { 248 Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); 249 if (matcher.find()) { 250 reportDiagnosticSummary(); 251 throw new RuntimeException("'" + pattern 252 + "' found in stderr \n"); 253 } 254 } 255 256 /** 257 * Get the captured group of the first string matching the pattern. 258 * stdout is searched before stderr. 259 * 260 * @param pattern The multi-line pattern to match 261 * @param group The group to capture 262 * @return The matched string or null if no match was found 263 */ 264 public String firstMatch(String pattern, int group) { 265 Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); 266 Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); 267 if (stdoutMatcher.find()) { 268 return stdoutMatcher.group(group); 269 } 270 if (stderrMatcher.find()) { 271 return stderrMatcher.group(group); 272 } 273 return null; 274 } 275 276 /** 277 * Get the first string matching the pattern. 278 * stdout is searched before stderr. 279 * 280 * @param pattern The multi-line pattern to match 281 * @return The matched string or null if no match was found 282 */ 283 public String firstMatch(String pattern) { 284 return firstMatch(pattern, 0); 285 } 286 287 /** 288 * Verify the exit value of the process 289 * 290 * @param expectedExitValue Expected exit value from process 291 * @throws RuntimeException If the exit value from the process did not match the expected value 292 */ 293 public void shouldHaveExitValue(int expectedExitValue) { 294 if (getExitValue() != expectedExitValue) { 295 reportDiagnosticSummary(); 296 throw new RuntimeException("Expected to get exit value of [" 297 + expectedExitValue + "]\n"); 298 } 299 } 300 301 302 /** 303 * Report summary that will help to diagnose the problem 304 * Currently includes: |