我正在尝试使用 Groovy HTTPBuilder 编写一个集成测试,该测试将验证正文中返回的正确错误消息以及 HTTP 409 状态消息。但是,我无法弄清楚在失败情况下如何实际访问 HTTP 响应的正文。
http.request(ENV_URL, Method.POST, ContentType.TEXT) {
uri.path = "/curate/${id}/submit"
contentType = ContentType.JSON
response.failure = { failresp_inner ->
failresp = failresp_inner
}
}
then:
assert failresp.status == 409
// I would like something like
//assert failresp.data == "expected error message"
这是来自服务器的 HTTP 响应的样子:
2013-11-13 18:17:58,726 DEBUG wire - << "HTTP/1.1 409 Conflict[\r][\n]"
2013-11-13 18:17:58,726 DEBUG wire - << "Date: Wed, 13 Nov 2013 23:17:58 GMT[\r][\n]"
2013-11-13 18:17:58,726 DEBUG wire - << "Content-Type: text/plain[\r][\n]"
2013-11-13 18:17:58,726 DEBUG wire - << "Transfer-Encoding: chunked[\r][\n]"
2013-11-13 18:17:58,727 DEBUG wire - << "[\r][\n]"
2013-11-13 18:17:58,728 DEBUG wire - << "E[\r][\n]"
2013-11-13 18:17:58,728 DEBUG wire - << "expected error message"
2013-11-13 18:17:58,728 DEBUG wire - << "[\r][\n]"
2013-11-13 18:17:58,728 DEBUG wire - << "0[\r][\n]"
2013-11-13 18:17:58,728 DEBUG wire - << "[\r][\n]"