@Test public void shouldGiveErrorIfFacilityCodeInvalid() throws Exception { mockStatic(RestResponse.class); String facilityCode = "F11"; OpenLmisMessage openLmisMessage = new OpenLmisMessage("error code"); ResponseEntity<RestResponse> errorResponse = new ResponseEntity<>(BAD_REQUEST); when(RestResponse.error(openLmisMessage, BAD_REQUEST)).thenReturn(errorResponse); doThrow(new DataException(openLmisMessage)).when(restFacilityService).getFacilityByCode(facilityCode); ResponseEntity<RestResponse> response = restFacilityController.getFacilityByCode(facilityCode); assertThat(response, is(errorResponse)); }
@RequestMapping(value = "/rest-api/facilities/{facilityCode}", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getFacilityByCode(@PathVariable String facilityCode) { FacilityFeedDTO facilityFeedDTO; try { facilityFeedDTO = restFacilityService.getFacilityByCode(facilityCode); } catch (DataException e) { return RestResponse.error(e.getOpenLmisMessage(), BAD_REQUEST); } return RestResponse.response(FACILITY, facilityFeedDTO); }
RestFacilityController extends BaseController { @RequestMapping(value = "/rest-api/facilities/{facilityCode}", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getFacilityByCode(@PathVariable String facilityCode) { FacilityFeedDTO facilityFeedDTO; try { facilityFeedDTO = restFacilityService.getFacilityByCode(facilityCode); } catch (DataException e) { return RestResponse.error(e.getOpenLmisMessage(), BAD_REQUEST); } return RestResponse.response(FACILITY, facilityFeedDTO); } }
RestFacilityController extends BaseController { @RequestMapping(value = "/rest-api/facilities/{facilityCode}", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getFacilityByCode(@PathVariable String facilityCode) { FacilityFeedDTO facilityFeedDTO; try { facilityFeedDTO = restFacilityService.getFacilityByCode(facilityCode); } catch (DataException e) { return RestResponse.error(e.getOpenLmisMessage(), BAD_REQUEST); } return RestResponse.response(FACILITY, facilityFeedDTO); }  }
RestFacilityController extends BaseController { @RequestMapping(value = "/rest-api/facilities/{facilityCode}", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getFacilityByCode(@PathVariable String facilityCode) { FacilityFeedDTO facilityFeedDTO; try { facilityFeedDTO = restFacilityService.getFacilityByCode(facilityCode); } catch (DataException e) { return RestResponse.error(e.getOpenLmisMessage(), BAD_REQUEST); } return RestResponse.response(FACILITY, facilityFeedDTO); }  @RequestMapping(value = "/rest-api/facilities/{facilityCode}", method = GET, headers = ACCEPT_JSON) ResponseEntity<RestResponse> getFacilityByCode(@PathVariable String facilityCode); }
RestFacilityController extends BaseController { @RequestMapping(value = "/rest-api/facilities/{facilityCode}", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getFacilityByCode(@PathVariable String facilityCode) { FacilityFeedDTO facilityFeedDTO; try { facilityFeedDTO = restFacilityService.getFacilityByCode(facilityCode); } catch (DataException e) { return RestResponse.error(e.getOpenLmisMessage(), BAD_REQUEST); } return RestResponse.response(FACILITY, facilityFeedDTO); }  @RequestMapping(value = "/rest-api/facilities/{facilityCode}", method = GET, headers = ACCEPT_JSON) ResponseEntity<RestResponse> getFacilityByCode(@PathVariable String facilityCode); static final String FACILITY; }