/** * Web service endpoint to delete a single Greeting entity. The HTTP request * body is empty. The primary key identifier of the Greeting to be deleted * is supplied in the URL as a path variable. * * If deleted successfully, the service returns an empty response body with * HTTP status 204. * * If not deleted successfully, the service returns an empty response body * with HTTP status 500. * * @param id A Long URL path variable containing the Greeting primary key * identifier. * @return A ResponseEntity with an empty response body and a HTTP status * code as described in the method comment. */ @RequestMapping( value = "/api/greetings/{id}", method = RequestMethod.DELETE) public ResponseEntity<Greeting> deleteGreeting( @PathVariable("id") Long id) { logger.info("> deleteGreeting id:{}", id); greetingService.delete(id); logger.info("< deleteGreeting id:{}", id); return new ResponseEntity<Greeting>(HttpStatus.NO_CONTENT); }
/** * Web service endpoint to delete a single Greeting entity. The HTTP request * body is empty. The primary key identifier of the Greeting to be deleted * is supplied in the URL as a path variable. * * If deleted successfully, the service returns an empty response body with * HTTP status 204. * * If not deleted successfully, the service returns an empty response body * with HTTP status 500. * * @param id A Long URL path variable containing the Greeting primary key * identifier. * @return A ResponseEntity with an empty response body and a HTTP status * code as described in the method comment. */ @RequestMapping( value = "/api/greetings/{id}", method = RequestMethod.DELETE) public ResponseEntity<Greeting> deleteGreeting( @PathVariable("id") Long id) { logger.info("> deleteGreeting id:{}", id); greetingService.delete(id); logger.info("< deleteGreeting id:{}", id); return new ResponseEntity<Greeting>(HttpStatus.NO_CONTENT); }
@Test public void testDelete() { Long id = new Long(1); Greeting entity = service.findOne(id); Assert.assertNotNull("failure - expected not null", entity); service.delete(id); Collection<Greeting> list = service.findAll(); Assert.assertEquals("failure - expected size", 1, list.size()); Greeting deletedEntity = service.findOne(id); Assert.assertNull("failure - expected null", deletedEntity); }
@Test public void testDeleteGreeting() throws Exception { // Create some test data Long id = new Long(1); // Perform the behavior being tested String uri = "/api/greetings/{id}"; MvcResult result = mvc.perform(MockMvcRequestBuilders.delete(uri, id)) .andReturn(); // Extract the response status and body String content = result.getResponse().getContentAsString(); int status = result.getResponse().getStatus(); // Verify the GreetingService.delete method was invoked once verify(greetingService, times(1)).delete(id); // Perform standard JUnit assertions on the test results Assert.assertEquals("failure - expected HTTP status 204", 204, status); Assert.assertTrue("failure - expected HTTP response body to be empty", content.trim().length() == 0); }