я запускаю RestApi, будьте уверены, что обновите это сообщение об ошибке не удалось решить проблему в Bookingdetails нет идентификатора. но в строке я получаю ошибку в строке
Нераспознанное поле "id" (класс pojoClasses.BookingDetails), не помеченное как игнорируемое (3 известных свойства: "title", "author", "createdat"])
у меня урок
BookingDetails.java
package pojoClasses;
import com.fasterxml.jackson.annotation.JsonProperty;
public class BookingDetails {
@JsonProperty
private String title;
@JsonProperty
private String author;
@JsonProperty
private String createdat;
public String gettitle(String title) {
return this.title;
}
public void settitle(String title) {
this.title = title;
}
public String getAuthor(String author) {
return this.author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getCreatedat(String createdat) {
return this.createdat;
}
public void setcreatedat(String createdat) {
this.createdat = createdat;
}
}
UpdateBooking.java
import io.restassured.response.Response;
import org.testng.annotations.Test;
import pojoClasses.BookingDetails;
import utility.AllureLogger;
import utility.BaseTest;
import static io.restassured.RestAssured.given;
public class UpdateBooking extends BaseTest {
@Test(description = "To update the details of the booking IDs")
public void updateBooking(){
AllureLogger.logToAllure("Starting the test to update details");
//Sending the PUT request for a specific booking id and receiving the response after updating the detals
AllureLogger.logToAllure("PUT update booking detail");
//Created a new booking
CreateBooking createBooking = new CreateBooking();
createBooking.createNewBooking("time", "psos", "2018-01-03", "null");
String IDtoUpdate = createBooking.newID;
AllureLogger.logToAllure("New Booking ID created is : "+IDtoUpdate);
System.out.println("IDtoUpdate::::::: "+IDtoUpdate);
//Update the booking with new first name
Response getResponse = given().
spec(requestSpec).
pathParam("id", IDtoUpdate).
when().
get("/posts/{id}");
BookingDetails bookingDetails = getResponse.as(BookingDetails.class);
bookingDetails.settitle("employee");
Response response = given().
spec(requestSpec).
header("Content-Type", "application/json").
header("Accept", "application/json").
// header("Cookie", cookieValue).
pathParam("id", IDtoUpdate).
// pathParam("id", 3).
body(bookingDetails).log().body().
when().
put("/posts/{id}");
//Verify the response code
AllureLogger.logToAllure("Asserting the response if the status code returned is 200");
response.then().spec(responseSpec);
//To log the response to report
logResponseAsString(response);
}
}
при запуске через команду -> мвн установить
Выход
Body:
{
"title": "time",
"author": "psos",
"createdat": "2018-01-03"
}
{
"title": "time",
"author": "psos",
"createdat": "2018-01-03",
"id": 32
}
32
IDtoUpdate::::::: 32
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 21.409 s <<< FAILURE! - in TestSuite
[ERROR] updateBooking(UpdateBooking) Time elapsed: 10.263 s <<< FAILURE!
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
Unrecognized field "id" (class pojoClasses.BookingDetails), not marked as ignorable (3 known properties: "title", "author", "createdat"])
at [Source: (String)"{
"title": "time",
"author": "psos",
"createdat": "2018-01-03",
"id": 32
}"; line: 5, column: 11] (through reference chain: pojoClasses.BookingDetails["id"])
at UpdateBooking.updateBooking(UpdateBooking.java:30)
Я не вижу поле id в DTO/POJO BookingDetails. Попробуйте добавить его так:
private String id;
public String getId() {
return this.id;
}
В вашем классе BookingDetails нет поля идентификатора.