rest-assured - 以 ASC/DESC 顺序放心响应
问题描述
有什么方法可以按顺序验证响应吗?
"user": [
{
"_id": "1",
"age": 21,
},
{
"_id": "2",
"age": 22,
},
{
"_id": "7",
"age": 30,
}
]
我可以通过以下方式获得特定的 id 值
.body("user[0].id", some validation) result: 1
当我做这样的事情时,我会得到所有的 id
.body("user.id", some validation) result: [1,2,7]
需要验证以验证结果是否按 DESC/ASC 顺序排列
.body("user.id", isDescOrder()/isAscOrder())
解决方案
您可以isInOrder(Iterable<? extends T> iterable, Comparator<T> comparator)
在com.google.common.collect.Comparators中使用。
List<String> user_IdList = given()
.when()
.get("api_url")
.then()
.extract()
.jsonPath()
.getList("user._id");
List<Integer> integerList = user_IdList
.stream()
.map(x-> Integer.parseInt(x))
.collect(Collectors.toList());
boolean isInAscOrder = isInOrder(integerList, Ordering.natural());
这isInAscOrder
将是真实的。因为 1,2,7 是按升序排列的。
推荐阅读
- ethereum - 将小写的加密钱包地址转换为正确的格式
- sql - 在 postgresql 中将结果合并到数组中
- angular - 自定义材质分页器的样式
- reactjs - 如何使用 create react app 和 webpack 配置 manifest.json
- java - Lombok 在 LibGDX 项目中未被识别
- daml - 在 DAML 中,如何查找和替换列表中的元素
- json - 配置json解析器解析json中转义的json字符串
- java - 从 ObservableList 填充的 tableView(JavaFX) 不起作用
- ios - 如何获取特定元素的所有后代?
- reactjs - 表单未在模态 React-Bootstrap 中呈现