RestAssured - transfer list as QueryParam

I have a REST service that accepts multiple query parameters, among others a list of strings. I am using RestAssured to test this REST service, but I am having some problems 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&param2=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 & param2 = something & list = item1 & list = item2

When I try to use this url in my browser the REST service correctly gets a list containing 2 items. But when you pass my RestAssured test, only the last of the parameters is noticed, giving me a 1-item list (containing "item2").

+3


source to share


1 answer


You should update REST Assured to the latest version as I believe this was a bug in older versions. You can 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();  

      

+8


source







All Articles