@Test public void shouldThrowErrorIfInvalidRequisitionIdPassed() throws Exception { Long reportRequisitionId = 1L; Long userId = 12345L; Rnr requisitionFromReport = new Rnr(reportRequisitionId); Report spyReport = spy(report); when(spyReport.getRequisition(reportRequisitionId, userId)).thenReturn(requisitionFromReport); doThrow(new DataException("rnr not found")).when(requisitionService).getFullRequisitionById(requisitionFromReport.getId()); expectedException.expect(DataException.class); expectedException.expectMessage("rnr not found"); service.approve(spyReport, reportRequisitionId, 2L); }
@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; }