1package DifferentWaysOfPassingPayloadToRequest;
2
3import java.io.File;
4
5import org.hamcrest.Matchers;
6import org.testng.annotations.Test;
7
8import io.restassured.RestAssured;
9import io.restassured.http.ContentType;
10
11public class PassFileAsPayload {
12
13 @Test
14 public void passFileAsPayload()
15 {
16 // Creating a File instance
17 File jsonDataInFile = new File("src/test/resources/Payloads/AuthPayload.json");
18
19 //GIVEN
20 RestAssured
21 .given()
22 .baseUri("https://restful-booker.herokuapp.com/auth")
23 .contentType(ContentType.JSON)
24 .body(jsonDataInFile)
25 // WHEN
26 .when()
27 .post()
28 // THEN
29 .then()
30 .assertThat()
31 .statusCode(200)
32 .body("token", Matchers.notNullValue())
33 .body("token.length()", Matchers.is(15))
34 .body("token", Matchers.matchesRegex("^[a-z0-9]+$"));
35 }
36
37}
38