action.execute(context);
} catch (Exception e) {
log.info("Validating caught exception ...");
if (!exception.isAssignableFrom(e.getClass())) {
throw new ValidationException("Validation failed for asserted exception type - expected: '" +
exception + "' but was: '" + e.getClass().getName() + "'", e);
}
if (message != null) {
if (ValidationMatcherUtils.isValidationMatcherExpression(message)) {
ValidationMatcherUtils.resolveValidationMatcher("message", e.getLocalizedMessage(), message, context);
} else if(!context.replaceDynamicContentInString(message).equals(e.getLocalizedMessage())) {
throw new ValidationException("Validation failed for asserted exception message - expected: '" +
message + "' but was: '" + e.getLocalizedMessage() + "'", e);
}
}
log.info("Exception is as expected: " + e.getClass() + ": " + e.getLocalizedMessage());
log.info("Exception validation successful");
return;
}
throw new ValidationException("Missing asserted exception '" + exception + "'");
}