I wondering how to do correct validate if returned uuid is in correct format.
I have created custom validator using Regex matches function.
What do you think about that:
package pl.gemiusz;
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;
import java.util.regex.Pattern;
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;
public class Case0020RegexValidatorSimulation extends Simulation {
HttpProtocolBuilder httpProtocol =
http
.baseUrl("https://postman-echo.com");
Pattern uuidRegexCompiledPattern = Pattern.compile("^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$");
ScenarioBuilder scn =
scenario("GeMi_RegexValidatorSimulation")
.exec(
http("GeMi_RegexValidator_get_randomUuid")
.get("/get?foo=#{randomUuid()}")
.check(jmesPath("args.foo").validate(
"UuidRegexValidator",
(actual, session) -> {
if (actual == null) {
throw new NullPointerException("Value is missing");
} else if (!uuidRegexCompiledPattern.matcher(actual).matches()) {
throw new IllegalArgumentException("Value " + actual + " not match Regex compiled pattern " + uuidRegexCompiledPattern.pattern());
}
return actual;
}).saveAs("get_randomUuid"))
)
.exec(session -> {
System.out.println("GeMi_RegexValidator_get_randomUuid: " + session.get("get_randomUuid"));
return session;
});
{
setUp(scn.injectOpen(atOnceUsers(1)).protocols(httpProtocol));
}
}
I’m thinking of making a feature request for Regex Validator, but I’m not sure if anyone besides me will need it
As I know not compiled regex patterns are slow so for this feature all will need to be compiled, I’m right?