Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
Validators


Validation of SUT responses is provided by Jagger components Validators. They verify responses from the SUT and decide whether responses are valid or not. Every response can be validated by multiple validators. One after another. If one of the validators in the chain sets FAIL status to the response, this request is considered failed. This will affect standard performance metrics: success rate and number of failures.

Java doc for validators and examples
Validators implementations and examples
Example of validator
We will create a custom validator provider. This provider is returning an instance of validator. Depending on the setup our validator will verify http response code or always return true.
package com.griddynamics.jagger.engine.e1.collector;
import com.griddynamics.jagger.coordinator.NodeContext;
import com.griddynamics.jagger.invoker.v2.JHttpEndpoint;
import com.griddynamics.jagger.invoker.v2.JHttpQuery;
import com.griddynamics.jagger.invoker.v2.JHttpResponse;
import org.springframework.http.HttpStatus;
import java.util.Objects;
public class ExampleResponseValidatorProvider implements ResponseValidatorProvider {
private final String someValue;
/* Constructor allows to pass parameters to the validator */
public ExampleResponseValidatorProvider(String someValue) {this.someValue = someValue;}
@Override
String taskId,
NodeContext kernelContext) {
return new ResponseValidator<JHttpQuery, JHttpEndpoint, JHttpResponse>(taskId, sessionId, kernelContext) {
@Override
/* This name will be displayed in the reports */
public String getName() {
return "Example response validator";
}
@Override
/* Validator logic in defined here */
public boolean validate(JHttpQuery query, JHttpEndpoint endpoint, JHttpResponse result, long duration) {
if (Objects.equals(someValue, "we are always good")) {
return true;
}
return result.getStatus() == HttpStatus.OK;
}
};
}
}
We will add created validator to a particular test. You can add multiple validators to the same test. htey will be executed in the same sequence like they are added
// begin: following section is used for docu generation - example of the invocation listener
JTestDefinition jTestDefinition = JTestDefinition
.builder(Id.of("exampleJaggerTestDefinition"), new ExampleEndpointsProvider())
// optional
.withComment("no comments")
.withQueryProvider(new ExampleQueriesProvider())
.addValidator(new ExampleResponseValidatorProvider("we are always good"))
.addValidator(DefaultResponseValidatorProvider.of(NotNullResponseValidator.class))
.addValidator(JHttpResponseStatusValidatorProvider.of(200, 201, 204))
.addListener(new NotNullInvocationListener())
.addListener(new ExampleInvocationListener())
.build();
// end: following section is used for docu generation - example of the invocation listener