如何使用REST-assured验证分块响应数据?

huangapple go评论64阅读模式
英文:

How to verify chunked response data with REST-assured?

问题

我有一个返回text/csv类型的Jersey资源,使用ChunkedOutput返回。

我正试图使用REST-assured编写一个测试,用于验证返回数据的正确性。

不幸的是,我在REST assured的文档中找不到有关验证分块响应数据的任何信息,并且谷歌搜索也没有产生有用的结果。

我可以像这样验证状态代码、响应头等:

given()
    .spec(mySpec)
    .accept("text/csv")
    .when()
    .post("/mycsvpath")
    .then()
    .statusCode(200);

我可以看到响应中有Transfer-Encoding=chunked头,但我如何验证实际数据呢?

英文:

I have a Jersey resource that returns text/csv as ChunkedOutput.

I'm trying to write a test with REST-assured that should verify correctness of the returned data.

Unfortunately I can't find anything about verifying chunked response data with REST assured in their docs and googling hasn't yielded anything useful.

I can verify status code, response headers, etc. like this:

given()
    .spec(mySpec)
    .accept("text/csv")
    .when()
    .post("/mycsvpath")
    .then()
    .statusCode(200);

I can see that the response has the Transfer-Encoding=chunked header, but how would I verify the actual data?

答案1

得分: 1

好的,我已经弄清楚了。其实非常简单:

Response r = given()
                .spec(mySpec)
                .accept("text/csv")
                .when()
                .post("/mycsvpath");
String data = r.asString();
英文:

OK, I figured it out. It's actually really simple:

Response r = given()
                .spec(mySpec)
                .accept("text/csv")
                .when()
                .post("/mycsvpath")
String data = r.asString();

huangapple
  • 本文由 发表于 2020年4月9日 18:58:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/61119575.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定