@Test public void shouldReturnStatusBadRequestIfDataException() throws Exception { setupStockData(); mockStatic(RestResponse.class); DataException dataException = new DataException("invalid data"); doThrow(dataException).when(restStockCardService).adjustStock(facilityId, stockEventList, userId); ResponseEntity<RestResponse> expectedResponse = new ResponseEntity<>(new RestResponse(ERROR, "invalid data"), HttpStatus.BAD_REQUEST); when(error(dataException.getOpenLmisMessage(), HttpStatus.BAD_REQUEST)).thenReturn(expectedResponse); ResponseEntity<RestResponse> response = restStockCardController.adjustStock(facilityId, stockEventList, principal); assertThat(response.getStatusCode(), is(HttpStatus.BAD_REQUEST)); assertThat((String) response.getBody().getData().get(ERROR), is("invalid data")); }
@RequestMapping(value = "/rest-api/facilities/{facilityId}/stockCards", method = POST, headers = ACCEPT_JSON) public ResponseEntity adjustStock(@PathVariable long facilityId, @RequestBody(required = true) List<StockEvent> events, Principal principal) { try { restStockCardService.adjustStock(facilityId, events, loggedInUserId(principal)); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } return RestResponse.success("msg.stockmanagement.adjuststocksuccess"); }
RestStockCardController extends BaseController { @RequestMapping(value = "/rest-api/facilities/{facilityId}/stockCards", method = POST, headers = ACCEPT_JSON) public ResponseEntity adjustStock(@PathVariable long facilityId, @RequestBody(required = true) List<StockEvent> events, Principal principal) { try { restStockCardService.adjustStock(facilityId, events, loggedInUserId(principal)); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } return RestResponse.success("msg.stockmanagement.adjuststocksuccess"); } }
RestStockCardController extends BaseController { @RequestMapping(value = "/rest-api/facilities/{facilityId}/stockCards", method = POST, headers = ACCEPT_JSON) public ResponseEntity adjustStock(@PathVariable long facilityId, @RequestBody(required = true) List<StockEvent> events, Principal principal) { try { restStockCardService.adjustStock(facilityId, events, loggedInUserId(principal)); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } return RestResponse.success("msg.stockmanagement.adjuststocksuccess"); }  }
RestStockCardController extends BaseController { @RequestMapping(value = "/rest-api/facilities/{facilityId}/stockCards", method = POST, headers = ACCEPT_JSON) public ResponseEntity adjustStock(@PathVariable long facilityId, @RequestBody(required = true) List<StockEvent> events, Principal principal) { try { restStockCardService.adjustStock(facilityId, events, loggedInUserId(principal)); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } return RestResponse.success("msg.stockmanagement.adjuststocksuccess"); }  @RequestMapping(value = "/rest-api/facilities/{facilityId}/stockCards", method = POST, headers = ACCEPT_JSON) ResponseEntity adjustStock(@PathVariable long facilityId,
                                      @RequestBody(required = true) List<StockEvent> events,
                                      Principal principal); }
RestStockCardController extends BaseController { @RequestMapping(value = "/rest-api/facilities/{facilityId}/stockCards", method = POST, headers = ACCEPT_JSON) public ResponseEntity adjustStock(@PathVariable long facilityId, @RequestBody(required = true) List<StockEvent> events, Principal principal) { try { restStockCardService.adjustStock(facilityId, events, loggedInUserId(principal)); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } return RestResponse.success("msg.stockmanagement.adjuststocksuccess"); }  @RequestMapping(value = "/rest-api/facilities/{facilityId}/stockCards", method = POST, headers = ACCEPT_JSON) ResponseEntity adjustStock(@PathVariable long facilityId,
                                      @RequestBody(required = true) List<StockEvent> events,
                                      Principal principal);  }