@Test public void shouldReturnNullIfProductDoesNotExists() { when(service.getById(2L)).thenReturn(null); ProductDTO productDTO = controller.getById(2L); assertThat(productDTO, is(nullValue())); }
@RequestMapping(value = "/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") public ProductDTO getById(@PathVariable(value = "id") Long id) { Product product = service.getById(id); if(product == null) return null; List<ProgramProduct> programProducts = programProductService.getByProductCode(product.getCode()); List<ProductPriceSchedule> productPriceSchedules = priceScheduleService.getByProductId(product.getId()); return new ProductDTO(product, product.getModifiedDate(), programProducts, productPriceSchedules); }
ProductController extends BaseController { @RequestMapping(value = "/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") public ProductDTO getById(@PathVariable(value = "id") Long id) { Product product = service.getById(id); if(product == null) return null; List<ProgramProduct> programProducts = programProductService.getByProductCode(product.getCode()); List<ProductPriceSchedule> productPriceSchedules = priceScheduleService.getByProductId(product.getId()); return new ProductDTO(product, product.getModifiedDate(), programProducts, productPriceSchedules); } }
ProductController extends BaseController { @RequestMapping(value = "/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") public ProductDTO getById(@PathVariable(value = "id") Long id) { Product product = service.getById(id); if(product == null) return null; List<ProgramProduct> programProducts = programProductService.getByProductCode(product.getCode()); List<ProductPriceSchedule> productPriceSchedules = priceScheduleService.getByProductId(product.getId()); return new ProductDTO(product, product.getModifiedDate(), programProducts, productPriceSchedules); }  }
ProductController extends BaseController { @RequestMapping(value = "/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") public ProductDTO getById(@PathVariable(value = "id") Long id) { Product product = service.getById(id); if(product == null) return null; List<ProgramProduct> programProducts = programProductService.getByProductCode(product.getCode()); List<ProductPriceSchedule> productPriceSchedules = priceScheduleService.getByProductId(product.getId()); return new ProductDTO(product, product.getModifiedDate(), programProducts, productPriceSchedules); }  @RequestMapping(value = "/groups", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductGroup> getAllGroups(); @RequestMapping(value = "/forms", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductForm> getAllForms(); @RequestMapping(value = "/dosageUnits", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<DosageUnit> getAllDosageUnits(); @RequestMapping(value = "/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ProductDTO getById(@PathVariable(value = "id") Long id); @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ResponseEntity<OpenLmisResponse> save(@RequestBody ProductDTO productDTO, HttpServletRequest request); @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ResponseEntity<OpenLmisResponse> update(@RequestBody ProductDTO productDTO, @PathVariable(value = "id") Long id,
                                                 HttpServletRequest request); @RequestMapping(value = "/categories", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductCategory> getAllCategories(); }
ProductController extends BaseController { @RequestMapping(value = "/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") public ProductDTO getById(@PathVariable(value = "id") Long id) { Product product = service.getById(id); if(product == null) return null; List<ProgramProduct> programProducts = programProductService.getByProductCode(product.getCode()); List<ProductPriceSchedule> productPriceSchedules = priceScheduleService.getByProductId(product.getId()); return new ProductDTO(product, product.getModifiedDate(), programProducts, productPriceSchedules); }  @RequestMapping(value = "/groups", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductGroup> getAllGroups(); @RequestMapping(value = "/forms", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductForm> getAllForms(); @RequestMapping(value = "/dosageUnits", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<DosageUnit> getAllDosageUnits(); @RequestMapping(value = "/{id}", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ProductDTO getById(@PathVariable(value = "id") Long id); @RequestMapping(method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ResponseEntity<OpenLmisResponse> save(@RequestBody ProductDTO productDTO, HttpServletRequest request); @RequestMapping(value = "/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") ResponseEntity<OpenLmisResponse> update(@RequestBody ProductDTO productDTO, @PathVariable(value = "id") Long id,
                                                 HttpServletRequest request); @RequestMapping(value = "/categories", method = RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_PRODUCT')") List<ProductCategory> getAllCategories();  }