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()));
}
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());
}
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));
}
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);
}
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);
}
Aggregations