* {@link Consumes} works.
*
* @throws Exception
*/
public void testGETOnlyDifferByConsumesAndProduces() throws Exception {
ClientResponse response =
client.resource(getBaseURI() + "/targeting/resourceconsumesandproduces")
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).get();
assertEquals(200, response.getStatusCode());
assertEquals("Hello JSON Consumes And Produces", response.getEntity(String.class));
assertEquals("application/json", response.getHeaders().getFirst("Content-Type"));
response =
client.resource(getBaseURI() + "/targeting/resourceconsumesandproduces")
.contentType(MediaType.APPLICATION_JSON).get();
assertEquals(200, response.getStatusCode());
assertEquals("Hello JSON Consumes And Produces", response.getEntity(String.class));
assertEquals("application/json", response.getHeaders().getFirst("Content-Type"));
/*
* due to no request Accept header, this is actually undefined behavior
* whether it hits the JSON or the XML on the Produces side
*/
response =
client.resource(getBaseURI() + "/targeting/resourceconsumesandproduces")
.contentType(MediaType.APPLICATION_XML).get();
assertEquals(200, response.getStatusCode());
if ("application/json".equals(response.getHeaders().getFirst("Content-Type"))) {
assertEquals(200, response.getStatusCode());
assertEquals("Hello XML Consumes And JSON Produces", response.getEntity(String.class));
assertEquals("application/json", response.getHeaders().getFirst("Content-Type"));
} else {
assertEquals(200, response.getStatusCode());
assertEquals("Hello XML Consumes And Produces", response.getEntity(String.class));
assertEquals("application/xml", response.getHeaders().getFirst("Content-Type"));
}
response =
client.resource(getBaseURI() + "/targeting/resourceconsumesandproduces")
.contentType(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).get();
assertEquals(200, response.getStatusCode());
assertEquals("Hello XML Consumes And Produces", response.getEntity(String.class));
assertEquals("application/xml", response.getHeaders().getFirst("Content-Type"));
response =
client.resource(getBaseURI() + "/targeting/resourceconsumesandproduces")
.contentType(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_JSON).get();
assertEquals(200, response.getStatusCode());
assertEquals("Hello XML Consumes And JSON Produces", response.getEntity(String.class));
assertEquals("application/json", response.getHeaders().getFirst("Content-Type"));
}