Question

I am testing a DELETE verb in the following way which seems to work just fine.

@Test
public void testDelete() throws Exception {
    WebResource webResourceTest = webResource.path("/deletesomestuff/delete").queryParam("FT","From Test");
    final String responseString = webResourceTest.type(MediaType.TEXT_PLAIN).delete(String.class);
    Assert.assertEquals("Request fulfilled.", responseString);
}

This returns what I am after in a String. Here is a snippet from the actual DELETE API call.

@DELETE
@Path("/delete")
@Produces(MediaType.TEXT_PLAIN)
public Response delete(@PathParam("/delete") String deleteString) {
    <snip> 
    return Response.status(204).entity("Request fulfilled.").build();
}

The DELETE calls works fine as well and returns the correct String but my question is this. How can I get the response status returned via a WebResource? I just can't seem to find a way to retrieve that. The test works as-is but I am just curious to know if pulling the response from a WebResource is possible. Now when I use ClientResponse from my junit test I always receive a 200.

I have also tested the DELETE API call with a curl:

curl -i -X DELETE /webapi/deletesomestuff/delete?FT=From+Test
HTTP/1.1 204 No Content
Server: Apache-Coyote/1.1
Content-Type: text/plain
Date: Mon, 08 Jul 2013 18:11:13 GMT

A 204 was returned.

Thanks!

Was it helpful?

Solution

I guess this should work:

ClientResponse response = webResourceTest.type(MediaType.TEXT_PLAIN).delete(ClientResponse.class);
Assert.assertEquals(204, response.getStatus());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top