Follow my code
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import static org.hamcrest.Matchers.equalTo;
public class APICriaContatoTests {
/*VARIAVEIS PARA A REQUEST*/
@Test
public void insereInformandoTodosOsDados()
{
JsonPath expectedJson = new JsonPath(new File("arquivos\jsonInsereInformandoTodosOsDados.json"));
//Criando dados para a requisição
jsonAsMap.put("name", "Teste de Nome 4");
jsonAsMap.put("last-name", "Nome Completo 4");
jsonAsMap.put("email", "[email protected]");
jsonAsMap.put("age", "25");
jsonAsMap.put("phone", "5519864666664");
jsonAsMap.put("address", "Rua 4");
jsonAsMap.put("state", "Estado 4");
jsonAsMap.put("city", "Cidade 4");
//executando a requisicao
RestAssured.given().accept(ACCEPT).contentType(TYPE)
.body(jsonAsMap)
.when()
.post(ENDPOINT_POST_CRIA_CONTATOS)
.then()
.statusCode(201)
.body("", equalTo(expectedJson.getMap("")));
}
}
Data from my file
{
"data": {
"id": "12",
"type": "contacts",
"attributes": {
"name": "Teste de Nome 4",
"last-name": "Nome Completo 4",
"email": "[email protected]",
"age": 25,
"phone": "5519864666664",
"address": "Rua 4",
"state": "Estado 4",
"city": "Cidade 4"
}
}
}
As the body validation I am using a sample file, I would like to know:
Thank you!