Testing 在Rest Assured json正文中匹配长值时出现问题
我有以下回应:Testing 在Rest Assured json正文中匹配长值时出现问题,testing,rest-assured,rest-assured-jsonpath,Testing,Rest Assured,Rest Assured Jsonpath,我有以下回应: [ { "id": 53, "fileUri": "abc", "filename": "abc.jpg", "fileSizeBytes": 578466, "createdDate": "2018-10-15", "updatedDate": "2018-10-15" }, { "id": 54, "fileUri": "xy
[
{
"id": 53,
"fileUri": "abc",
"filename": "abc.jpg",
"fileSizeBytes": 578466,
"createdDate": "2018-10-15",
"updatedDate": "2018-10-15"
},
{
"id": 54,
"fileUri": "xyz",
"filename": "xyz.pdf",
"fileSizeBytes": 88170994,
"createdDate": "2018-10-15",
"updatedDate": "2018-10-15"
}
]
.body("id", hasItems(file1.getId(), file2.getId()));
我试图将id
值与JUnit中的对象匹配,如下所示:
RestAssured.given() //
.expect() //
.statusCode(HttpStatus.SC_OK) //
.when() //
.get(String.format("%s/%s/file", URL_BASE, id)) //
.then() //
.log().all() //
.body("", hasSize(2)) //
.body("id", hasItems(file1.getId(), file2.getId()));
.body("id", hasItems(file1.getId(), file2.getId()));
但当匹配发生时,它会尝试将int
与long
匹配。相反,我得到以下输出:
java.lang.AssertionError: 1 expectation failed.
JSON path id doesn't match.
Expected: (a collection containing <53L> and a collection containing <54L>)
Actual: [53, 54]
.body("id", hasItems(file1.getId(), file2.getId()));
java.lang.AssertionError:1预期失败。
JSON路径id不匹配。
应为:(包含的集合和包含的集合)
实际:[53、54]
如何告诉Rest Assured值确实是一个长值,即使它可能足够短,可以放入int?我可以将文件的
id
转换为int
,它可以工作,但这似乎有些草率。问题是,当从json转换为java类型时,选中int类型,
.body("id", hasItems(file1.getId(), file2.getId()));
一种解决方案是比较int值。
而不是
.body("id", hasItems(file1.getId(), file2.getId()));
使用
.body("id", hasItems(file1.getId(), file2.getId()));