@Test(expected = DataAccessException.class) public void testDeleteUnsuccessful() throws Exception { Long id = 1l; ExtendedModelMap modelMap = new ExtendedModelMap(); Ninja command = new Ninja(); command.setId(id); command.setFirstName("Sasuke"); command.setLastName("Uchiha"); BindingResult bindingResult = new BeanPropertyBindingResult(command, "ninja"); Mockito.doThrow(new DataAccessException("Mock exception")).when(ninjaService).delete(id); ninjaCrudController.delete(id, command, bindingResult, modelMap, mockRequest, mockResponse); }
@RequestMapping(value = "{id}", method = RequestMethod.DELETE, produces = "application/json") public final @ResponseBody Map<String, Object> delete(@PathVariable("id") Long id, T command, BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); List<MessageResponse> messages = new ArrayList<MessageResponse>(); if (id >= 0) { try { deleteTx(id, bindingResult, uiModel, request, response); messages.addAll(CrudUtil.buildSuccessMessage(command, "delete", request.getLocale(), messageSource)); model.put("messages", messages); return model; } catch (Exception e) { String message = "Failed to delete " + this.entityBeanType + " with id = [" + id + "]"; _log.error(message, e); throw new DataAccessException(message, e); } } else { String message = "Invalid id = [" + id + "] for delete operation of " + this.entityBeanType; _log.error(message); throw new DataAccessException(message); } }
BaseCrudController implements InitializingBean { @RequestMapping(value = "{id}", method = RequestMethod.DELETE, produces = "application/json") public final @ResponseBody Map<String, Object> delete(@PathVariable("id") Long id, T command, BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); List<MessageResponse> messages = new ArrayList<MessageResponse>(); if (id >= 0) { try { deleteTx(id, bindingResult, uiModel, request, response); messages.addAll(CrudUtil.buildSuccessMessage(command, "delete", request.getLocale(), messageSource)); model.put("messages", messages); return model; } catch (Exception e) { String message = "Failed to delete " + this.entityBeanType + " with id = [" + id + "]"; _log.error(message, e); throw new DataAccessException(message, e); } } else { String message = "Invalid id = [" + id + "] for delete operation of " + this.entityBeanType; _log.error(message); throw new DataAccessException(message); } } }
BaseCrudController implements InitializingBean { @RequestMapping(value = "{id}", method = RequestMethod.DELETE, produces = "application/json") public final @ResponseBody Map<String, Object> delete(@PathVariable("id") Long id, T command, BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); List<MessageResponse> messages = new ArrayList<MessageResponse>(); if (id >= 0) { try { deleteTx(id, bindingResult, uiModel, request, response); messages.addAll(CrudUtil.buildSuccessMessage(command, "delete", request.getLocale(), messageSource)); model.put("messages", messages); return model; } catch (Exception e) { String message = "Failed to delete " + this.entityBeanType + " with id = [" + id + "]"; _log.error(message, e); throw new DataAccessException(message, e); } } else { String message = "Invalid id = [" + id + "] for delete operation of " + this.entityBeanType; _log.error(message); throw new DataAccessException(message); } }  }
BaseCrudController implements InitializingBean { @RequestMapping(value = "{id}", method = RequestMethod.DELETE, produces = "application/json") public final @ResponseBody Map<String, Object> delete(@PathVariable("id") Long id, T command, BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); List<MessageResponse> messages = new ArrayList<MessageResponse>(); if (id >= 0) { try { deleteTx(id, bindingResult, uiModel, request, response); messages.addAll(CrudUtil.buildSuccessMessage(command, "delete", request.getLocale(), messageSource)); model.put("messages", messages); return model; } catch (Exception e) { String message = "Failed to delete " + this.entityBeanType + " with id = [" + id + "]"; _log.error(message, e); throw new DataAccessException(message, e); } } else { String message = "Invalid id = [" + id + "] for delete operation of " + this.entityBeanType; _log.error(message); throw new DataAccessException(message); } }  @ExceptionHandler(Exception.class) @ResponseBody Map<String, Object> handleBindException(Exception ex,
			HttpServletRequest request); @RequestMapping(method = RequestMethod.GET, produces = "application/json") @ResponseView(Views.SearchView.class) final @ResponseBody SearchResults<T> search(@ModelAttribute("searchCommand") T command,
			BindingResult bindingResult, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.GET) final String searchHtml(@ModelAttribute("searchCommand") T command,
			BindingResult bindingResult, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"", "0"}, method = RequestMethod.POST, produces = "application/json") @ResponseView(Views.FormView.class) final @ResponseBody Map<String, Object> create(@FormBind(name = "formCommand") T command,
			BindingResult bindingResult, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = "{id}", method = { RequestMethod.PUT, RequestMethod.POST }, produces = "application/json") @ResponseView(Views.FormView.class) final @ResponseBody Map<String, Object> update(@FormBind(name = "formCommand") T command,
			@PathVariable("id") Long id, BindingResult bindingResult,
			Model uiModel, HttpServletRequest request,
			HttpServletResponse response); @RequestMapping(value = "{id}", method = RequestMethod.GET, produces = "application/json") @ResponseView(Views.FormView.class) final @ResponseBody T get(@PathVariable("id") Long id, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); void preProcessCommand(T command); @RequestMapping(value = "{id}", method = RequestMethod.GET) String getHtml(@PathVariable("id") Long id, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = "/view/{id}", method = RequestMethod.GET) String getDisplayHtml(@PathVariable("id") Long id, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = "{id}", method = RequestMethod.DELETE, produces = "application/json") final @ResponseBody Map<String, Object> delete(@PathVariable("id") Long id, T command,
			BindingResult bindingResult, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @SuppressWarnings({ "unchecked" }) @Override void afterPropertiesSet(); final BaseCrudService<T> getService(); }
BaseCrudController implements InitializingBean { @RequestMapping(value = "{id}", method = RequestMethod.DELETE, produces = "application/json") public final @ResponseBody Map<String, Object> delete(@PathVariable("id") Long id, T command, BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); List<MessageResponse> messages = new ArrayList<MessageResponse>(); if (id >= 0) { try { deleteTx(id, bindingResult, uiModel, request, response); messages.addAll(CrudUtil.buildSuccessMessage(command, "delete", request.getLocale(), messageSource)); model.put("messages", messages); return model; } catch (Exception e) { String message = "Failed to delete " + this.entityBeanType + " with id = [" + id + "]"; _log.error(message, e); throw new DataAccessException(message, e); } } else { String message = "Invalid id = [" + id + "] for delete operation of " + this.entityBeanType; _log.error(message); throw new DataAccessException(message); } }  @ExceptionHandler(Exception.class) @ResponseBody Map<String, Object> handleBindException(Exception ex,
			HttpServletRequest request); @RequestMapping(method = RequestMethod.GET, produces = "application/json") @ResponseView(Views.SearchView.class) final @ResponseBody SearchResults<T> search(@ModelAttribute("searchCommand") T command,
			BindingResult bindingResult, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.GET) final String searchHtml(@ModelAttribute("searchCommand") T command,
			BindingResult bindingResult, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"", "0"}, method = RequestMethod.POST, produces = "application/json") @ResponseView(Views.FormView.class) final @ResponseBody Map<String, Object> create(@FormBind(name = "formCommand") T command,
			BindingResult bindingResult, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = "{id}", method = { RequestMethod.PUT, RequestMethod.POST }, produces = "application/json") @ResponseView(Views.FormView.class) final @ResponseBody Map<String, Object> update(@FormBind(name = "formCommand") T command,
			@PathVariable("id") Long id, BindingResult bindingResult,
			Model uiModel, HttpServletRequest request,
			HttpServletResponse response); @RequestMapping(value = "{id}", method = RequestMethod.GET, produces = "application/json") @ResponseView(Views.FormView.class) final @ResponseBody T get(@PathVariable("id") Long id, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); void preProcessCommand(T command); @RequestMapping(value = "{id}", method = RequestMethod.GET) String getHtml(@PathVariable("id") Long id, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = "/view/{id}", method = RequestMethod.GET) String getDisplayHtml(@PathVariable("id") Long id, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = "{id}", method = RequestMethod.DELETE, produces = "application/json") final @ResponseBody Map<String, Object> delete(@PathVariable("id") Long id, T command,
			BindingResult bindingResult, Model uiModel,
			HttpServletRequest request, HttpServletResponse response); @SuppressWarnings({ "unchecked" }) @Override void afterPropertiesSet(); final BaseCrudService<T> getService();  }