Search in sources :

Example 96 with InvoiceLine

use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.

the class InvoicesApiTest method testTransitionFromOpenToApprovedWithRestrictExpenditures.

@Test
void testTransitionFromOpenToApprovedWithRestrictExpenditures() {
    Invoice reqData = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class);
    String id = reqData.getId();
    InvoiceLine invoiceLine = getMinimalContentInvoiceLine(id);
    invoiceLine.setSubTotal(50d);
    invoiceLine.setId(UUID.randomUUID().toString());
    String fundId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    Budget budget = new Budget().withId(UUID.randomUUID().toString()).withFundId(fundId).withFiscalYearId(FISCAL_YEAR_ID).withAllocated(50d).withAvailable(50d).withBudgetStatus(BudgetStatus.ACTIVE).withUnavailable(0d);
    Fund fund = new Fund().withId(fundId).withExternalAccountNo("test").withLedgerId(ledgerId).withCode("FC").withFundStatus(Fund.FundStatus.ACTIVE);
    Ledger ledger = new Ledger().withId(ledgerId).withRestrictExpenditures(false);
    FundDistribution amountDistribution = new FundDistribution().withFundId(fundId).withDistributionType(AMOUNT).withValue(50d);
    invoiceLine.getFundDistributions().add(amountDistribution);
    addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
    addMockEntry(BUDGETS, JsonObject.mapFrom(budget));
    addMockEntry(FUNDS, JsonObject.mapFrom(fund));
    addMockEntry(LEDGERS, JsonObject.mapFrom(ledger));
    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);
}
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) Ledger(org.folio.rest.acq.model.finance.Ledger) Budget(org.folio.rest.acq.model.finance.Budget) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 97 with InvoiceLine

use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.

the class InvoicesApiTest method testPutInvoiceByIdChangeStatusToPayedGetFundsServerError.

@Test
void testPutInvoiceByIdChangeStatusToPayedGetFundsServerError() {
    logger.info("=== Test Put Invoice By Id, get Funds server error ===");
    Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
    String id = reqData.getId();
    reqData.setStatus(Status.APPROVED);
    InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
    reqData.setAdjustments(emptyList());
    invoiceLine.setId(UUID.randomUUID().toString());
    invoiceLine.setInvoiceId(reqData.getId());
    invoiceLine.getFundDistributions().get(0).withFundId(ID_FOR_INTERNAL_SERVER_ERROR);
    addMockEntry(INVOICES, reqData);
    addMockEntry(INVOICE_LINES, invoiceLine);
    prepareMockVoucher(id);
    reqData.setStatus(Status.PAID);
    Errors errors = verifyPut(String.format(INVOICE_ID_PATH, id), JsonObject.mapFrom(reqData), APPLICATION_JSON, 500).as(Errors.class);
    assertThat(getRqRsEntries(HttpMethod.GET, INVOICE_LINES), hasSize(1));
    assertThat(getRqRsEntries(HttpMethod.GET, FINANCE_TRANSACTIONS), hasSize(0));
    assertThat(getRqRsEntries(HttpMethod.GET, FUNDS), hasSize(0));
    assertThat(getRqRsEntries(HttpMethod.POST, FINANCE_PAYMENTS), hasSize(0));
    assertThat(getRqRsEntries(HttpMethod.POST, FINANCE_CREDITS), hasSize(0));
    assertThat(errors.getErrors(), hasSize(1));
    Error error = errors.getErrors().get(0);
    assertThat(error.getCode(), equalTo(GENERIC_ERROR_CODE.getCode()));
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) Invoice(org.folio.rest.jaxrs.model.Invoice) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Error(org.folio.rest.jaxrs.model.Error) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 98 with InvoiceLine

use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.

the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaidWithMissingPoLine.

@Test
void testUpdateValidInvoiceTransitionToPaidWithMissingPoLine() {
    logger.info("=== Test transition invoice to paid with deleted associated poLine ===");
    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.setInvoiceId(id);
    invoiceLine.setPoLineId(ID_DOES_NOT_EXIST);
    addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
    prepareMockVoucher(id);
    String jsonBody = JsonObject.mapFrom(reqData).encode();
    Errors errors = verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, APPLICATION_JSON, 404).then().extract().body().as(Errors.class);
    assertThat(serverRqRs.get(INVOICES, HttpMethod.PUT), nullValue());
    assertThat(errors.getErrors(), hasSize(1));
    assertThat(errors.getErrors().get(0).getCode(), equalTo(PO_LINE_NOT_FOUND.getCode()));
    assertThat(errors.getErrors().get(0).getParameters().get(0).getValue(), equalTo(ID_DOES_NOT_EXIST));
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) Invoice(org.folio.rest.jaxrs.model.Invoice) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 99 with InvoiceLine

use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.

the class InvoicesApiTest method testTransitionToApprovedWithAdjustmentFundDistributionsNotPresent.

@Test
void testTransitionToApprovedWithAdjustmentFundDistributionsNotPresent() {
    logger.info("=== Test transition invoice to Approved with adjustment's Fund Distributions empty will fail ===");
    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);
    reqData.setStatus(Invoice.Status.APPROVED);
    Adjustment adjustment = new Adjustment().withProrate(Prorate.NOT_PRORATED).withDescription("Description").withType(Type.AMOUNT).withValue(50d).withRelationToTotal(Adjustment.RelationToTotal.IN_ADDITION_TO);
    reqData.getAdjustments().add(adjustment);
    String id = reqData.getId();
    invoiceLine.setId(UUID.randomUUID().toString());
    invoiceLine.setInvoiceId(id);
    invoiceLine.getFundDistributions().get(0).setDistributionType(FundDistribution.DistributionType.PERCENTAGE);
    invoiceLine.getFundDistributions().get(0).setValue(100d);
    addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
    String jsonBody = JsonObject.mapFrom(reqData).encode();
    Headers headers = prepareHeaders(X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
    Errors errors = verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, APPLICATION_JSON, 400).then().extract().body().as(Errors.class);
    assertThat(errors, notNullValue());
    assertThat(errors.getErrors(), hasSize(1));
    Error error = errors.getErrors().get(0);
    assertThat(error.getMessage(), equalTo(ADJUSTMENT_FUND_DISTRIBUTIONS_NOT_PRESENT.getDescription()));
    assertThat(error.getCode(), equalTo(ADJUSTMENT_FUND_DISTRIBUTIONS_NOT_PRESENT.getCode()));
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) 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) Error(org.folio.rest.jaxrs.model.Error) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 100 with InvoiceLine

use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.

the class InvoicesApiTest method testTransitionToApprovedWithFundDistributionsTotalAmountNotEqualToLineTotal.

@Test
void testTransitionToApprovedWithFundDistributionsTotalAmountNotEqualToLineTotal() {
    logger.info("=== Test transition invoice to Approved with Fund Distributions empty will fail ===");
    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);
    reqData.setStatus(Invoice.Status.APPROVED);
    String id = reqData.getId();
    invoiceLine.setId(UUID.randomUUID().toString());
    invoiceLine.setInvoiceId(id);
    invoiceLine.getFundDistributions().get(0).setDistributionType(AMOUNT);
    invoiceLine.getFundDistributions().get(0).setValue(100d);
    invoiceLine.setSubTotal(300d);
    addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
    String jsonBody = JsonObject.mapFrom(reqData).encode();
    Headers headers = prepareHeaders(X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
    Errors errors = verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, APPLICATION_JSON, 400).then().extract().body().as(Errors.class);
    assertThat(errors, notNullValue());
    assertThat(errors.getErrors(), hasSize(1));
    Error error = errors.getErrors().get(0);
    assertThat(error.getMessage(), equalTo(LINE_FUND_DISTRIBUTIONS_SUMMARY_MISMATCH.getDescription()));
    assertThat(error.getCode(), equalTo(LINE_FUND_DISTRIBUTIONS_SUMMARY_MISMATCH.getCode()));
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) Invoice(org.folio.rest.jaxrs.model.Invoice) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Headers(io.restassured.http.Headers) Error(org.folio.rest.jaxrs.model.Error) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)120 Test (org.junit.jupiter.api.Test)88 Invoice (org.folio.rest.jaxrs.model.Invoice)83 Matchers.containsString (org.hamcrest.Matchers.containsString)58 Adjustment (org.folio.rest.jaxrs.model.Adjustment)45 JsonObject (io.vertx.core.json.JsonObject)39 Errors (org.folio.rest.jaxrs.model.Errors)36 Headers (io.restassured.http.Headers)34 Error (org.folio.rest.jaxrs.model.Error)30 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)26 ArrayList (java.util.ArrayList)25 InvoiceLineCollection (org.folio.rest.jaxrs.model.InvoiceLineCollection)25 List (java.util.List)24 RequestContext (org.folio.rest.core.models.RequestContext)22 Collections (java.util.Collections)21 Fund (org.folio.rest.acq.model.finance.Fund)20 Voucher (org.folio.rest.jaxrs.model.Voucher)20 Vertx (io.vertx.core.Vertx)19 LogManager (org.apache.logging.log4j.LogManager)17 Logger (org.apache.logging.log4j.Logger)17