@Test public void shouldThrowErrorWhenInsertingProductForInvalidProgram() { Product product = make(a(defaultProduct)); Program program = make(a(defaultProgram)); ProgramProduct programProduct = new ProgramProduct(program, product, 10, true); when(programRepository.getIdByCode(programProduct.getProgram().getCode())).thenThrow(new DataException("exception")); expectedEx.expect(DataException.class); expectedEx.expectMessage("exception"); programProductRepository.save(programProduct); }
public void save(ProgramProduct programProduct) { Long programId = programRepository.getIdByCode(programProduct.getProgram().getCode()); programProduct.getProgram().setId(programId); validateProductCode(programProduct.getProduct().getCode()); Long productId = productRepository.getIdByCode(programProduct.getProduct().getCode()); programProduct.getProduct().setId(productId); try { if (programProduct.getId() == null) { mapper.insert(programProduct); } else { mapper.update(programProduct); } } catch (DuplicateKeyException duplicateKeyException) { throw new DataException("error.duplicate.product.code.program.code"); } }
ProgramProductRepository { public void save(ProgramProduct programProduct) { Long programId = programRepository.getIdByCode(programProduct.getProgram().getCode()); programProduct.getProgram().setId(programId); validateProductCode(programProduct.getProduct().getCode()); Long productId = productRepository.getIdByCode(programProduct.getProduct().getCode()); programProduct.getProduct().setId(productId); try { if (programProduct.getId() == null) { mapper.insert(programProduct); } else { mapper.update(programProduct); } } catch (DuplicateKeyException duplicateKeyException) { throw new DataException("error.duplicate.product.code.program.code"); } } }
ProgramProductRepository { public void save(ProgramProduct programProduct) { Long programId = programRepository.getIdByCode(programProduct.getProgram().getCode()); programProduct.getProgram().setId(programId); validateProductCode(programProduct.getProduct().getCode()); Long productId = productRepository.getIdByCode(programProduct.getProduct().getCode()); programProduct.getProduct().setId(productId); try { if (programProduct.getId() == null) { mapper.insert(programProduct); } else { mapper.update(programProduct); } } catch (DuplicateKeyException duplicateKeyException) { throw new DataException("error.duplicate.product.code.program.code"); } }  }
ProgramProductRepository { public void save(ProgramProduct programProduct) { Long programId = programRepository.getIdByCode(programProduct.getProgram().getCode()); programProduct.getProgram().setId(programId); validateProductCode(programProduct.getProduct().getCode()); Long productId = productRepository.getIdByCode(programProduct.getProduct().getCode()); programProduct.getProduct().setId(productId); try { if (programProduct.getId() == null) { mapper.insert(programProduct); } else { mapper.update(programProduct); } } catch (DuplicateKeyException duplicateKeyException) { throw new DataException("error.duplicate.product.code.program.code"); } }  void save(ProgramProduct programProduct); Long getIdByProgramIdAndProductId(Long programId, Long productId); void updateCurrentPrice(ProgramProduct programProduct); ProgramProduct getByProgramAndProductCode(ProgramProduct programProduct); ProgramProduct getByProgramAndProductId(Long programId, Long productId); void updatePriceHistory(ProgramProductPrice programProductPrice); void updateProgramProduct(ProgramProduct programProduct); ProgramProductPrice getProgramProductPrice(ProgramProduct programProduct); List<ProgramProduct> getByProgram(Program program); ProgramProduct getById(Long id); List<ProgramProduct> getByProductCode(String code); List<ProgramProduct> getProgramProductsBy(Long programId, String facilityTypeCode); List<ProgramProduct> getNonFullSupplyProductsForProgram(Program program); List<ProgramProduct> searchByProgram(String searchParam, Pagination pagination); Integer getTotalSearchResultCount(String searchParam); List<ProgramProduct> searchByProduct(String searchParam, Pagination pagination); List<ProgramProduct> getActiveByProgram(Long programId); @Transactional void insertISA(ProgramProductISA programProductISA); void updateISA(ProgramProductISA programProductISA); }
ProgramProductRepository { public void save(ProgramProduct programProduct) { Long programId = programRepository.getIdByCode(programProduct.getProgram().getCode()); programProduct.getProgram().setId(programId); validateProductCode(programProduct.getProduct().getCode()); Long productId = productRepository.getIdByCode(programProduct.getProduct().getCode()); programProduct.getProduct().setId(productId); try { if (programProduct.getId() == null) { mapper.insert(programProduct); } else { mapper.update(programProduct); } } catch (DuplicateKeyException duplicateKeyException) { throw new DataException("error.duplicate.product.code.program.code"); } }  void save(ProgramProduct programProduct); Long getIdByProgramIdAndProductId(Long programId, Long productId); void updateCurrentPrice(ProgramProduct programProduct); ProgramProduct getByProgramAndProductCode(ProgramProduct programProduct); ProgramProduct getByProgramAndProductId(Long programId, Long productId); void updatePriceHistory(ProgramProductPrice programProductPrice); void updateProgramProduct(ProgramProduct programProduct); ProgramProductPrice getProgramProductPrice(ProgramProduct programProduct); List<ProgramProduct> getByProgram(Program program); ProgramProduct getById(Long id); List<ProgramProduct> getByProductCode(String code); List<ProgramProduct> getProgramProductsBy(Long programId, String facilityTypeCode); List<ProgramProduct> getNonFullSupplyProductsForProgram(Program program); List<ProgramProduct> searchByProgram(String searchParam, Pagination pagination); Integer getTotalSearchResultCount(String searchParam); List<ProgramProduct> searchByProduct(String searchParam, Pagination pagination); List<ProgramProduct> getActiveByProgram(Long programId); @Transactional void insertISA(ProgramProductISA programProductISA); void updateISA(ProgramProductISA programProductISA);  }