I have recently started exploring Dropwizard and I don't understand how to 
properly test errors emitted from resource endpoints.

In the endpoint below I throw a javax.ws.rs.BadRequestException.
https://gist.github.com/pomle/734e68096aa7307ae58a5f1efa849fa3#file-resource-java-L27

This generates a nice JSON formatted error when probed using `curl`.

HTTP/1.1 400 Bad Request
> Date: Tue, 07 Nov 2017 10:21:09 GMT
> Content-Type: application/json
> Content-Length: 83
> {"code":400,"message":"Video ac4827da-c2e4-11e7-8b6a-4ccc6ae15a71 already 
> exists."}



When I write a test for this I use the ResourceTestRule to create a HTTP 
client but when the request is executed a javax.ws.rs.ClientErrorException 
is thrown.
https://gist.github.com/pomle/734e68096aa7307ae58a5f1efa849fa3#file-resourcetest-java-L46

As far as I can tell the ClientErrorException does not contain the 
information from the original exception.

I have tried writing the test by calling the resource method directly on 
the Resource class.
https://gist.github.com/pomle/734e68096aa7307ae58a5f1efa849fa3#file-resourcetest-java-L63

How can I structure my test using the ResourceTestRule and assert that the 
error is of the expected type and has the expected message?

Thank you!



-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to