Использование queryParams вместо Json body в Restassured API testing - PullRequest
1 голос
/ 29 мая 2020

Я использую библиотеку RestAssured для автоматизации ответов API на языке Java, и вот тело API, которое я использую:

{



"meta": {
    "language": "en",
    "marketCountry": "IN",
    "sourceUrl": "https://cj-gaq-dev.logistics.dhl/regular-shipment.html?en-AU"
},
"contactInformation": {
    "company": "test",
    "firstName": "test",
    "lastName": "test",
    "address": "test",
    "zip": "test",
    "city": "test",
    "country": "IN",
    "countryDisplay": "India",
    "email": "test@test.com",
    "phoneNumber": "2324243243",
    "comments": "test"
},
"shipmentScale": {
    "domestic": false,
    "regional": false,
    "global": true
},
"shipmentProduct": {
    "FREIGHT": {
        "numberOfShipments": "50",
        "frequency": "WEEKLY",
        "checked": true
    }



}

вместо использования всего тела api, я хочу использовать queryParameters. Есть ли способ сделать это?

Это то, что я использовал до сих пор и продолжаю получать ошибку кода состояния 422:

String result = given().header("Content-Type","application/json" )
            .header("Accept","application/json").log().all().queryParam("marketCountry", "IN").queryParam("shipmentScale.domestic", "false")
            .queryParam("shipmentScale.regional", "false").queryParam("shipmentScale.global", "true")
            .queryParam("shipmentProduct.FREIGHT.checked", "true")
            .queryParam("shipmentProduct.FREIGHT.numberOfShipments", "50")
            .queryParam("shipmentProduct.FREIGHT.frequency", "WEEKLY")
            .queryParam("contactInformation.company", "test")
            .queryParam("contactInformation.firstName", "test")
            .queryParam("contactInformation.lastName", "test")
            .queryParam("contactInformation.address", "test")
            .queryParam("contactInformation.zip", "test")
            .queryParam("contactInformation.city", "test")
            .queryParam("contactInformation.email", "test@test.com")
            .queryParam("contactInformation.phoneNumber", "213456")
            .queryParam("contactInformation.comments", "test")
            .queryParam("contactInformation.country", "IN")
            .queryParam("contactInformation.comments", "test")
            .when().post().then().assertThat().statusCode(200).extract().response().asString();
...