RestAssured 测试 hateoas
RestAssured test hateoas
我正在 RestAssured 中编写测试用例,以使用 spring mvc 测试其余 Web 服务。
其余反应是
{
"links": [
{
"rel": "self",
"href": "http://www.localhost.com:8080/v1/communities?offset=0&limit=10"
},
{
"rel": "next",
"href": "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"
}
],
"content": [
{
.....
我的测试用例是
when().
get("/communities").
then().
root("links").
body("href", new ResponseAwareMatcher() {
public Matcher<? extends Object> matcher(ResponseBody response) {
return equalTo(new String[] {"http://www.localhost.com:8080/v1/communities?offset=0&limit=10", "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"});
}
});
测试用例因错误而失败
java.lang.AssertionError: 1 expectation failed.
JSON path links.href doesn't match.
Expected: ["http://www.localhost.com:8080/v1/communities?offset=0&limit=10", "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"]
Actual: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]
我什至试过了
equalTo("[http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10");
这会出错为
java.lang.AssertionError: 1 expectation failed.
JSON path links.href doesn't match.
Expected: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]]
Actual: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]
我正在使用 Rest Assured 3.0.1。提前感谢您的帮助。
试试这个
assertEquals("http://www.localhost.com:8080/v1/communities?offset=0&limit=10", given().when().get("/communities").body().jsonPath().get("links[0].href"));
我正在 RestAssured 中编写测试用例,以使用 spring mvc 测试其余 Web 服务。
其余反应是
{
"links": [
{
"rel": "self",
"href": "http://www.localhost.com:8080/v1/communities?offset=0&limit=10"
},
{
"rel": "next",
"href": "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"
}
],
"content": [
{
.....
我的测试用例是
when().
get("/communities").
then().
root("links").
body("href", new ResponseAwareMatcher() {
public Matcher<? extends Object> matcher(ResponseBody response) {
return equalTo(new String[] {"http://www.localhost.com:8080/v1/communities?offset=0&limit=10", "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"});
}
});
测试用例因错误而失败
java.lang.AssertionError: 1 expectation failed.
JSON path links.href doesn't match.
Expected: ["http://www.localhost.com:8080/v1/communities?offset=0&limit=10", "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"]
Actual: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]
我什至试过了
equalTo("[http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10");
这会出错为
java.lang.AssertionError: 1 expectation failed.
JSON path links.href doesn't match.
Expected: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]]
Actual: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]
我正在使用 Rest Assured 3.0.1。提前感谢您的帮助。
试试这个
assertEquals("http://www.localhost.com:8080/v1/communities?offset=0&limit=10", given().when().get("/communities").body().jsonPath().get("links[0].href"));