@Test public void shouldReturnBadRequestIfError() { mockStatic(RestResponse.class); DataException e = new DataException("error.facility.code.invalid"); when(restProgramsService.getAllProgramsWithProductsByFacilityCode("F10")).thenThrow(e); ResponseEntity<RestResponse> expectedResponse = new ResponseEntity<>(new RestResponse(ERROR, "error.facility.code.invalid"), BAD_REQUEST); when(RestResponse.error(e.getOpenLmisMessage(), BAD_REQUEST)).thenReturn(expectedResponse); ResponseEntity<RestResponse> response = restProgramsController.getProgramWithProductsByFacility("F10"); assertEquals(expectedResponse, response); }
@RequestMapping(value = "/rest-api/programs-with-products", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getProgramWithProductsByFacility(@RequestParam String facilityCode) { try { List<ProgramWithProducts> programsWithProducts = programService.getAllProgramsWithProductsByFacilityCode(facilityCode); return response("programsWithProducts", programsWithProducts); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }
RestProgramsController extends BaseController { @RequestMapping(value = "/rest-api/programs-with-products", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getProgramWithProductsByFacility(@RequestParam String facilityCode) { try { List<ProgramWithProducts> programsWithProducts = programService.getAllProgramsWithProductsByFacilityCode(facilityCode); return response("programsWithProducts", programsWithProducts); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } } }
RestProgramsController extends BaseController { @RequestMapping(value = "/rest-api/programs-with-products", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getProgramWithProductsByFacility(@RequestParam String facilityCode) { try { List<ProgramWithProducts> programsWithProducts = programService.getAllProgramsWithProductsByFacilityCode(facilityCode); return response("programsWithProducts", programsWithProducts); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }  }
RestProgramsController extends BaseController { @RequestMapping(value = "/rest-api/programs-with-products", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getProgramWithProductsByFacility(@RequestParam String facilityCode) { try { List<ProgramWithProducts> programsWithProducts = programService.getAllProgramsWithProductsByFacilityCode(facilityCode); return response("programsWithProducts", programsWithProducts); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }  @RequestMapping(value = "/rest-api/programs-with-products", method = GET, headers = ACCEPT_JSON) ResponseEntity<RestResponse> getProgramWithProductsByFacility(@RequestParam String facilityCode); }
RestProgramsController extends BaseController { @RequestMapping(value = "/rest-api/programs-with-products", method = GET, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> getProgramWithProductsByFacility(@RequestParam String facilityCode) { try { List<ProgramWithProducts> programsWithProducts = programService.getAllProgramsWithProductsByFacilityCode(facilityCode); return response("programsWithProducts", programsWithProducts); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }  @RequestMapping(value = "/rest-api/programs-with-products", method = GET, headers = ACCEPT_JSON) ResponseEntity<RestResponse> getProgramWithProductsByFacility(@RequestParam String facilityCode);  }