@Test public void shouldGiveErrorMessageIfReportInvalid() throws Exception { String errorMessage = "some error"; Report report = new Report(); Rnr requisition = new Rnr(); requisition.setId(1L); DataException dataException = new DataException(errorMessage); doThrow(dataException).when(service).submitReport(report, 1L); ResponseEntity<RestResponse> expectResponse = new ResponseEntity<>(new RestResponse(ERROR, errorMessage), HttpStatus.BAD_REQUEST); when(error(dataException.getOpenLmisMessage(), HttpStatus.BAD_REQUEST)).thenReturn(expectResponse); ResponseEntity<RestResponse> response = controller.submitRequisition(report, principal); assertThat((String) response.getBody().getData().get(ERROR), is(errorMessage)); }
@RequestMapping(value = "/rest-api/requisitions", method = POST, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> submitRequisition(@RequestBody Report report, Principal principal) { Rnr requisition; try { requisition = restRequisitionService.submitReport(report, loggedInUserId(principal)); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } return response(RNR, requisition.getId(), CREATED); }
RestRequisitionController extends BaseController { @RequestMapping(value = "/rest-api/requisitions", method = POST, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> submitRequisition(@RequestBody Report report, Principal principal) { Rnr requisition; try { requisition = restRequisitionService.submitReport(report, loggedInUserId(principal)); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } return response(RNR, requisition.getId(), CREATED); } }
RestRequisitionController extends BaseController { @RequestMapping(value = "/rest-api/requisitions", method = POST, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> submitRequisition(@RequestBody Report report, Principal principal) { Rnr requisition; try { requisition = restRequisitionService.submitReport(report, loggedInUserId(principal)); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } return response(RNR, requisition.getId(), CREATED); }  }
RestRequisitionController extends BaseController { @RequestMapping(value = "/rest-api/requisitions", method = POST, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> submitRequisition(@RequestBody Report report, Principal principal) { Rnr requisition; try { requisition = restRequisitionService.submitReport(report, loggedInUserId(principal)); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } return response(RNR, requisition.getId(), CREATED); }  @RequestMapping(value = "/rest-api/requisitions", method = POST, headers = ACCEPT_JSON) ResponseEntity<RestResponse> submitRequisition(@RequestBody Report report, Principal principal); @RequestMapping(value = "/rest-api/sdp-requisitions", method = POST, headers = ACCEPT_JSON) ResponseEntity<RestResponse> submitSDPRequisition(@RequestBody Report report, Principal principal); @RequestMapping(value = "/rest-api/requisitions/{requisitionId}/approve", method = PUT, headers = ACCEPT_JSON) ResponseEntity<RestResponse> approve(@PathVariable Long requisitionId, @RequestBody Report report, Principal principal); @RequestMapping(value = "/rest-api/requisitions/{id}", method = GET, headers = ACCEPT_JSON) ResponseEntity<RestResponse> getReplenishment(@PathVariable Long id); @RequestMapping(value="/rest-api/requisitions", method = GET, headers = ACCEPT_JSON) ResponseEntity<RestResponse> getRequisitionsByFacility(@RequestParam(value="facilityCode") String facilityCode); }
RestRequisitionController extends BaseController { @RequestMapping(value = "/rest-api/requisitions", method = POST, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> submitRequisition(@RequestBody Report report, Principal principal) { Rnr requisition; try { requisition = restRequisitionService.submitReport(report, loggedInUserId(principal)); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } return response(RNR, requisition.getId(), CREATED); }  @RequestMapping(value = "/rest-api/requisitions", method = POST, headers = ACCEPT_JSON) ResponseEntity<RestResponse> submitRequisition(@RequestBody Report report, Principal principal); @RequestMapping(value = "/rest-api/sdp-requisitions", method = POST, headers = ACCEPT_JSON) ResponseEntity<RestResponse> submitSDPRequisition(@RequestBody Report report, Principal principal); @RequestMapping(value = "/rest-api/requisitions/{requisitionId}/approve", method = PUT, headers = ACCEPT_JSON) ResponseEntity<RestResponse> approve(@PathVariable Long requisitionId, @RequestBody Report report, Principal principal); @RequestMapping(value = "/rest-api/requisitions/{id}", method = GET, headers = ACCEPT_JSON) ResponseEntity<RestResponse> getReplenishment(@PathVariable Long id); @RequestMapping(value="/rest-api/requisitions", method = GET, headers = ACCEPT_JSON) ResponseEntity<RestResponse> getRequisitionsByFacility(@RequestParam(value="facilityCode") String facilityCode); static final String RNR; }