in src/components/src/main/java/org/apache/jmeter/assertions/ResponseAssertion.java [295:395]
private AssertionResult evaluateResponse(SampleResult response) {
AssertionResult result = new AssertionResult(getName());
if (getAssumeSuccess()) {
response.setSuccessful(true);// Allow testing of failure codes
}
String toCheck = getStringToCheck(response);
result.setFailure(false);
result.setError(false);
int testType = getTestType();
boolean notTest = (NOT & testType) > 0;
boolean orTest = (OR & testType) > 0;
boolean contains = isContainsType(); // do it once outside loop
boolean equals = isEqualsType();
boolean substring = isSubstringType();
log.debug("Test Type Info: contains={}, notTest={}, orTest={}", contains, notTest, orTest);
if (StringUtils.isEmpty(toCheck)) {
if (notTest) { // Not should always succeed against an empty result
return result;
}
if (log.isDebugEnabled()) {
log.debug("Not checking empty response field in: {}", response.getSampleLabel());
}
return result.setResultForNull();
}
try {
// Get the Matcher for this thread
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
boolean hasTrue = false;
List<String> allCheckMessage = new ArrayList<>();
for (JMeterProperty jMeterProperty : getTestStrings()) {
String stringPattern = jMeterProperty.getStringValue();
boolean found;
if (contains) {
if (USE_JAVA_REGEX) {
found = containsWithJavaRegex(toCheck, stringPattern);
} else {
Pattern pattern = JMeterUtils.getPatternCache()
.getPattern(stringPattern, Perl5Compiler.READ_ONLY_MASK);
found = localMatcher.contains(toCheck, pattern);
}
} else if (equals) {
found = toCheck.equals(stringPattern);
} else if (substring) {
found = toCheck.contains(stringPattern);
} else { // this is the old `matches` part which means `isMatchType()` is true
if (USE_JAVA_REGEX) {
found = matchesWithJavaRegex(toCheck, stringPattern);
} else {
Pattern pattern = JMeterUtils.getPatternCache()
.getPattern(stringPattern, Perl5Compiler.READ_ONLY_MASK);
found = localMatcher.matches(toCheck, pattern);
}
}
boolean pass = notTest ? !found : found;
if (orTest) {
if (!pass) {
log.debug("Failed: {}", stringPattern);
allCheckMessage.add(getFailText(stringPattern, toCheck));
} else {
hasTrue=true;
break;
}
} else {
if (!pass) {
log.debug("Failed: {}", stringPattern);
result.setFailure(true);
String customMsg = getCustomFailureMessage();
if (StringUtils.isEmpty(customMsg)) {
result.setFailureMessage(getFailText(stringPattern, toCheck));
} else {
result.setFailureMessage(customMsg);
}
break;
}
log.debug("Passed: {}", stringPattern);
}
}
if (orTest && !hasTrue){
result.setFailure(true);
String customMsg = getCustomFailureMessage();
if (StringUtils.isEmpty(customMsg)) {
result.setFailureMessage(
allCheckMessage.stream()
.collect(Collectors.joining("\t", "", "\t")));
} else {
result.setFailureMessage(customMsg);
}
}
} catch (MalformedCachePatternException | PatternSyntaxException e) {
result.setError(true);
result.setFailure(false);
result.setFailureMessage("Bad test configuration " + e);
}
return result;
}