8

我正在使用放心 - https://code.google.com/p/rest-assured/wiki/Usage 我的 JsonObject 看起来像这样

{
"id": "12",
"employeeInfo": null,
"employerInfo": null,
"checkDate": 1395093997218,
"netAmount": {
"amount": 70,
"currency": "USD"
},
"moneyDistributionLineItems": [
{
"mAmount": 100,
"employeeBankAccountId": "BankAccount 1"
}
],
}

如何使用 REST-assured POST 将其作为参数的一部分发送?我努力了

given().param("key1", "value1").param("key2", "value2").when().post("/somewhere").then().
        body(containsString("OK")); 

但这对于具有嵌套值的 HUGE 对象是不可扩展的。有更好的方法吗?

4

2 回答 2

9

您只需在正文中发送 JSON 文档。例如,如果您将 JSON 文档保存在名为 myJson 的字符串中,那么您可以这样做:

String myJson = ..
given().contentType(JSON).body(myJson).when().post("/somewhere"). .. 

您还可以使用 POJO、输入流和 byte[] 来代替 String。

于 2014-03-18T06:44:10.833 回答
2
    URL file = Resources.getResource("PublishFlag_False_Req.json");
    String myJson = Resources.toString(file, Charsets.UTF_8);

    Response responsedata = given().header("Authorization", AuthorizationValue)
        .header("X-App-Client-Id", XappClintIDvalue)
        .contentType("application/vnd.api+json")
        .body(myJson)
        .with()
        .when()
        .post(dataPostUrl);
于 2016-08-12T18:22:37.227 回答