use of com.endava.cats.model.util.JsonUtils.NOT_SET in project cats by Endava.
the class CustomFuzzerUtil method checkVerifiesAndReport.
private void checkVerifiesAndReport(String request, CatsResponse response, String verify, String expectedResponseCode) {
Map<String, String> verifies = this.parseYmlEntryIntoMap(verify);
Map<String, String> responseValues = this.matchVariablesWithTheResponse(response, verifies, Map.Entry::getKey);
log.info("Parameters to verify: {}", verifies);
log.info("Parameters matched to response: {}", responseValues);
if (responseValues.entrySet().stream().anyMatch(entry -> entry.getValue().equalsIgnoreCase(NOT_SET))) {
log.error("There are Verify parameters which were not present in the response!");
testCaseListener.reportError(log, "The following Verify parameters were not present in the response: {}", responseValues.entrySet().stream().filter(entry -> entry.getValue().equalsIgnoreCase(NOT_SET)).map(Map.Entry::getKey).collect(Collectors.toList()));
} else {
StringBuilder errorMessages = new StringBuilder();
verifies.forEach((key, value) -> {
String valueToCheck = responseValues.get(key);
String parsedVerifyValue = this.getVerifyValue(request, response, value);
Matcher verifyMatcher = Pattern.compile(parsedVerifyValue).matcher(valueToCheck);
if (!verifyMatcher.matches()) {
errorMessages.append(String.format(NOT_MATCHING_ERROR, key, valueToCheck, parsedVerifyValue));
}
});
if (errorMessages.length() == 0 && expectedResponseCode.equalsIgnoreCase(response.responseCodeAsString())) {
testCaseListener.reportInfo(log, "Response matches all 'verify' parameters");
} else if (errorMessages.length() == 0) {
testCaseListener.reportWarn(log, "Response matches all 'verify' parameters, but response code doesn't match expected response code: expected [{}], actual [{}]", expectedResponseCode, response.responseCodeAsString());
} else {
testCaseListener.reportError(log, errorMessages.toString());
}
}
}
Aggregations