Search in sources :

Example 21 with Fund

use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.

the class FundServiceTest method testShouldRetrieveFundsByFundIds.

@Test
void testShouldRetrieveFundsByFundIds() throws UnsupportedEncodingException {
    // Given
    String fundId1 = UUID.randomUUID().toString();
    String fundId2 = UUID.randomUUID().toString();
    List<String> fundIds = List.of(fundId1, fundId2);
    List<Fund> funds = List.of(new Fund().withId(fundId1), new Fund().withId(fundId2));
    FundCollection fundCollection = new FundCollection().withFunds(funds).withTotalRecords(1);
    String query = URLEncoder.encode("id==(" + fundId1 + " or " + fundId2 + ")", StandardCharsets.UTF_8.toString());
    doReturn(completedFuture(fundCollection)).when(restClient).get(any(), any(), any());
    // When
    List<Fund> actFund = fundService.getAllFunds(fundIds, requestContext).join();
    // Then
    ArgumentCaptor<RequestEntry> argumentCaptor = ArgumentCaptor.forClass(RequestEntry.class);
    verify(restClient).get(argumentCaptor.capture(), any(), eq(FundCollection.class));
    RequestEntry requestEntry = argumentCaptor.getValue();
    assertEquals(query, requestEntry.getQueryParams().get("query"));
    assertEquals(0, requestEntry.getQueryParams().get("offset"));
    assertEquals(MAX_IDS_FOR_GET_RQ, requestEntry.getQueryParams().get("limit"));
    assertThat(actFund, equalTo(fundCollection.getFunds()));
}
Also used : CompositeFund(org.folio.rest.acq.model.finance.CompositeFund) Fund(org.folio.rest.acq.model.finance.Fund) FundCollection(org.folio.rest.acq.model.finance.FundCollection) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 22 with Fund

use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.

the class FundServiceTest method testShouldRetrieveFundById.

@Test
void testShouldRetrieveFundById() {
    // Given
    String ledgerId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    CompositeFund compositeFund = new CompositeFund().withFund(new Fund().withId(fundId).withLedgerId(ledgerId));
    doReturn(completedFuture(compositeFund)).when(restClient).get(any(), eq(requestContext), eq(CompositeFund.class));
    // When
    Fund actFund = fundService.retrieveFundById(fundId, requestContext).join();
    // Then
    assertThat(actFund, equalTo(compositeFund.getFund()));
    ArgumentCaptor<RequestEntry> argumentCaptor = ArgumentCaptor.forClass(RequestEntry.class);
    verify(restClient).get(argumentCaptor.capture(), eq(requestContext), eq(CompositeFund.class));
    RequestEntry requestEntry = argumentCaptor.getValue();
    assertEquals("/finance/funds/" + fundId, requestEntry.buildEndpoint());
}
Also used : CompositeFund(org.folio.rest.acq.model.finance.CompositeFund) Fund(org.folio.rest.acq.model.finance.Fund) CompositeFund(org.folio.rest.acq.model.finance.CompositeFund) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 23 with Fund

use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.

the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceLessThanBudgetRemainingAmount.

@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceLessThanBudgetRemainingAmount() {
    String fiscalYearId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    String budgetId = UUID.randomUUID().toString();
    Transaction existingTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(50d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
    Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(60d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
    Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(59d).withAvailable(9d).withTotalFunding(59d).withUnavailable(50d).withAwaitingPayment(50D).withAllowableEncumbrance(150d);
    Fund fund = new Fund().withId(fundId).withLedgerId(ledgerId);
    Ledger ledger = new Ledger().withId(ledgerId).withRestrictEncumbrance(true);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(existingTransaction).withNewEncumbrance(newTransaction).withBudget(budget).withLedgerId(fund.getLedgerId()).withRestrictEncumbrances(ledger.getRestrictExpenditures()).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD");
    holders.add(holder);
    assertDoesNotThrow(() -> restrictionService.checkEncumbranceRestrictions(holders));
}
Also used : Transaction(org.folio.rest.acq.model.finance.Transaction) Fund(org.folio.rest.acq.model.finance.Fund) Ledger(org.folio.rest.acq.model.finance.Ledger) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Budget(org.folio.rest.acq.model.finance.Budget) Test(org.junit.jupiter.api.Test)

Example 24 with Fund

use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.

the class MockServer method getFundsByIds.

private JsonObject getFundsByIds(List<String> fundIds) {
    Supplier<List<Fund>> getFromFile = () -> {
        try {
            return new JsonObject(getMockData(FUNDS_PATH)).mapTo(FundCollection.class).getFunds();
        } catch (IOException e) {
            return Collections.emptyList();
        }
    };
    List<Fund> funds = getMockEntries(FUNDS, Fund.class).orElseGet(getFromFile);
    if (!fundIds.isEmpty()) {
        funds.removeIf(item -> !fundIds.contains(item.getId()));
    }
    Object record = new FundCollection().withFunds(funds).withTotalRecords(funds.size());
    return JsonObject.mapFrom(record);
}
Also used : Fund(org.folio.rest.acq.model.finance.Fund) JsonObject(io.vertx.core.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) JsonObject(io.vertx.core.json.JsonObject) FundCollection(org.folio.rest.acq.model.finance.FundCollection) IOException(java.io.IOException)

Example 25 with Fund

use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.

the class PurchaseOrderLinesApiTest method testShouldUnreleasedEncumbrancesAfterUncancelledPoLine.

@Test
void testShouldUnreleasedEncumbrancesAfterUncancelledPoLine() {
    logger.info("=== Test unreleased encumbrances after uncancelled PoLine ===");
    CompositePoLine lineFromStorage = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, "740809a1-84ca-45d7-a7a8-accc21efd5bd").mapTo(CompositePoLine.class);
    lineFromStorage.setReceiptStatus(ReceiptStatus.CANCELLED);
    lineFromStorage.setPaymentStatus(PaymentStatus.CANCELLED);
    CompositePoLine reqData = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, "740809a1-84ca-45d7-a7a8-accc21efd5bd").mapTo(CompositePoLine.class);
    reqData.setReceiptStatus(ReceiptStatus.AWAITING_RECEIPT);
    reqData.setPaymentStatus(PaymentStatus.AWAITING_PAYMENT);
    Fund fund = new Fund().withId("7fbd5d84-62d1-44c6-9c45-6cb173998bbd").withName("Fund").withExternalAccountNo("externalNo").withLedgerId("133a7916-f05e-4df4-8f7f-09eb2a7076d1");
    addMockEntry(PIECES_STORAGE, new Piece().withPoLineId(reqData.getId()).withLocationId(reqData.getLocations().get(0).getLocationId()));
    addMockEntry(PO_LINES_STORAGE, lineFromStorage);
    addMockEntry(FUNDS, fund);
    verifyPut(String.format(LINE_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), "", 204);
}
Also used : Fund(org.folio.rest.acq.model.finance.Fund) Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

Fund (org.folio.rest.acq.model.finance.Fund)47 Test (org.junit.jupiter.api.Test)39 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)17 Budget (org.folio.rest.acq.model.finance.Budget)15 ArrayList (java.util.ArrayList)14 Transaction (org.folio.rest.acq.model.finance.Transaction)12 FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)11 FundCollection (org.folio.rest.acq.model.finance.FundCollection)11 ReEncumbranceHolder (org.folio.models.ReEncumbranceHolder)10 Invoice (org.folio.rest.jaxrs.model.Invoice)10 InvoiceWorkflowDataHolder (org.folio.models.InvoiceWorkflowDataHolder)9 Error (org.folio.rest.jaxrs.model.Error)9 InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 List (java.util.List)8 Headers (io.restassured.http.Headers)7 HttpException (org.folio.invoices.rest.exceptions.HttpException)7 JsonObject (io.vertx.core.json.JsonObject)6 Ledger (org.folio.rest.acq.model.finance.Ledger)6 ConversionQuery (javax.money.convert.ConversionQuery)5