Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting header values, Status code etc from Jax-Rs Response class in Junit

I am using Restful web Service using Dropwizard. And generating response as:

    Response response = resources.client().resource("/url")
    .header("CONTENT-TYPE","value")
    .post(Response.class, jsonRequestString);

Now I want to write unit test to ensure the returned content type is corrected in Response Object. how to do that?

like image 485
Bharat Pahalwani Avatar asked Dec 02 '25 14:12

Bharat Pahalwani


1 Answers

You can use the ClientResponse type in Jackson. For example, using a GET operation:

ClientResponse response = Client.create()
                                .resource(url)
                                .get(ClientResponse.class);
String contentType = response.getHeaders()
                             .getFirst("Content-Type");
System.out.println(contentType);
like image 88
McDowell Avatar answered Dec 04 '25 05:12

McDowell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!