Put Request body as a Map code example
Example: Put Request body as a Map
@BeforeAll
public static void init() {
RestAssured.baseURI = "http://..........";
RestAssured.port = 8000;
RestAssured.basePath = "/api";
}
@DisplayName("Put Request body as a Map")
@Test
public void testPutRequestWithMap() {
String randomName = new Faker().name().firstName();
Map<String,Object> updatedBody = new LinkedHashMap<>();
updatedBody.put("name", randomName) ;
updatedBody.put("gender", "Male") ;
updatedBody.put("phone",8745124312L ) ;
given()
.log().all()
.contentType(ContentType.JSON)
.body(updatedBody).
when()
.put("/spartans/{id}",142).
then()
.log().all()
.statusCode( is(204) )
;