@Test public void shouldThrowAnExceptionIfLineItemsCountMismatchBetweenReportAndSavedRequisition() throws Exception { long requisitionId = 123L; List<RnrLineItem> productList = asList(make(a(defaultRnrLineItem, with(productCode, "P10")))); Report report = make(a(defaultReport, with(products, productList))); Facility facility = make(a(FacilityBuilder.defaultFacility, with(FacilityBuilder.virtualFacility, true))); Rnr rnr = make(a(RequisitionBuilder.defaultRequisition, with(RequisitionBuilder.facility, facility))); rnr.setFullSupplyLineItems(asList(make(a(defaultRnrLineItem, with(productCode, "P10"))), make(a(defaultRnrLineItem, with(productCode, "P11"))))); when(requisitionService.getFullRequisitionById(requisitionId)).thenReturn(rnr); expectedException.expect(DataException.class); expectedException.expectMessage("error.number.of.line.items.mismatch"); service.approve(report, requisitionId, 3L); }
@Transactional public void approve(Report report, Long requisitionId, Long userId) { Rnr requisition = report.getRequisition(requisitionId, userId); Rnr savedRequisition = requisitionService.getFullRequisitionById(requisition.getId()); if (!savedRequisition.getFacility().getVirtualFacility()) { throw new DataException("error.approval.not.allowed"); } if (savedRequisition.getNonSkippedLineItems().size() != report.getProducts().size()) { throw new DataException("error.number.of.line.items.mismatch"); } restRequisitionCalculator.validateProducts(report.getProducts(), savedRequisition); requisitionService.save(requisition); requisitionService.approve(requisition, report.getApproverName()); }
RestRequisitionService { @Transactional public void approve(Report report, Long requisitionId, Long userId) { Rnr requisition = report.getRequisition(requisitionId, userId); Rnr savedRequisition = requisitionService.getFullRequisitionById(requisition.getId()); if (!savedRequisition.getFacility().getVirtualFacility()) { throw new DataException("error.approval.not.allowed"); } if (savedRequisition.getNonSkippedLineItems().size() != report.getProducts().size()) { throw new DataException("error.number.of.line.items.mismatch"); } restRequisitionCalculator.validateProducts(report.getProducts(), savedRequisition); requisitionService.save(requisition); requisitionService.approve(requisition, report.getApproverName()); } }
RestRequisitionService { @Transactional public void approve(Report report, Long requisitionId, Long userId) { Rnr requisition = report.getRequisition(requisitionId, userId); Rnr savedRequisition = requisitionService.getFullRequisitionById(requisition.getId()); if (!savedRequisition.getFacility().getVirtualFacility()) { throw new DataException("error.approval.not.allowed"); } if (savedRequisition.getNonSkippedLineItems().size() != report.getProducts().size()) { throw new DataException("error.number.of.line.items.mismatch"); } restRequisitionCalculator.validateProducts(report.getProducts(), savedRequisition); requisitionService.save(requisition); requisitionService.approve(requisition, report.getApproverName()); }  }
RestRequisitionService { @Transactional public void approve(Report report, Long requisitionId, Long userId) { Rnr requisition = report.getRequisition(requisitionId, userId); Rnr savedRequisition = requisitionService.getFullRequisitionById(requisition.getId()); if (!savedRequisition.getFacility().getVirtualFacility()) { throw new DataException("error.approval.not.allowed"); } if (savedRequisition.getNonSkippedLineItems().size() != report.getProducts().size()) { throw new DataException("error.number.of.line.items.mismatch"); } restRequisitionCalculator.validateProducts(report.getProducts(), savedRequisition); requisitionService.save(requisition); requisitionService.approve(requisition, report.getApproverName()); }  @Transactional Rnr submitReport(Report report, Long userId); @Transactional Rnr submitSdpReport(Report report, Long userId); @Transactional void approve(Report report, Long requisitionId, Long userId); ReplenishmentDTO getReplenishmentDetails(Long id); List<Report> getRequisitionsByFacility(String facilityCode); }
RestRequisitionService { @Transactional public void approve(Report report, Long requisitionId, Long userId) { Rnr requisition = report.getRequisition(requisitionId, userId); Rnr savedRequisition = requisitionService.getFullRequisitionById(requisition.getId()); if (!savedRequisition.getFacility().getVirtualFacility()) { throw new DataException("error.approval.not.allowed"); } if (savedRequisition.getNonSkippedLineItems().size() != report.getProducts().size()) { throw new DataException("error.number.of.line.items.mismatch"); } restRequisitionCalculator.validateProducts(report.getProducts(), savedRequisition); requisitionService.save(requisition); requisitionService.approve(requisition, report.getApproverName()); }  @Transactional Rnr submitReport(Report report, Long userId); @Transactional Rnr submitSdpReport(Report report, Long userId); @Transactional void approve(Report report, Long requisitionId, Long userId); ReplenishmentDTO getReplenishmentDetails(Long id); List<Report> getRequisitionsByFacility(String facilityCode); static final boolean EMERGENCY; }