在整个现有项目中出现错误(放心)

问题描述 投票:0回答:0

package demoProject;

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.ReuseableMethods;
import files.paayload;

public class Basics {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
//Validate If add place API working is expected 
        
        //Basic principal of Rest assured
        //Given - all i/p details
        //When - submit the APIs: responce
        //Then - validate the response
        
        RestAssured.baseURI= "https://rahulshettyacademy.com";
        String response=given().log().all().queryParam("key", "qaclick123").header("Content-Type", "application/json")
        .body(paayload.Addplace()).when().post("maps/api/place/add/json")
        .then().log().all().assertThat().statusCode(200).body("scope", equalTo("APP"))
        
        //when you write .header after then() mean you validate o/p value here we do server validation
        //.header("server", "Apache/2.4.41 (Ubuntu)");
        .header("server", "Apache/2.4.41 (Ubuntu)").extract().response().asString();
        
        System.out.println(response);
        
        JsonPath js=new JsonPath(response);  //for parshing json
        
        String placeID=js.getString("place_id");
        
        System.out.println(placeID);
        //Add place-> update place with new add-> Get place and validate the new address is present or not  
        
        //Task: Integrtion the multipul API's with common Json responce values: here we use Place ID variable value for Update the Place value 
        
        String newAddress = "orar, gwalior";
        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 getPlaceResponce= given().log().all().queryParam("key", "qaclick123").queryParam("place_id", placeID)
        .when().get("maps/api/place/get/json")
        .then().log().all().statusCode(200).extract().response().asString();
        
        JsonPath js1 = ReuseableMethods.rwToJson(getPlaceResponce);
        String actualAddress= js1.get("address");
        System.out.println(actualAddress);
        Assert.assertEquals(newAddress, actualAddress);
        //cucumber, TestNG, Junit
    }

}

json eclipse rest-assured
© www.soinside.com 2019 - 2024. All rights reserved.