use of org.folio.rest.jaxrs.model.Voucher in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionToApprovedWithExistingVoucherAndVoucherLines.
@Test
void testTransitionToApprovedWithExistingVoucherAndVoucherLines() {
logger.info("=== Test transition invoice to Approved with existing voucher and voucherLines ===");
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
Invoice reqData = getMockAsJson(REVIEWED_INVOICE_WITH_EXISTING_VOUCHER_SAMPLE_PATH).mapTo(Invoice.class);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(reqData.getId());
invoiceLine.getFundDistributions().forEach(fundDistribution -> fundDistribution.setCode(null));
prepareMockVoucher(reqData.getId());
VoucherLine voucherLine = new VoucherLine().withVoucherId(EXISTING_VOUCHER_ID);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
addMockEntry(VOUCHER_LINES, JsonObject.mapFrom(voucherLine));
reqData.setStatus(Invoice.Status.APPROVED);
String id = reqData.getId();
String jsonBody = JsonObject.mapFrom(reqData).encode();
Headers headers = prepareHeaders(X_OKAPI_TENANT, X_OKAPI_USER_ID);
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, "", 204);
List<JsonObject> vouchersUpdated = serverRqRs.get(VOUCHERS_STORAGE, HttpMethod.PUT);
List<JsonObject> voucherLinesDeletions = serverRqRs.get(VOUCHER_LINES, HttpMethod.DELETE);
List<JsonObject> voucherLinesSearches = serverRqRs.get(VOUCHER_LINES, HttpMethod.GET);
assertThat(vouchersUpdated, notNullValue());
assertThat(vouchersUpdated, hasSize(1));
assertThat(voucherLinesDeletions, notNullValue());
assertThat(voucherLinesSearches, notNullValue());
assertThat(voucherLinesSearches, hasSize(1));
VoucherLineCollection voucherLineCollection = voucherLinesSearches.get(0).mapTo(VoucherLineCollection.class);
assertThat(voucherLinesDeletions, hasSize(voucherLineCollection.getTotalRecords()));
Voucher updatedVoucher = vouchersUpdated.get(0).mapTo(Voucher.class);
Invoice updatedInvoice = serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).mapTo(Invoice.class);
List<JsonObject> fundsSearches = serverRqRs.get(FUNDS, HttpMethod.GET);
List<Fund> funds = fundsSearches.get(0).mapTo(FundCollection.class).getFunds();
verifyTransitionToApproved(updatedVoucher, Collections.singletonList(invoiceLine), updatedInvoice, getExpectedVoucherLinesQuantity(funds));
}
use of org.folio.rest.jaxrs.model.Voucher in project mod-invoice by folio-org.
the class InvoicesApiTest method prepareMockVoucher.
private void prepareMockVoucher(String invoiceId, boolean failOnUpdate) {
Voucher voucher = getMockAsJson(VOUCHERS_LIST_PATH).mapTo(VoucherCollection.class).getVouchers().get(0);
voucher.setInvoiceId(invoiceId);
if (failOnUpdate) {
voucher.setId(ID_FOR_INTERNAL_SERVER_ERROR_PUT);
}
addMockEntry(VOUCHERS_STORAGE, JsonObject.mapFrom(voucher));
}
use of org.folio.rest.jaxrs.model.Voucher in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionFromOpenToApprovedWithMixedTypesFundDistributionsAndWithLockTotalWhichEqualToTotal.
@Test
void testTransitionFromOpenToApprovedWithMixedTypesFundDistributionsAndWithLockTotalWhichEqualToTotal() {
Invoice reqData = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class);
String id = reqData.getId();
InvoiceLine invoiceLine = getMinimalContentInvoiceLine(id);
invoiceLine.setSubTotal(100d);
invoiceLine.setId(UUID.randomUUID().toString());
FundDistribution percentageDistribution = new FundDistribution().withFundId(EXISTING_FUND_ID).withCode(null).withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withValue(50d);
FundDistribution amountDistribution = new FundDistribution().withFundId(EXISTING_FUND_ID).withDistributionType(AMOUNT).withValue(50d);
invoiceLine.getFundDistributions().addAll(Arrays.asList(percentageDistribution, amountDistribution));
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
reqData.setStatus(Invoice.Status.APPROVED);
reqData.setLockTotal(100d);
String jsonBody = JsonObject.mapFrom(reqData).encode();
Headers headers = prepareHeaders(X_OKAPI_URL, X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, "", 204);
// Verify that expected number of external calls made
assertThat(getInvoiceRetrievals(), hasSize(1));
assertThat(getInvoiceLineSearches(), hasSize(1));
Invoice updatedInvoice = serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).mapTo(Invoice.class);
List<JsonObject> vouchersCreated = serverRqRs.get(VOUCHERS_STORAGE, HttpMethod.POST);
assertThat(vouchersCreated, notNullValue());
assertThat(vouchersCreated, hasSize(1));
Voucher voucherCreated = vouchersCreated.get(0).mapTo(Voucher.class);
assertThat(voucherCreated.getVoucherNumber(), equalTo(TEST_PREFIX + VOUCHER_NUMBER_VALUE));
assertThat(voucherCreated.getSystemCurrency(), equalTo(DEFAULT_SYSTEM_CURRENCY));
List<JsonObject> fundsSearches = serverRqRs.get(FUNDS, HttpMethod.GET);
List<Fund> funds = fundsSearches.get(0).mapTo(FundCollection.class).getFunds();
verifyTransitionToApproved(voucherCreated, Collections.singletonList(invoiceLine), updatedInvoice, getExpectedVoucherLinesQuantity(funds));
checkVoucherAcqUnitIdsList(voucherCreated, reqData);
}
use of org.folio.rest.jaxrs.model.Voucher in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateInvoiceTransitionToPaidNoVoucherUpdate.
@Test
void testUpdateInvoiceTransitionToPaidNoVoucherUpdate() {
logger.info("=== Test transition invoice to paid - voucher already paid ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
// Prepare already paid voucher
Voucher voucher = getMockAsJson(VOUCHERS_LIST_PATH).mapTo(VoucherCollection.class).getVouchers().get(0);
voucher.setInvoiceId(id);
voucher.setStatus(Voucher.Status.PAID);
addMockEntry(VOUCHERS_STORAGE, JsonObject.mapFrom(voucher));
String jsonBody = JsonObject.mapFrom(reqData).encode();
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, "", 204);
assertThat(getRqRsEntries(HttpMethod.GET, VOUCHERS_STORAGE), hasSize(1));
assertThat(getRqRsEntries(HttpMethod.PUT, VOUCHERS_STORAGE), empty());
assertThat(getRqRsEntries(HttpMethod.PUT, INVOICES), hasSize(1));
assertThat(getRqRsEntries(HttpMethod.PUT, INVOICES).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
}
use of org.folio.rest.jaxrs.model.Voucher in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionFromOpenToApproved.
@Test
void testTransitionFromOpenToApproved() {
logger.info("=== Test transition invoice to Approved ===");
Adjustment adjustment1 = new Adjustment().withProrate(Prorate.NOT_PRORATED).withDescription("Description").withType(Type.AMOUNT).withValue(50d).withRelationToTotal(Adjustment.RelationToTotal.IN_ADDITION_TO);
FundDistribution fundDistribution1 = new FundDistribution().withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withValue(100d).withFundId(EXISTING_FUND_ID);
Adjustment adjustment2 = new Adjustment().withProrate(Prorate.NOT_PRORATED).withDescription("Description").withType(Type.AMOUNT).withValue(50d).withRelationToTotal(Adjustment.RelationToTotal.IN_ADDITION_TO);
FundDistribution fundDistribution2 = new FundDistribution().withDistributionType(AMOUNT).withValue(50d).withFundId(EXISTING_FUND_ID);
adjustment1.getFundDistributions().add(fundDistribution1);
adjustment2.getFundDistributions().add(fundDistribution2);
List<InvoiceLine> invoiceLines = getMockAsJson(INVOICE_LINES_LIST_PATH).mapTo(InvoiceLineCollection.class).getInvoiceLines();
Invoice reqData = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class);
reqData.getAdjustments().add(adjustment1);
reqData.getAdjustments().add(adjustment2);
String id = reqData.getId();
invoiceLines.forEach(invoiceLine -> {
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(id);
invoiceLine.getFundDistributions().forEach(fundDistribution -> fundDistribution.setCode(null));
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
});
reqData.setStatus(Invoice.Status.APPROVED);
String jsonBody = JsonObject.mapFrom(reqData).encode();
Headers headers = prepareHeaders(X_OKAPI_URL, X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, "", 204);
// Verify that expected number of external calls made
assertThat(getInvoiceRetrievals(), hasSize(1));
assertThat(getInvoiceLineSearches(), hasSize(1));
Invoice updatedInvoice = serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).mapTo(Invoice.class);
List<JsonObject> vouchersCreated = serverRqRs.get(VOUCHERS_STORAGE, HttpMethod.POST);
assertThat(vouchersCreated, notNullValue());
assertThat(vouchersCreated, hasSize(1));
Voucher voucherCreated = vouchersCreated.get(0).mapTo(Voucher.class);
assertThat(voucherCreated.getVoucherNumber(), equalTo(TEST_PREFIX + VOUCHER_NUMBER_VALUE));
assertThat(voucherCreated.getSystemCurrency(), equalTo(DEFAULT_SYSTEM_CURRENCY));
verifyTransitionToApproved(voucherCreated, invoiceLines, updatedInvoice, 5);
verifyVoucherLineWithExpenseClasses(2L);
checkVoucherAcqUnitIdsList(voucherCreated, reqData);
}
Aggregations