@Test public void sdpShouldThrowErrorIfPeriodHasExistingAuthorizedRnr() throws Exception{ ProcessingPeriod currentPeriod = new ProcessingPeriod(1L); ProcessingPeriod nextEligiblePeriod = new ProcessingPeriod(2L); Facility reportingFacility = new Facility(); Program reportingProgram = new Program(); Rnr requisition = new Rnr(); requisition.setStatus(RnrStatus.APPROVED); List<ProcessingPeriod> periods = new ArrayList<ProcessingPeriod>(); periods.add(nextEligiblePeriod); when(requisitionService.getCurrentPeriod(any(RequisitionSearchCriteria.class))).thenReturn(currentPeriod); when(requisitionService.getPeriodForInitiating(reportingFacility, reportingProgram)).thenReturn(nextEligiblePeriod); when(requisitionService.getRequisitionsFor(any(RequisitionSearchCriteria.class), any(periods.getClass()))).thenReturn(asList(requisition)); expectedException.expect(DataException.class); restRequisitionCalculator.validateCustomPeriod(reportingFacility, reportingProgram, nextEligiblePeriod, 1L); }
public void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId) { if (period == null) { throw new DataException("error.rnr.period.provided.is.invalid"); } RequisitionSearchCriteria searchCriteria = new RequisitionSearchCriteria(); searchCriteria.setProgramId(reportingProgram.getId()); searchCriteria.setFacilityId(reportingFacility.getId()); List<ProcessingPeriod> periods = new ArrayList<ProcessingPeriod>(); periods.add(period); searchCriteria.setWithoutLineItems(true); searchCriteria.setUserId(userId); List<Rnr> list = requisitionService.getRequisitionsFor(searchCriteria, periods); if (list != null && !list.isEmpty() && !list.get(0).preAuthorize()) { throw new DataException("error.rnr.already.submitted.for.this.period"); } }
RestRequisitionCalculator { public void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId) { if (period == null) { throw new DataException("error.rnr.period.provided.is.invalid"); } RequisitionSearchCriteria searchCriteria = new RequisitionSearchCriteria(); searchCriteria.setProgramId(reportingProgram.getId()); searchCriteria.setFacilityId(reportingFacility.getId()); List<ProcessingPeriod> periods = new ArrayList<ProcessingPeriod>(); periods.add(period); searchCriteria.setWithoutLineItems(true); searchCriteria.setUserId(userId); List<Rnr> list = requisitionService.getRequisitionsFor(searchCriteria, periods); if (list != null && !list.isEmpty() && !list.get(0).preAuthorize()) { throw new DataException("error.rnr.already.submitted.for.this.period"); } } }
RestRequisitionCalculator { public void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId) { if (period == null) { throw new DataException("error.rnr.period.provided.is.invalid"); } RequisitionSearchCriteria searchCriteria = new RequisitionSearchCriteria(); searchCriteria.setProgramId(reportingProgram.getId()); searchCriteria.setFacilityId(reportingFacility.getId()); List<ProcessingPeriod> periods = new ArrayList<ProcessingPeriod>(); periods.add(period); searchCriteria.setWithoutLineItems(true); searchCriteria.setUserId(userId); List<Rnr> list = requisitionService.getRequisitionsFor(searchCriteria, periods); if (list != null && !list.isEmpty() && !list.get(0).preAuthorize()) { throw new DataException("error.rnr.already.submitted.for.this.period"); } }  }
RestRequisitionCalculator { public void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId) { if (period == null) { throw new DataException("error.rnr.period.provided.is.invalid"); } RequisitionSearchCriteria searchCriteria = new RequisitionSearchCriteria(); searchCriteria.setProgramId(reportingProgram.getId()); searchCriteria.setFacilityId(reportingFacility.getId()); List<ProcessingPeriod> periods = new ArrayList<ProcessingPeriod>(); periods.add(period); searchCriteria.setWithoutLineItems(true); searchCriteria.setUserId(userId); List<Rnr> list = requisitionService.getRequisitionsFor(searchCriteria, periods); if (list != null && !list.isEmpty() && !list.get(0).preAuthorize()) { throw new DataException("error.rnr.already.submitted.for.this.period"); } }  void validatePeriod(Facility reportingFacility, Program reportingProgram); void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId); void validateProducts(List<RnrLineItem> products, Rnr savedRequisition); Rnr setDefaultValues(Rnr requisition); }
RestRequisitionCalculator { public void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId) { if (period == null) { throw new DataException("error.rnr.period.provided.is.invalid"); } RequisitionSearchCriteria searchCriteria = new RequisitionSearchCriteria(); searchCriteria.setProgramId(reportingProgram.getId()); searchCriteria.setFacilityId(reportingFacility.getId()); List<ProcessingPeriod> periods = new ArrayList<ProcessingPeriod>(); periods.add(period); searchCriteria.setWithoutLineItems(true); searchCriteria.setUserId(userId); List<Rnr> list = requisitionService.getRequisitionsFor(searchCriteria, periods); if (list != null && !list.isEmpty() && !list.get(0).preAuthorize()) { throw new DataException("error.rnr.already.submitted.for.this.period"); } }  void validatePeriod(Facility reportingFacility, Program reportingProgram); void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId); void validateProducts(List<RnrLineItem> products, Rnr savedRequisition); Rnr setDefaultValues(Rnr requisition);  }