@Test public void shouldFailProductValidationIfReportedProductDoesNotBelongToRequisition() throws Exception { Report report = new Report(); RnrLineItem rnrLineItem1 = make(a(defaultRnrLineItem, with(productCode, "P11"))); RnrLineItem rnrLineItem2 = make(a(defaultRnrLineItem, with(productCode, "P12"))); report.setProducts(asList(rnrLineItem1, rnrLineItem2)); Rnr savedRequisition = mock(Rnr.class); when(savedRequisition.findCorrespondingLineItem(rnrLineItem1)).thenReturn(rnrLineItem1); when(savedRequisition.findCorrespondingLineItem(rnrLineItem2)).thenReturn(null); expectedException.expect(DataException.class); expectedException.expectMessage("code: invalid.product.codes, params: { [P12] }"); restRequisitionCalculator.validateProducts(report.getProducts(), savedRequisition); verify(savedRequisition).findCorrespondingLineItem(rnrLineItem1); verify(savedRequisition).findCorrespondingLineItem(rnrLineItem2); }
public void validateProducts(List<RnrLineItem> products, Rnr savedRequisition) { if (products == null) { return; } List<String> invalidProductCodes = new ArrayList<>(); for (final RnrLineItem product : products) { RnrLineItem correspondingLineItem = savedRequisition.findCorrespondingLineItem(product); if (correspondingLineItem == null) { invalidProductCodes.add(product.getProductCode()); } } if (!invalidProductCodes.isEmpty()) { throw new DataException("invalid.product.codes", invalidProductCodes.toString()); } }
RestRequisitionCalculator { public void validateProducts(List<RnrLineItem> products, Rnr savedRequisition) { if (products == null) { return; } List<String> invalidProductCodes = new ArrayList<>(); for (final RnrLineItem product : products) { RnrLineItem correspondingLineItem = savedRequisition.findCorrespondingLineItem(product); if (correspondingLineItem == null) { invalidProductCodes.add(product.getProductCode()); } } if (!invalidProductCodes.isEmpty()) { throw new DataException("invalid.product.codes", invalidProductCodes.toString()); } } }
RestRequisitionCalculator { public void validateProducts(List<RnrLineItem> products, Rnr savedRequisition) { if (products == null) { return; } List<String> invalidProductCodes = new ArrayList<>(); for (final RnrLineItem product : products) { RnrLineItem correspondingLineItem = savedRequisition.findCorrespondingLineItem(product); if (correspondingLineItem == null) { invalidProductCodes.add(product.getProductCode()); } } if (!invalidProductCodes.isEmpty()) { throw new DataException("invalid.product.codes", invalidProductCodes.toString()); } }  }
RestRequisitionCalculator { public void validateProducts(List<RnrLineItem> products, Rnr savedRequisition) { if (products == null) { return; } List<String> invalidProductCodes = new ArrayList<>(); for (final RnrLineItem product : products) { RnrLineItem correspondingLineItem = savedRequisition.findCorrespondingLineItem(product); if (correspondingLineItem == null) { invalidProductCodes.add(product.getProductCode()); } } if (!invalidProductCodes.isEmpty()) { throw new DataException("invalid.product.codes", invalidProductCodes.toString()); } }  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 validateProducts(List<RnrLineItem> products, Rnr savedRequisition) { if (products == null) { return; } List<String> invalidProductCodes = new ArrayList<>(); for (final RnrLineItem product : products) { RnrLineItem correspondingLineItem = savedRequisition.findCorrespondingLineItem(product); if (correspondingLineItem == null) { invalidProductCodes.add(product.getProductCode()); } } if (!invalidProductCodes.isEmpty()) { throw new DataException("invalid.product.codes", invalidProductCodes.toString()); } }  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);  }