Search in sources :

Example 6 with Voucher

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));
}
Also used : VoucherLine(org.folio.rest.jaxrs.model.VoucherLine) Invoice(org.folio.rest.jaxrs.model.Invoice) Fund(org.folio.rest.acq.model.finance.Fund) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Headers(io.restassured.http.Headers) VoucherLineCollection(org.folio.rest.acq.model.VoucherLineCollection) JsonObject(io.vertx.core.json.JsonObject) FundCollection(org.folio.rest.acq.model.finance.FundCollection) Matchers.containsString(org.hamcrest.Matchers.containsString) Voucher(org.folio.rest.jaxrs.model.Voucher) Test(org.junit.jupiter.api.Test)

Example 7 with Voucher

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));
}
Also used : Voucher(org.folio.rest.jaxrs.model.Voucher)

Example 8 with 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);
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Invoice(org.folio.rest.jaxrs.model.Invoice) Fund(org.folio.rest.acq.model.finance.Fund) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Headers(io.restassured.http.Headers) JsonObject(io.vertx.core.json.JsonObject) FundCollection(org.folio.rest.acq.model.finance.FundCollection) Matchers.containsString(org.hamcrest.Matchers.containsString) Voucher(org.folio.rest.jaxrs.model.Voucher) Test(org.junit.jupiter.api.Test)

Example 9 with Voucher

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()));
}
Also used : Invoice(org.folio.rest.jaxrs.model.Invoice) Matchers.containsString(org.hamcrest.Matchers.containsString) Voucher(org.folio.rest.jaxrs.model.Voucher) Test(org.junit.jupiter.api.Test)

Example 10 with Voucher

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);
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Invoice(org.folio.rest.jaxrs.model.Invoice) Adjustment(org.folio.rest.jaxrs.model.Adjustment) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Headers(io.restassured.http.Headers) JsonObject(io.vertx.core.json.JsonObject) InvoiceLineCollection(org.folio.rest.jaxrs.model.InvoiceLineCollection) Matchers.containsString(org.hamcrest.Matchers.containsString) Voucher(org.folio.rest.jaxrs.model.Voucher) Test(org.junit.jupiter.api.Test)

Aggregations

Voucher (org.folio.rest.jaxrs.model.Voucher)28 JsonObject (io.vertx.core.json.JsonObject)24 Test (org.junit.jupiter.api.Test)18 Invoice (org.folio.rest.jaxrs.model.Invoice)17 InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)15 Vertx (io.vertx.core.Vertx)13 List (java.util.List)12 Map (java.util.Map)12 Collectors.toList (java.util.stream.Collectors.toList)12 RequestContext (org.folio.rest.core.models.RequestContext)11 Context (io.vertx.core.Context)10 IOException (java.io.IOException)10 HashMap (java.util.HashMap)10 VoucherCollection (org.folio.rest.jaxrs.model.VoucherCollection)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 Headers (io.restassured.http.Headers)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 Fund (org.folio.rest.acq.model.finance.Fund)9 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)9 FundCollection (org.folio.rest.acq.model.finance.FundCollection)7