@Test public void shouldApproveIfRnrBelongsToVirtualFacility() throws Exception { Rnr requisitionFromReport = new Rnr(); Report spyReport = spy(report); long requisitionId = 111L; long modifiedBy = 233L; when(spyReport.getRequisition(requisitionId, modifiedBy)).thenReturn(requisitionFromReport); Facility facility = make(a(defaultFacility, with(virtualFacility, true))); Rnr rnr = make(a(RequisitionBuilder.defaultRequisition, with (RequisitionBuilder.facility, facility))); when(requisitionService.getFullRequisitionById(requisitionFromReport.getId())).thenReturn(rnr); service.approve(spyReport, requisitionId, modifiedBy); verify(spyReport).getRequisition(requisitionId, modifiedBy); verify(requisitionService).save(requisitionFromReport); verify(requisitionService).approve(requisitionFromReport, DEFAULT_APPROVER_NAME); }
@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; }