2
ユーザーを名前で検索するためのRESTがあります。検索条件によっては、その用語が姓または名字のユーザーを返します。「OR」条件が再確認されました
GET /search/joe
戻りJSON配列:
restassuredと、このRESTをテストし、与えられた検索用語がすべての行の最初または最後の名前に含まれていることを確認する方法[
{"id": 1, "firstName": "Joe", "lastName": "Doe"},
{"id": 2, "firstName": "Alex", "lastName": "Joelson"}
]
、大文字と小文字を区別しませんか?あなたがUser
オブジェクトを持っている場合は、検証をより簡単にするためにジャクソンやJsonPathを使用してに見て
Response response = given().when().get("/user/search");
response.then().statusCode(200);
JSONArray users = new JSONArray(response.asString());
for (int i = 0; i < users.length(); i++) {
JSONObject user = users.getJSONObject(i);
String firstName = user.getString("firstName").toLowercase();
String lastName = user.getString("lastName").toLowercase();
Assert.assertTrue(firstName.contains("joe") || lastName.contains("joe"));
}
:User
オブジェクトなし
given()
.when()
.get("/user/search")
.then()
.statusCode(200)
.body(?)