My code is:
package demo1;
import io.restassured.RestAssured;
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
import demo1.Files.PayLoad;
public class PostMethodEx1 {
public static void main(String[] args) {
//to validate if add place api is working as expected.
//given-->all input details
//when-->submit the API
//then-->validate the response
RestAssured.baseURI="https://rahulshettyacademy.com";
String response=given().log().all().queryParam("key", "qaclick123").header("Content-Type","application/json")
.body(PayLoad.addPlace())
.when().post("maps/api/place/add/json")
.then().assertThat().statusCode(200).body("scope", equalTo("APP"))
.header("Server", "Apache/2.4.18 (Ubuntu)").extract().response().asString();
System.out.println(response);
}
}
Payload class code is:
package demo1.Files;
public class PayLoad {
public static String addPlace(){
return "{\\r\\n\" + \r\n" +
" \" \\\"location\\\": {\\r\\n\" + \r\n" +
" \" \\\"lat\\\": -38.383494,\\r\\n\" + \r\n" +
" \" \\\"lng\\\": 33.427362\\r\\n\" + \r\n" +
" \" },\\r\\n\" + \r\n" +
" \" \\\"accuracy\\\": 50,\\r\\n\" + \r\n" +
" \" \\\"name\\\": \\\"Akshay-MG\\\",\\r\\n\" + \r\n" +
" \" \\\"phone_number\\\": \\\"(+91) 983 893 3937\\\",\\r\\n\" + \r\n" +
" \" \\\"address\\\": \\\"29, side layout, cohen 09\\\",\\r\\n\" + \r\n" +
" \" \\\"types\\\": [\\r\\n\" + \r\n" +
" \" \\\"shoe park\\\",\\r\\n\" + \r\n" +
" \" \\\"shop\\\"\\r\\n\" + \r\n" +
" \" ],\\r\\n\" + \r\n" +
" \" \\\"website\\\": \\\"http://google.com\\\",\\r\\n\" + \r\n" +
" \" \\\"language\\\": \\\"French-IN\\\"\\r\\n\" + \r\n" +
" \"}";
}
}
Error I am getting is: Exception in thread "main" groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized.
Aucun commentaire:
Enregistrer un commentaire