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;
public ExampleResponseValidatorProvider(String someValue) {this.someValue = someValue;}
@Override
String taskId,
NodeContext kernelContext) {
@Override
public String getName() {
return "Example response validator";
}
@Override
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
JTestDefinition jTestDefinition = JTestDefinition
.builder(Id.of("exampleJaggerTestDefinition"), new ExampleEndpointsProvider())
.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();