I am trying to test a small rest service that I am doing to study using rest assured. I followed the advice of this guy's video: https://www.youtube.com/watch?v=yDdBOspPp_c
however at the time of realizing the post is said that: failed to parse the json document However the data is persisted in the database. What should I do?
@SuppressWarnings("unchecked")
@Test
public void deveInserirUmProduto() {
// Specify base URI
RestAssured.baseURI = "http://localhost:8080/ProjetoJersey/api/produto";
// Request Object
RequestSpecification httpRequest = RestAssured.given();
//Request playload sending along with post request
JSONObject requestParams = new JSONObject();
requestParams.put("nome", "MacBook PRO");
requestParams.put("tipoProduto", "INFORMATICA");
requestParams.put("valor", 26000.00);
requestParams.put("cor", "Cinza Espacial");
requestParams.put("especificacoes", "Top de linha");
httpRequest.header("Content-type", "application/json");
httpRequest.body(requestParams.toJSONString());
// Response Object
Response response = httpRequest.request(Method.POST, "/");
// Print response in console window
String responseBody = response.getBody().asString();
System.out.println("Response Body is: " + responseBody);
// Status code validation
int statusCode = response.getStatusCode();
System.out.println("Status code is: " + statusCode);
Assert.assertEquals(statusCode, 201);
// Success code validation
String successCode = response.jsonPath().get("SuccessCode");
Assert.assertEquals(successCode, "OPERATION_SUCCESS");
}