I try to use Jmeter and a http request to send data to a controller using a function to create 5 new user with the same data.
the function inside the controlleur:
public Result create(Http.Request request){
var body = safeJsonBody(request);
var mandatory_params = Ref.of(List.of("username", "firstname", "email", "password", "phonenumber", "address"));
var maybeUsername = extractNonEmptyString(body, "username");
var maybeFirstname = extractNonEmptyString(body, "firstname");
var maybeEmail = extractEmail(body, "email");
var maybePassword = extractNonEmptyString(body, "password");
var hashedPassword = "";
if(!maybePassword.isEmpty())
{
var hash = hashFactory.mkHash(maybePassword.get(), Registration);
hashedPassword= hash.get().hash;
}
var maybePhonenumber = extractNonEmptyString(body, "phonenumber");
var maybeAddress = extractNonEmptyString(body, "address");
logger.warn("maybeUsername : " + maybeUsername);
logger.warn("maybeFirstname : " + maybeFirstname);
logger.warn("maybeEmail : " + maybeEmail);
logger.warn("maybePassword : " + maybePassword);
logger.warn("maybePhonenumber : " + maybePhonenumber);
logger.warn("maybeAddress : "+maybeAddress);
if ( maybeUsername.isEmpty() || maybeFirstname.isEmpty() || maybeEmail.isEmpty() || maybePassword.isEmpty()) {
checkIfIsPresent(mandatory_params,maybeUsername,"username");
checkIfIsPresent(mandatory_params,maybeFirstname,"firstname");
checkIfIsPresent(mandatory_params,maybeEmail,"email");
checkIfIsPresent(mandatory_params,maybePassword,"password");
checkIfIsPresent(mandatory_params,maybePhonenumber,"phonenumber");
checkIfIsPresent(mandatory_params,maybeAddress,"address");
return badRequest("Missing mandatory params: " + mandatory_params);
}
var tx = usersModel.upsert(maybeUsername.get(),maybeFirstname.get(),
maybeEmail.get(),hashedPassword,maybePhonenumber.get(),maybeAddress.get());
if (tx.isEmpty()){
logger.warn(tx.toString());
return internalServerError(stc_map_to_json(Map.of("status","error","message", "The user could not be created or updated.")).get());
}
return ok(tx.get());
}
I see "Missing mandatory params: Ref{val=[username, firstname, email, password, phonenumber, address]}" inside the response body in the View result tree I created so the data must be going to the right function.
And I try display the content of the request send to the controller by using a logger and it's weirdly display "POST /user/create"
It looks like you need to send a JSON structure like:
{
"username": "userJM",
"firstname": "usernameJM",
"email": "userJM@gmail.com",
"password": "mdpJM",
"phonenumber": 12345678934,
"address": "150 rue jmeter"
}
In JMeter it would be something like:
You might also need to add a HTTP Header Manager and configure it to send Content-Type header with the value of application/json
If you're not sure how to properly build this or that request the easiest way is just recording it using JMeter's HTTP(S) Test Script Recorder