-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasics.java
More file actions
61 lines (48 loc) · 2.28 KB
/
Basics.java
File metadata and controls
61 lines (48 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
import org.testng.Assert;
import files.ReUsableMethods;
import files.payload;
public class Basics {
public static void main(String[] args) {
// TODO Auto-generated method stub
// validate if Add Place API is workimg as expected
// Add place-> Update Place with New Address -> Get Place to validate if New
// address is present in response
// given - all input details
// when - Submit the API -resource,http method
// Then - validate the response
RestAssured.baseURI = "https://rahulshettyacademy.com";
String response = given().log().all().queryParam("key", "qaclick12322").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.52 (Ubuntu)").extract().response().asString();
System.out.println("The response is:" + response);
// for parsing Json
JsonPath js = new JsonPath(response);
String placeId = js.getString("place_id");
System.out.println("The placeId is:" + placeId);
// Update Place
String newAddress = "Summer Walk, Africa";
given().log().all().queryParam("key", "qaclick123").header("Content-Type", "application/json")
.body("{\r\n" +
"\"place_id\":\"" + placeId + "\",\r\n" +
"\"address\":\"" + newAddress + "\",\r\n" +
"\"key\":\"qaclick123\"\r\n" +
"}")
.when().put("maps/api/place/update/json")
.then().assertThat().log().all().statusCode(200).body("msg", equalTo("Address successfully updated"));
// Get Place
String getPlaceResponse = given().log().all().queryParam("key", "qaclick123").queryParam("place_id", placeId)
.when().get("maps/api/place/get/json")
.then().assertThat().log().all().statusCode(200).extract().response().asString();
JsonPath js1 = ReUsableMethods.rawToJson(getPlaceResponse);
String actualAddress = js1.getString("address");
System.out.println(actualAddress);
Assert.assertEquals(actualAddress, "Pacific ocean");
// Cucumber Junit, Testng
// End of the test
System.out.println("The test is completed");
}
}