use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.
the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountGreaterThanBudgetRemainingAmountAndBudgetRestricted.
@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountGreaterThanBudgetRemainingAmountAndBudgetRestricted() {
String fiscalYearId = UUID.randomUUID().toString();
String fundId = UUID.randomUUID().toString();
String budgetId = UUID.randomUUID().toString();
String fundCode = "TEST-FUND";
Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(10d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(59d).withTotalFunding(59d).withAvailable(0d).withUnavailable(50d).withAwaitingPayment(50d).withAllowableEncumbrance(100d);
List<EncumbranceRelationsHolder> holders = new ArrayList<>();
FundDistribution fundDistribution = new FundDistribution().withFundId(fundId).withCode(fundCode);
EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(null).withNewEncumbrance(newTransaction).withBudget(budget).withRestrictEncumbrances(true).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD").withFundDistribution(fundDistribution);
holders.add(holder);
HttpException httpException = assertThrows(HttpException.class, () -> restrictionService.checkEncumbranceRestrictions(holders));
assertEquals(422, httpException.getCode());
Error error = httpException.getError();
assertEquals(FUND_CANNOT_BE_PAID.getCode(), error.getCode());
assertEquals(Collections.singletonList(fundCode).toString(), error.getParameters().get(0).getValue());
}
use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.
the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndRestrictEncumbranceIsFalse.
@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndRestrictEncumbranceIsFalse() {
String fiscalYearId = UUID.randomUUID().toString();
String fundId = 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).withTotalFunding(59d).withAvailable(0d).withUnavailable(50d).withAwaitingPayment(50d).withAllowableEncumbrance(100d);
List<EncumbranceRelationsHolder> holders = new ArrayList<>();
EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(existingTransaction).withNewEncumbrance(newTransaction).withBudget(budget).withRestrictEncumbrances(false).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD");
holders.add(holder);
assertDoesNotThrow(() -> restrictionService.checkEncumbranceRestrictions(holders));
}
use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.
the class EncumbranceRelationsHoldersBuilderTest method testShouldPopulatePoLineToFiscalYearCurrencyConversion.
@Test
void testShouldPopulatePoLineToFiscalYearCurrencyConversion() {
// given
String currency = "RUB";
List<EncumbranceRelationsHolder> holders = new ArrayList<>();
holders.add(holder1.withCurrency(currency));
holders.add(holder2.withCurrency(currency));
holders.add(holder3.withCurrency(currency));
ExchangeRateProvider exchangeRateProvider = mock(ManualExchangeRateProvider.class);
when(exchangeRateProviderResolver.resolve(any(), any())).thenReturn(exchangeRateProvider);
when(exchangeRateProvider.getCurrencyConversion(any(ConversionQuery.class))).thenAnswer(invocation -> {
ConversionQuery conversionQuery = invocation.getArgument(0);
return mock(ManualCurrencyConversion.class, conversionQuery.getBaseCurrency().getCurrencyCode());
});
when(requestContextMock.getContext()).thenReturn(Vertx.vertx().getOrCreateContext());
// When
encumbranceRelationsHoldersBuilder.withConversion(holders, requestContextMock).join();
// Then
assertEquals("USD", holder1.getPoLineToFyConversion().toString());
assertEquals("USD", holder2.getPoLineToFyConversion().toString());
assertSame(holder1.getPoLineToFyConversion(), holder2.getPoLineToFyConversion());
assertEquals("EUR", holder3.getPoLineToFyConversion().toString());
}
use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.
the class EncumbranceRelationsHoldersBuilderTest method testShouldPopulateHoldersWithOldEncumbranceIfMatchesTransactionFromStorage.
@Test
void testShouldPopulateHoldersWithOldEncumbranceIfMatchesTransactionFromStorage() {
// given
Transaction encumbranceFromStorage = new Transaction().withId(UUID.randomUUID().toString()).withFromFundId(distribution1.getFundId()).withSource(PO_LINE).withAmount(38d).withFiscalYearId(UUID.randomUUID().toString()).withEncumbrance(new Encumbrance().withSubscription(false).withReEncumber(true).withOrderType(ONGOING).withSourcePurchaseOrderId(order.getId()).withSourcePoLineId(line1.getId()).withInitialAmountEncumbered(68d).withAmountExpended(10d).withAmountAwaitingPayment(20d));
List<EncumbranceRelationsHolder> holders = new ArrayList<>();
holders.add(holder1);
holders.add(holder2);
when(encumbranceService.getEncumbrancesByIds(anyList(), any())).thenReturn(CompletableFuture.completedFuture(singletonList(encumbranceFromStorage)));
// When
List<EncumbranceRelationsHolder> resultHolders = encumbranceRelationsHoldersBuilder.withExistingTransactions(holders, order, requestContextMock).join();
// Then
assertThat(resultHolders, hasSize(2));
assertEquals(encumbranceFromStorage, holder1.getOldEncumbrance());
assertEquals(encumbranceFromStorage.getId(), holder1.getNewEncumbrance().getId());
assertEquals(encumbranceFromStorage.getEncumbrance().getAmountExpended(), holder1.getNewEncumbrance().getEncumbrance().getAmountExpended());
assertEquals(encumbranceFromStorage.getEncumbrance().getAmountAwaitingPayment(), holder1.getNewEncumbrance().getEncumbrance().getAmountAwaitingPayment());
assertNull(holder2.getOldEncumbrance());
}
Aggregations