RestAssured-将列表作为QueryParam传递 [英] RestAssured - passing list as QueryParam

查看:155
本文介绍了RestAssured-将列表作为QueryParam传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个REST服务,它接受许多查询参数,此外还包含字符串列表.我使用RestAssured来测试此REST服务,但是在将列表传递给服务时遇到了一些问题.

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.

我的REST服务:

@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) {

我的RestAssured测试:

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

当我在浏览器中尝试此URL时,REST服务正确获取包含2个元素的列表.但是,当通过我的RestAssured测试运行时,仅会注意到后者的参数,从而为我提供了1个元素(包含"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").

推荐答案

您应该将REST Assured升级到最新版本,因为我认为这是旧版本中的错误.您还可以指定如下参数:

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();  

这篇关于RestAssured-将列表作为QueryParam传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆