@Test public void shouldReturnSuccessCodeAndRequisitionListIfNoException() { String facilityCode = "F1"; List<Report> expectedRequisitions = new ArrayList<>(); when(service.getRequisitionsByFacility(facilityCode)).thenReturn(expectedRequisitions); String requisitionsKey = "requisitions"; ResponseEntity<RestResponse> expectedResponse = new ResponseEntity<>(new RestResponse(requisitionsKey, expectedRequisitions), OK); when(RestResponse.response(requisitionsKey, expectedRequisitions, HttpStatus.OK)).thenReturn(expectedResponse); ResponseEntity<RestResponse> response = controller.getRequisitionsByFacility(facilityCode); assertThat(response.getStatusCode(), is(HttpStatus.OK)); assertThat((List<Report>) response.getBody().getData().get(requisitionsKey), is(expectedRequisitions)); }
@RequestMapping(value="/rest-api/requisitions", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getRequisitionsByFacility(@RequestParam(value="facilityCode") String facilityCode) { try { return response("requisitions", restRequisitionService.getRequisitionsByFacility(facilityCode), OK); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }
RestRequisitionController extends BaseController { @RequestMapping(value="/rest-api/requisitions", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getRequisitionsByFacility(@RequestParam(value="facilityCode") String facilityCode) { try { return response("requisitions", restRequisitionService.getRequisitionsByFacility(facilityCode), OK); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } } }
RestRequisitionController extends BaseController { @RequestMapping(value="/rest-api/requisitions", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getRequisitionsByFacility(@RequestParam(value="facilityCode") String facilityCode) { try { return response("requisitions", restRequisitionService.getRequisitionsByFacility(facilityCode), OK); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }  }
RestRequisitionController extends BaseController { @RequestMapping(value="/rest-api/requisitions", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getRequisitionsByFacility(@RequestParam(value="facilityCode") String facilityCode) { try { return response("requisitions", restRequisitionService.getRequisitionsByFacility(facilityCode), OK); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }  @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 = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getRequisitionsByFacility(@RequestParam(value="facilityCode") String facilityCode) { try { return response("requisitions", restRequisitionService.getRequisitionsByFacility(facilityCode), OK); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }  @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; }