Boa tarde.
tenho uma coleção de 3 testes em JAVA com Rest Assured, o get e o delete funcionam, o post não!
O post executa com sucesso mas não grava os dados.
RETORNO DA API
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 646
Date: Wed, 16 May 2018 16:54:42 GMT
Connection: keep-alive
{
“contatos”: [
{
“id”: 1,
“nome”: “João”,
“email”: "joao@gmail.com",
“idade”: 46,
“restricao”: false
},
{
“id”: 2,
“nome”: “Maria”,
“email”: "maria@gmail.com",
“idade”: 21,
“restricao”: false
},
{
“id”: 3,
“nome”: “José”,
“email”: "jose@gmail.com",
“idade”: 18,
“restricao”: true
},
{
“id”: 4,
“nome”: “Maria”,
“email”: "maria@gmail.com",
“idade”: 25,
“restricao”: false
},
{
“id”: 5,
“nome”: “batata”,
“email”: “Wed, 21 Oct 2015 18:27:50 GMT”,
“idade”: 19,
“restricao”: true
},
{
“id”: 6,
“nome”: “Maria”,
“email”: "maria@gmail.com",
“idade”: 25,
“restricao”: false
},
{
“id”: 7
},
{
“id”: 8
}
]
}
CLASSE DE TESTE
package RestAPITest;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
import org.testng.annotations.BeforeTest;
import io.restassured.matcher.RestAssuredMatchers.;
import io.restassured.module.jsv.JsonSchemaValidator.;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
import static io.restassured.RestAssured.;
import static org.hamcrest.Matchers.;
public class RestTest {
@Test(priority = 1)
public void getAPI() {
given().auth().preemptive().basic("admin", "12345").get("http://localhost:3000/api/v1/contact/1").then().statusCode(200).log().all();
}
@Test(priority = 2)
public void PostAPI() {
given().auth().preemptive().basic("admin","12345")
.formParam("contato.nome", "john")
.formParams("contato.email", "email@email.com")
.formParams("contato.idade", 1)
.formParams("contato.restricao", true )
.when()
.post("http://localhost:3000/api/v1/contact")
.then().log().all();
}
@Test(priority = 3)
public void deletePI() {
given().auth().preemptive().basic("admin","12345")
.when()
.delete("http://localhost:3000/api/v1/contact/16");
}
}
RESULTADO
PASSED: getAPI
PASSED: PostAPI
PASSED: deletePI
HTTP/1.1 201 Created
Content-Type: application/json
Content-Length: 40
Date: Wed, 16 May 2018 18:22:35 GMT
Connection: keep-alive
{
“status”: “sucesso”,
“contato”: {
“id”: 26
}
}