@SuppressWarnings("unchecked") @Test public void testUpdate() { 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"); Map<String, Object> model = ninjaCrudController.update(command, id, bindingResult, modelMap, mockRequest, mockResponse); assertEquals(command, model.get("command")); List<MessageResponse> messages = (List<MessageResponse>)model.get("messages"); assertEquals(1, messages.size()); MessageResponse message = messages.get(0); assertEquals("Record has been successfully updated.", message.getMessage()); Mockito.verify(ninjaService).save(command); }
@RequestMapping(value = "{id}", method = { RequestMethod.PUT, RequestMethod.POST }, produces = "application/json") @ResponseView(Views.FormView.class) public final @ResponseBody Map<String, Object> update(@FormBind(name = "formCommand") T command, @PathVariable("id") Long id, BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); List<MessageResponse> messages = new ArrayList<MessageResponse>(); if (command.getId() == null) { command.setId(id); } updateTx(command, bindingResult, uiModel, request, response); messages.addAll(CrudUtil.buildSuccessMessage(command, "update", request.getLocale(), messageSource)); model.put("command", command); model.put("messages", messages); return model; }
BaseCrudController implements InitializingBean { @RequestMapping(value = "{id}", method = { RequestMethod.PUT, RequestMethod.POST }, produces = "application/json") @ResponseView(Views.FormView.class) public final @ResponseBody Map<String, Object> update(@FormBind(name = "formCommand") T command, @PathVariable("id") Long id, BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); List<MessageResponse> messages = new ArrayList<MessageResponse>(); if (command.getId() == null) { command.setId(id); } updateTx(command, bindingResult, uiModel, request, response); messages.addAll(CrudUtil.buildSuccessMessage(command, "update", request.getLocale(), messageSource)); model.put("command", command); model.put("messages", messages); return model; } }
BaseCrudController implements InitializingBean { @RequestMapping(value = "{id}", method = { RequestMethod.PUT, RequestMethod.POST }, produces = "application/json") @ResponseView(Views.FormView.class) public final @ResponseBody Map<String, Object> update(@FormBind(name = "formCommand") T command, @PathVariable("id") Long id, BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); List<MessageResponse> messages = new ArrayList<MessageResponse>(); if (command.getId() == null) { command.setId(id); } updateTx(command, bindingResult, uiModel, request, response); messages.addAll(CrudUtil.buildSuccessMessage(command, "update", request.getLocale(), messageSource)); model.put("command", command); model.put("messages", messages); return model; }  }
BaseCrudController implements InitializingBean { @RequestMapping(value = "{id}", method = { RequestMethod.PUT, RequestMethod.POST }, produces = "application/json") @ResponseView(Views.FormView.class) public final @ResponseBody Map<String, Object> update(@FormBind(name = "formCommand") T command, @PathVariable("id") Long id, BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); List<MessageResponse> messages = new ArrayList<MessageResponse>(); if (command.getId() == null) { command.setId(id); } updateTx(command, bindingResult, uiModel, request, response); messages.addAll(CrudUtil.buildSuccessMessage(command, "update", request.getLocale(), messageSource)); model.put("command", command); model.put("messages", messages); return model; }  @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.PUT, RequestMethod.POST }, produces = "application/json") @ResponseView(Views.FormView.class) public final @ResponseBody Map<String, Object> update(@FormBind(name = "formCommand") T command, @PathVariable("id") Long id, BindingResult bindingResult, Model uiModel, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); List<MessageResponse> messages = new ArrayList<MessageResponse>(); if (command.getId() == null) { command.setId(id); } updateTx(command, bindingResult, uiModel, request, response); messages.addAll(CrudUtil.buildSuccessMessage(command, "update", request.getLocale(), messageSource)); model.put("command", command); model.put("messages", messages); return model; }  @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();  }