My code under test uses Apache HttpClient to post some JSON content:
HttpPost httpPost = new HttpPost("http://foo.api")
HttpEntity reqEntity = new StringEntity(data, "UTF-8") // <- where data is a JSON string
response = httpClient.execute(httpPost) // <- Betamax proxy-configured httpClient
I was expecting to see the JSON appear in the tape file in the body section, but it's empty. I have also tried annotating my Spock test method to no effect:
import static betamax.MatchRule.*
@Betamax(match=[method, uri, body], tape="tape name")
I'm using Grails 1.3.7 and, in my buildConfig,
excludes "groovy", "xml-apis"
Same issue here ... Here's a tiny project for you to reproduce the issue: https://github.com/Ookami86/betamax-post-body-bug
Run gradle test and take a at the created .yaml file.
Thanks. I'll look into this.
For the record the match property on the annotation should make no difference to what gets stored in the tape, only the criteria used for determining if an existing recording is a match to the current request.
Failing test for #50
#50 check post body gets recorded with UrlConnection
You can see from the test I've added in 71d27e2 that this doesn't work when using a UrlConnection either.
The problem seems to be that org.eclipse.jetty.server.Request.getInputStream is always returning an empty stream. I presume I'm using it incorrectly but the code in the request & response abstraction is pretty messy anyway so I might attempt a rewrite as part of the fix.