英文:
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();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论