2016-10-06 8 views
0

Ich schreibe Testfälle in RestAssured, um Rest Webservices mit Federmvc zu testen.RestAssured Test hateoas

Rest Antwort ist

{ 
    "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": [ 
{ 
..... 

und mein Testfall ist

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"}); 
      } 
     }); 

Der Testfall mit Fehler fehlschlägt

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] 

Ich habe sogar versucht

equalTo("[http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10"); 

die als

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] 

Ich bin mit dem Rest zugesichert 3.0.1 Fehler würde. Danke im Vorraus für deine Hilfe.

Antwort

0

Versuchen Sie, diese

assertEquals("http://www.localhost.com:8080/v1/communities?offset=0&limit=10", given().when().get("/communities").body().jsonPath().get("links[0].href"));