I have a REST-service that takes in a number of query-params, amongst other things a list of strings. I use RestAssured to test this REST-service, but I am experiencing some problems with passing the list to the service.
My REST-service:
@GET
@Consumes(Mediatyper.JSON_UTF8)
@Produces(Mediatyper.JSON_UTF8)
public AggregerteDataDTO doSearch(@QueryParam("param1") final String param1,
@QueryParam("param2") final String param2,
@QueryParam("list") final List<String> list) {
My RestAssured test:
public void someTest() {
final String url = BASE_URL + "/search?param1=2014¶m2=something&list=item1&list=item2";
final String json = given()
.expect()
.statusCode(200)
.when()
.get(url)
.asString();
When I print the url, it looks like this:
http://localhost:9191/application/rest/search?param1=2014¶m2=something&list=item1&list=item2
When I try this url in my browser, the REST-service correctly gets a list containing 2 elements. But, when run through my RestAssured-test, only the latter of the params are noticed, giving me a list of 1 element (containing "item2").
You should upgrade REST Assured to the latest version since I believe that this was a bug in older versions. You could also specify parameters like this:
final String json =
given().
param("param1", 2014).
param("param2", "something").
param("list", "item1", "item2").
when().
get("/search").
then().
statusCode(200).
extract().
body().asString();