rest assured post json file example

Solutions on MaxInterview for rest assured post json file example by the best coders in the world

showing results for - "rest assured post json file example"
Cristóbal
08 Oct 2016
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
similar questions
queries leading to this page
rest assured post json file example