I am really new to this, so maybe I am making an extremely simple mistake.
I have an automated test using Serenity and Java, making a POST request to an endpoint.
In the JSON payload there is a field "inspectionId" which requires a unique value. If the value already exists in the database, the POST fails and you get a 400.
I know how to generate the unique ID in the java code, but I cant figure out how to put it into the payload before sending the POST request.
I am trying to figure out how to insert the newly generated UUID into the payload before making the post request.
In my code I have the JSON file, a POJO class, and all of the methods. Mostly using Restassured,
I know there must be an easy way to insert the UUID into the payload before sending, but I cant wrap my head around how or when to do it. post request step
Here is the code in case it's necessary
@Then("Send a POST request to the mobile api {string} version {double} for {string}")
public void sendAPOSTRequestToUploadPaperworkApi(String api, double apiVersionValue, String value) throws JsonProcessingException {
Double apiVersion = apiVersionValue;
String apiType = value;
if (apiType.equals("startInspection"))
{
StartInspection startInspection = testData.get(threadName).getStartInspection(); //Gets the POJO file
String endpoint = variables.getProperty("ct_api_endpoint") + api; //creates the route to the endpoint
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); //formats dates
mapper.setDateFormat(simpleDateFormat);
String body = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(startInspection); //sets the body object
Response response = ControlTowerOperators.ctPostARequestWithBody(endpoint, body, apiVersion);
testData.get(threadName).setResponse(response);
}
}