CodeSystemController extends AbstractNodeController { @RequestMapping(value = "/codeSystem/delete/{id}", method = RequestMethod.POST) public String delete(@PathVariable("id") Long id, RedirectAttributes redirectAttribute) { LOGGER.debug("Deleting codeSystem with id: " + id); CodeSystemDto deleted = new CodeSystemDto(); try { deleted = codeSystemService.delete(id); deleted.setError(false); deleted.setSuccessMessage(" CodeSystem with Code: " + deleted.getCode() + " and OID: " + deleted.getCodeSystemOId() +" is deleted Successfully. "); } catch (CodeSystemNotFoundException e) { LOGGER.debug("No codeSystem found with id: " + id); deleted.setError(true); deleted.setErrorMessage(ERROR_MESSAGE_KEY_DELETED_CODESYSTEM_WAS_NOT_FOUND); } redirectAttribute.addFlashAttribute(MODEL_ATTIRUTE_CODESYSTEMDTO, deleted); return createRedirectViewPath(REDIRECT_ID_MAPPING_LIST); }  @RequestMapping(value = REQUEST_MAPPING_LIST, method = RequestMethod.GET) String showCreateCodeSystemForm(Model model, HttpServletRequest request); @RequestMapping(value = "codeSystemAdd.html", method = RequestMethod.GET) String codeSystemAddForm(Model model, HttpServletRequest request); @RequestMapping(value = "/codeSystem/create", method = RequestMethod.POST) String submitCreateCodeSystemForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_CODESYSTEMDTO) CodeSystemDto created, RedirectAttributes redirectAttribute,  Model model); @RequestMapping(value = "/codeSystem/delete/{id}", method = RequestMethod.POST) String delete(@PathVariable("id") Long id, RedirectAttributes redirectAttribute); @RequestMapping(value = "/codeSystem/edit/{id}", method = RequestMethod.GET) String showEditCodeSystemForm(@PathVariable("id") Long id, Model model, RedirectAttributes attributes); @RequestMapping(value = "/codeSystem/edit/{id}", method = RequestMethod.POST) String submitEditCodeSystemForm(@ModelAttribute(MODEL_ATTIRUTE_CODESYSTEMDTO) CodeSystemDto updated, @PathVariable("id") Long id,RedirectAttributes redirectAttribute);  }
@Test public void testDeleteCodeSystem() throws Exception{ CodeSystemDto deleted=new CodeSystemDto(); when(codeSystemService.delete(anyLong())).thenReturn(deleted); mockMvc.perform(post("/sysadmin/codeSystem/delete/1")) .andExpect(view().name("redirect:../../home")); }
@Test public void testDeleteCodeSystemForm_throwException() throws Exception{ when(codeSystemService.delete(anyLong())).thenThrow(new CodeSystemNotFoundException()); mockMvc.perform(post("/sysadmin/codeSystem/delete/1")) .andExpect(view().name("redirect:../../home")); }