use of io.gravitee.gateway.services.healthcheck.eval.assertion.AssertionEvaluation in project gravitee-gateway by gravitee-io.
the class HttpEndpointRuleHandler method validateAssertions.
private EndpointStatus.StepBuilder validateAssertions(final io.gravitee.definition.model.services.healthcheck.Step step, final EvaluableHttpResponse response) {
EndpointStatus.StepBuilder stepBuilder = EndpointStatus.forStep(step.getName());
// Run assertions
if (step.getResponse().getAssertions() != null) {
Iterator<String> assertionIterator = step.getResponse().getAssertions().iterator();
boolean success = true;
while (success && assertionIterator.hasNext()) {
try {
// TODO: assertion must be compiled only one time to preserve CPU
AssertionEvaluation evaluation = new AssertionEvaluation(assertionIterator.next());
evaluation.setVariable("response", response);
// Run validation
success = evaluation.validate();
if (success) {
stepBuilder.success();
} else {
stepBuilder.fail("Assertion not validated: " + evaluation.getAssertion());
}
} catch (EvaluationException eex) {
success = false;
stepBuilder.fail(eex.getMessage());
}
}
}
return stepBuilder;
}
Aggregations