简体   繁体   中英

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM