mercredi 31 mars 2021

POST request fails (rest-assured test) Expected response body to be verified as JSON, HTML or XML but no content-type was defined in the response.?

I have problem with making POST request with rest-assured. @Test public void deleteBook(){

    //Given
    
    Response response = given().
        contentType("application/json").
        body(" { \"Title\": \"Libro2\"}").
    when().
        post("api/books/").andReturn();
    
    int id = from(response.getBody().asString()).get("id");
        
    //When
    when().
        delete("api/books/{id}",id).
    //Then  
    then().
        statusCode(200).
        body("id", equalTo(id));
    
    when()
        .get("api/books/{id}",id).
    then()
        .statusCode(404);
}

java.lang.IllegalStateException: Expected response body to be verified as JSON, HTML or XML but no content-type was defined in the response. Try registering a default parser using: RestAssured.defaultParser(); I have run out of ideas whats wrong.

Aucun commentaire:

Enregistrer un commentaire