@Test public void shouldGetProgramProductsByProgramCodeAndFacilityTypeCode() throws Exception { List<ProgramProductDTO> expectedProgramProductList = new ArrayList<>(); Program program = new Program(1l); program.setCode("P1"); FacilityType facilityType = new FacilityType(); facilityType.setCode("warehouse"); when(service.getProgramProductsBy(program.getCode(), facilityType.getCode())).thenReturn(new ArrayList<ProgramProduct>()); ResponseEntity<RestResponse> expectedResponse = new ResponseEntity<>(new RestResponse(PROGRAM_PRODUCT_LIST, expectedProgramProductList), OK); when(RestResponse.response(PROGRAM_PRODUCT_LIST, expectedProgramProductList)).thenReturn(expectedResponse); ResponseEntity<RestResponse> responseEntity = controller.getProgramProductsBy(program.getCode(), facilityType.getCode()); assertThat((ArrayList<ProgramProductDTO>) responseEntity.getBody().getData().get(PROGRAM_PRODUCT_LIST), is(expectedProgramProductList)); verify(service).getProgramProductsBy(program.getCode(), facilityType.getCode()); }
@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; }