@Test public void shouldReturnErrorResponseUponDataException() throws Exception { String programCode = "P1"; String facilityTypeCode = "warehouse"; String expectedErrorMsg = "program.code.invalid"; DataException dataException = new DataException(expectedErrorMsg); doThrow(dataException).when(service).getProgramProductsBy(programCode, facilityTypeCode); ResponseEntity<RestResponse> expectedResponse = new ResponseEntity<>(new RestResponse(ERROR, expectedErrorMsg), BAD_REQUEST); when(RestResponse.error(dataException.getOpenLmisMessage(), BAD_REQUEST)).thenReturn(expectedResponse); ResponseEntity<RestResponse> errorResponse = controller.getProgramProductsBy(programCode, facilityTypeCode); verify(service).getProgramProductsBy(programCode, facilityTypeCode); assertThat(errorResponse, is(expectedResponse)); }
@RequestMapping(value = "/rest-api/program-products", method = GET, headers = BaseController.ACCEPT_JSON) public ResponseEntity<RestResponse> getProgramProductsBy(@RequestParam String programCode, @RequestParam(required = false) String facilityTypeCode) { try { final List<ProgramProductDTO> programProductsDTO = new ArrayList<>(); List<ProgramProduct> programProducts = service.getProgramProductsBy(programCode, facilityTypeCode); forAllDo(programProducts, new Closure() { @Override public void execute(Object o) { programProductsDTO.add(new ProgramProductDTO((ProgramProduct) o)); } }); return response(PROGRAM_PRODUCT_LIST, programProductsDTO); } catch (DataException de) { return error(de.getOpenLmisMessage(), BAD_REQUEST); } }
RestProgramProductController extends BaseController { @RequestMapping(value = "/rest-api/program-products", method = GET, headers = BaseController.ACCEPT_JSON) public ResponseEntity<RestResponse> getProgramProductsBy(@RequestParam String programCode, @RequestParam(required = false) String facilityTypeCode) { try { final List<ProgramProductDTO> programProductsDTO = new ArrayList<>(); List<ProgramProduct> programProducts = service.getProgramProductsBy(programCode, facilityTypeCode); forAllDo(programProducts, new Closure() { @Override public void execute(Object o) { programProductsDTO.add(new ProgramProductDTO((ProgramProduct) o)); } }); return response(PROGRAM_PRODUCT_LIST, programProductsDTO); } catch (DataException de) { return error(de.getOpenLmisMessage(), BAD_REQUEST); } } }
RestProgramProductController extends BaseController { @RequestMapping(value = "/rest-api/program-products", method = GET, headers = BaseController.ACCEPT_JSON) public ResponseEntity<RestResponse> getProgramProductsBy(@RequestParam String programCode, @RequestParam(required = false) String facilityTypeCode) { try { final List<ProgramProductDTO> programProductsDTO = new ArrayList<>(); List<ProgramProduct> programProducts = service.getProgramProductsBy(programCode, facilityTypeCode); forAllDo(programProducts, new Closure() { @Override public void execute(Object o) { programProductsDTO.add(new ProgramProductDTO((ProgramProduct) o)); } }); return response(PROGRAM_PRODUCT_LIST, programProductsDTO); } catch (DataException de) { return error(de.getOpenLmisMessage(), BAD_REQUEST); } }  }
RestProgramProductController extends BaseController { @RequestMapping(value = "/rest-api/program-products", method = GET, headers = BaseController.ACCEPT_JSON) public ResponseEntity<RestResponse> getProgramProductsBy(@RequestParam String programCode, @RequestParam(required = false) String facilityTypeCode) { try { final List<ProgramProductDTO> programProductsDTO = new ArrayList<>(); List<ProgramProduct> programProducts = service.getProgramProductsBy(programCode, facilityTypeCode); forAllDo(programProducts, new Closure() { @Override public void execute(Object o) { programProductsDTO.add(new ProgramProductDTO((ProgramProduct) o)); } }); return response(PROGRAM_PRODUCT_LIST, programProductsDTO); } catch (DataException de) { return error(de.getOpenLmisMessage(), BAD_REQUEST); } }  @RequestMapping(value = "/rest-api/program-products", method = GET, headers = BaseController.ACCEPT_JSON) ResponseEntity<RestResponse> getProgramProductsBy(@RequestParam String programCode,
                                                           @RequestParam(required = false) String facilityTypeCode); }
RestProgramProductController extends BaseController { @RequestMapping(value = "/rest-api/program-products", method = GET, headers = BaseController.ACCEPT_JSON) public ResponseEntity<RestResponse> getProgramProductsBy(@RequestParam String programCode, @RequestParam(required = false) String facilityTypeCode) { try { final List<ProgramProductDTO> programProductsDTO = new ArrayList<>(); List<ProgramProduct> programProducts = service.getProgramProductsBy(programCode, facilityTypeCode); forAllDo(programProducts, new Closure() { @Override public void execute(Object o) { programProductsDTO.add(new ProgramProductDTO((ProgramProduct) o)); } }); return response(PROGRAM_PRODUCT_LIST, programProductsDTO); } catch (DataException de) { return error(de.getOpenLmisMessage(), BAD_REQUEST); } }  @RequestMapping(value = "/rest-api/program-products", method = GET, headers = BaseController.ACCEPT_JSON) ResponseEntity<RestResponse> getProgramProductsBy(@RequestParam String programCode,
                                                           @RequestParam(required = false) String facilityTypeCode); static final String PROGRAM_PRODUCT_LIST; }