use of org.folio.invoices.utils.ResourcePathResolver.ORDER_LINES in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceTrue.
@Test
void testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceTrue() {
logger.info("=== Test transition invoice to paid and releaseEncumbrance true for all invoice lines ===");
List<InvoiceLine> invoiceLines = new ArrayList<>();
List<CompositePoLine> poLines = new ArrayList<>();
for (int i = 0; i < 3; i++) {
invoiceLines.add(getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class));
poLines.add(getMockAsJson(String.format("%s%s.json", PO_LINE_MOCK_DATA_PATH, EXISTENT_PO_LINE_ID)).mapTo(CompositePoLine.class));
}
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
for (int i = 0; i < 3; i++) {
InvoiceLine invoiceLine = invoiceLines.get(i);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(reqData.getId());
String poLineId = UUID.randomUUID().toString();
invoiceLine.setPoLineId(poLineId);
poLines.get(i).setId(poLineId);
}
invoiceLines.forEach(line -> addMockEntry(INVOICE_LINES, JsonObject.mapFrom(line)));
poLines.forEach(line -> addMockEntry(ORDER_LINES, JsonObject.mapFrom(line)));
prepareMockVoucher(id);
verifyPut(String.format(INVOICE_ID_PATH, id), JsonObject.mapFrom(reqData), "", 204);
assertThat(getRqRsEntries(HttpMethod.PUT, INVOICES).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
assertThat(getRqRsEntries(HttpMethod.GET, INVOICE_LINES), hasSize(1));
assertThat(getRqRsEntries(HttpMethod.GET, INVOICE_LINES).get(0).mapTo(InvoiceLineCollection.class).getTotalRecords(), equalTo(3));
assertThat(getRqRsEntries(HttpMethod.PUT, ORDER_LINES), hasSize(3));
getRqRsEntries(HttpMethod.PUT, ORDER_LINES).stream().map(entries -> entries.mapTo(CompositePoLine.class)).forEach(compositePoLine -> assertThat(compositePoLine.getPaymentStatus(), equalTo(CompositePoLine.PaymentStatus.FULLY_PAID)));
assertThatVoucherPaid();
List<JsonObject> invoiceLinesUpdates = serverRqRs.get(INVOICE_LINES, HttpMethod.PUT);
List<InvoiceLine> lines = invoiceLinesUpdates.stream().map(entry -> entry.mapTo(InvoiceLine.class)).collect(toList());
assertThat(lines, everyItem(hasProperty("invoiceLineStatus", is(InvoiceLine.InvoiceLineStatus.PAID))));
assertThat(getRqRsEntries(HttpMethod.GET, FINANCE_TRANSACTIONS), hasSize(2));
assertThat(getRqRsEntries(HttpMethod.POST, FINANCE_PAYMENTS), hasSize(5));
assertThat(getRqRsEntries(HttpMethod.POST, FINANCE_CREDITS), hasSize(0));
checkCreditsPayments(reqData, invoiceLines);
}
use of org.folio.invoices.utils.ResourcePathResolver.ORDER_LINES in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateInvoiceTransitionToPaidPoLineIdNotSpecified.
@Test
void testUpdateInvoiceTransitionToPaidPoLineIdNotSpecified() {
logger.info("=== Test transition invoice to paid, invoice line doesn't have poLineId ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
prepareMockVoucher(id);
InvoiceLine invoiceLine1 = getMinimalContentInvoiceLine(id).withPoLineId(null);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine1));
InvoiceLine invoiceLine2 = getMinimalContentInvoiceLine(id).withPoLineId(null);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine2));
CompositePoLine poLine = getMockAsJson(String.format("%s%s.json", PO_LINE_MOCK_DATA_PATH, EXISTENT_PO_LINE_ID)).mapTo(CompositePoLine.class).withPaymentStatus(CompositePoLine.PaymentStatus.AWAITING_PAYMENT);
addMockEntry(ORDER_LINES, JsonObject.mapFrom(poLine));
InvoiceLine invoiceLine3 = getMinimalContentInvoiceLine(id).withPoLineId(poLine.getId());
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine3));
String jsonBody = JsonObject.mapFrom(reqData).encode();
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, "", 204);
assertThat(serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
final List<CompositePoLine> updatedPoLines = getRqRsEntries(HttpMethod.PUT, ORDER_LINES).stream().map(line -> line.mapTo(CompositePoLine.class)).collect(Collectors.toList());
assertThat(updatedPoLines, hasSize(1));
assertThatVoucherPaid();
}
use of org.folio.invoices.utils.ResourcePathResolver.ORDER_LINES in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceFalse.
@Test
void testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceFalse() {
logger.info("=== Test transition invoice to paid and releaseEncumbrance false for all invoice lines ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
List<InvoiceLine> invoiceLines = new ArrayList<>();
// Prepare invoice lines
for (int i = 0; i < 3; i++) {
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(id);
invoiceLine.setPoLineId(EXISTENT_PO_LINE_ID);
invoiceLine.setReleaseEncumbrance(false);
invoiceLines.add(invoiceLine);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
}
prepareMockVoucher(id);
verifyPut(String.format(INVOICE_ID_PATH, id), JsonObject.mapFrom(reqData), "", 204);
assertThat(serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
assertThat(serverRqRs.get(INVOICE_LINES, HttpMethod.GET), notNullValue());
assertThat(serverRqRs.get(INVOICE_LINES, HttpMethod.GET).get(0).mapTo(InvoiceLineCollection.class).getTotalRecords(), equalTo(3));
assertThat(serverRqRs.get(ORDER_LINES, HttpMethod.PUT), notNullValue());
assertThat(serverRqRs.get(ORDER_LINES, HttpMethod.PUT), hasSize(1));
assertThat(serverRqRs.get(ORDER_LINES, HttpMethod.PUT).get(0).mapTo(CompositePoLine.class).getPaymentStatus(), equalTo(CompositePoLine.PaymentStatus.PARTIALLY_PAID));
List<JsonObject> invoiceLinesUpdates = serverRqRs.get(INVOICE_LINES, HttpMethod.PUT);
List<InvoiceLine> lines = invoiceLinesUpdates.stream().map(entry -> entry.mapTo(InvoiceLine.class)).collect(toList());
assertThat(lines, everyItem(hasProperty("invoiceLineStatus", is(InvoiceLine.InvoiceLineStatus.PAID))));
checkCreditsPayments(reqData, invoiceLines);
}
use of org.folio.invoices.utils.ResourcePathResolver.ORDER_LINES in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceFalseNoPoLineUpdate.
@Test
void testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceFalseNoPoLineUpdate() {
logger.info("=== Test transition invoice to paid and releaseEncumbrance false for invoice line without poLine update ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(id);
invoiceLine.setPoLineId(EXISTENT_PO_LINE_ID);
invoiceLine.setReleaseEncumbrance(false);
// to test credit creation
invoiceLine.setSubTotal(-invoiceLine.getSubTotal());
invoiceLine.setTotal(-invoiceLine.getTotal());
CompositePoLine poLine = getMockAsJson(String.format("%s%s.json", PO_LINE_MOCK_DATA_PATH, EXISTENT_PO_LINE_ID)).mapTo(CompositePoLine.class);
poLine.setId(EXISTENT_PO_LINE_ID);
poLine.setPaymentStatus(CompositePoLine.PaymentStatus.PARTIALLY_PAID);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
addMockEntry(ORDER_LINES, JsonObject.mapFrom(poLine));
prepareMockVoucher(id);
verifyPut(String.format(INVOICE_ID_PATH, id), JsonObject.mapFrom(reqData), "", 204);
assertThat(getRqRsEntries(HttpMethod.PUT, INVOICES).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
assertThat(getRqRsEntries(HttpMethod.GET, INVOICE_LINES), hasSize(1));
assertThat(getRqRsEntries(HttpMethod.GET, INVOICE_LINES).get(0).mapTo(InvoiceLineCollection.class).getTotalRecords(), equalTo(1));
assertThat(getRqRsEntries(HttpMethod.PUT, ORDER_LINES), empty());
assertThatVoucherPaid();
List<JsonObject> invoiceLinesUpdates = serverRqRs.get(INVOICE_LINES, HttpMethod.PUT);
List<InvoiceLine> lines = invoiceLinesUpdates.stream().map(entry -> entry.mapTo(InvoiceLine.class)).collect(toList());
assertThat(lines, everyItem(hasProperty("invoiceLineStatus", is(InvoiceLine.InvoiceLineStatus.PAID))));
checkCreditsPayments(reqData, Collections.singletonList(invoiceLine));
}
use of org.folio.invoices.utils.ResourcePathResolver.ORDER_LINES in project mod-invoice by folio-org.
the class InvoicesApiTest method validatePoLinesPaymentStatus.
private void validatePoLinesPaymentStatus() {
final List<CompositePoLine> updatedPoLines = getRqRsEntries(HttpMethod.PUT, ORDER_LINES).stream().map(poLine -> poLine.mapTo(CompositePoLine.class)).collect(Collectors.toList());
assertThat(updatedPoLines, not(empty()));
Map<String, List<InvoiceLine>> invoiceLines = getRqRsEntries(HttpMethod.GET, INVOICE_LINES).get(0).mapTo(InvoiceLineCollection.class).getInvoiceLines().stream().collect(groupingBy(InvoiceLine::getPoLineId));
assertThat(invoiceLines.size(), equalTo(updatedPoLines.size()));
for (Map.Entry<String, List<InvoiceLine>> poLineIdWithInvoiceLines : invoiceLines.entrySet()) {
CompositePoLine poLine = updatedPoLines.stream().filter(compositePoLine -> compositePoLine.getId().equals(poLineIdWithInvoiceLines.getKey())).findFirst().orElseThrow(NullPointerException::new);
CompositePoLine.PaymentStatus expectedStatus = poLineIdWithInvoiceLines.getValue().stream().anyMatch(InvoiceLine::getReleaseEncumbrance) ? CompositePoLine.PaymentStatus.FULLY_PAID : CompositePoLine.PaymentStatus.PARTIALLY_PAID;
assertThat(expectedStatus, is(poLine.getPaymentStatus()));
}
}
Aggregations