@Test public void shouldReturnErrorMessageWhenExceptionOccursOnSupplyLineUpdate() { SupplyLine supplyLine = new SupplyLine(1L); doThrow(new DataException("error")).when(service).save(supplyLine); ResponseEntity<OpenLmisResponse> responseEntity = controller.update(supplyLine, 1L, request); verify(service).save(supplyLine); verify(messageService, never()).message(anyString(), anyString()); assertThat(responseEntity.getBody().getErrorMsg(), CoreMatchers.is("error")); assertThat(supplyLine.getModifiedBy(), CoreMatchers.is(1L)); }
@RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") public ResponseEntity<OpenLmisResponse> update(@RequestBody SupplyLine supplyLine, @PathVariable(value = "id") Long supervisoryNodeId, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); supplyLine.setModifiedBy(userId); supplyLine.setId(supervisoryNodeId); try { service.save(supplyLine); } catch (DataException de) { response = OpenLmisResponse.error(de, BAD_REQUEST); return response; } response = OpenLmisResponse.success(messageService.message("message.supply.line.updated.success")); response.getBody().addData(SUPPLY_LINE_ID, supplyLine.getId()); return response; }
SupplyLineController extends BaseController { @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") public ResponseEntity<OpenLmisResponse> update(@RequestBody SupplyLine supplyLine, @PathVariable(value = "id") Long supervisoryNodeId, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); supplyLine.setModifiedBy(userId); supplyLine.setId(supervisoryNodeId); try { service.save(supplyLine); } catch (DataException de) { response = OpenLmisResponse.error(de, BAD_REQUEST); return response; } response = OpenLmisResponse.success(messageService.message("message.supply.line.updated.success")); response.getBody().addData(SUPPLY_LINE_ID, supplyLine.getId()); return response; } }
SupplyLineController extends BaseController { @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") public ResponseEntity<OpenLmisResponse> update(@RequestBody SupplyLine supplyLine, @PathVariable(value = "id") Long supervisoryNodeId, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); supplyLine.setModifiedBy(userId); supplyLine.setId(supervisoryNodeId); try { service.save(supplyLine); } catch (DataException de) { response = OpenLmisResponse.error(de, BAD_REQUEST); return response; } response = OpenLmisResponse.success(messageService.message("message.supply.line.updated.success")); response.getBody().addData(SUPPLY_LINE_ID, supplyLine.getId()); return response; }  }
SupplyLineController extends BaseController { @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") public ResponseEntity<OpenLmisResponse> update(@RequestBody SupplyLine supplyLine, @PathVariable(value = "id") Long supervisoryNodeId, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); supplyLine.setModifiedBy(userId); supplyLine.setId(supervisoryNodeId); try { service.save(supplyLine); } catch (DataException de) { response = OpenLmisResponse.error(de, BAD_REQUEST); return response; } response = OpenLmisResponse.success(messageService.message("message.supply.line.updated.success")); response.getBody().addData(SUPPLY_LINE_ID, supplyLine.getId()); return response; }  @RequestMapping(value = "/search", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") ResponseEntity<OpenLmisResponse> search(@RequestParam(value = "searchParam") String searchParam,
                                                 @RequestParam(value = "column") String column,
                                                 @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                 @Value("${search.page.size}") String limit); @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") ResponseEntity<OpenLmisResponse> insert(@RequestBody SupplyLine supplyLine,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") ResponseEntity<OpenLmisResponse> update(@RequestBody SupplyLine supplyLine,
                                                 @PathVariable(value = "id") Long supervisoryNodeId,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") SupplyLine getById(@PathVariable(value = "id") Long id); @RequestMapping(value = "/supplying-depots.json", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> getSupplyingDepots(HttpServletRequest request); }
SupplyLineController extends BaseController { @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") public ResponseEntity<OpenLmisResponse> update(@RequestBody SupplyLine supplyLine, @PathVariable(value = "id") Long supervisoryNodeId, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); supplyLine.setModifiedBy(userId); supplyLine.setId(supervisoryNodeId); try { service.save(supplyLine); } catch (DataException de) { response = OpenLmisResponse.error(de, BAD_REQUEST); return response; } response = OpenLmisResponse.success(messageService.message("message.supply.line.updated.success")); response.getBody().addData(SUPPLY_LINE_ID, supplyLine.getId()); return response; }  @RequestMapping(value = "/search", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") ResponseEntity<OpenLmisResponse> search(@RequestParam(value = "searchParam") String searchParam,
                                                 @RequestParam(value = "column") String column,
                                                 @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                 @Value("${search.page.size}") String limit); @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") ResponseEntity<OpenLmisResponse> insert(@RequestBody SupplyLine supplyLine,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") ResponseEntity<OpenLmisResponse> update(@RequestBody SupplyLine supplyLine,
                                                 @PathVariable(value = "id") Long supervisoryNodeId,
                                                 HttpServletRequest request); @RequestMapping(value = "/{id}", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_SUPPLY_LINE')") SupplyLine getById(@PathVariable(value = "id") Long id); @RequestMapping(value = "/supplying-depots.json", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> getSupplyingDepots(HttpServletRequest request); static final String SUPPLY_LINES; static final String PAGINATION; static final String SUPPLYLINES; static final String SUPPLY_LINE_ID; }