use of org.folio.models.ReEncumbranceHolder in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldPopulateEachReEncumbranceHolderWithCorrespondingLedgerIdIfAllFundsFound.
@Test
void shouldPopulateEachReEncumbranceHolderWithCorrespondingLedgerIdIfAllFundsFound() {
FundDistribution fundDistribution1 = new FundDistribution().withFundId(UUID.randomUUID().toString());
FundDistribution fundDistribution2 = new FundDistribution().withFundId(UUID.randomUUID().toString());
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withFundDistribution(fundDistribution1);
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withFundDistribution(fundDistribution2);
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
Fund fund1 = new Fund().withId(fundDistribution1.getFundId()).withLedgerId(UUID.randomUUID().toString());
Fund fund2 = new Fund().withId(fundDistribution2.getFundId()).withLedgerId(UUID.randomUUID().toString());
when(fundService.getFunds(anyCollection(), any())).thenReturn(CompletableFuture.completedFuture(Arrays.asList(fund2, fund1)));
reEncumbranceHoldersBuilder.withFundsData(holders, requestContext).join();
assertEquals(fund1.getLedgerId(), holder1.getLedgerId());
assertEquals(fund2.getLedgerId(), holder2.getLedgerId());
}
use of org.folio.models.ReEncumbranceHolder in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldPopulateEachReEncumbranceHolderWithFiscalYearIfFundExist.
@Test
void shouldPopulateEachReEncumbranceHolderWithFiscalYearIfFundExist() {
Fund fund1 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
Fund fund2 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId());
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId());
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
FiscalYear fiscalYear = new FiscalYear().withId(UUID.randomUUID().toString());
when(fiscalYearService.getCurrentFiscalYear(anyString(), any())).thenReturn(CompletableFuture.completedFuture(fiscalYear));
List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withCurrentFiscalYearData(holders, requestContext).join();
assertThat(resultHolders, everyItem(hasProperty("currentFiscalYearId", is(fiscalYear.getId()))));
assertThat(resultHolders, everyItem(hasProperty("currency", is(fiscalYear.getCurrency()))));
}
use of org.folio.models.ReEncumbranceHolder in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithToFyEncumbrancesWhenBasedOnExpended.
@Test
void shouldPopulateReEncumbranceHoldersWithToFyEncumbrancesWhenBasedOnExpended() {
String fromFyId = UUID.randomUUID().toString();
String toFyId = UUID.randomUUID().toString();
String orderId = UUID.randomUUID().toString();
String fund1Id = UUID.randomUUID().toString();
String fund2Id = UUID.randomUUID().toString();
double exchangeEurToUsdRate = 1.1d;
EncumbranceRollover encumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.EXPENDED).withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withIncreaseBy(10d);
LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withFromFiscalYearId(fromFyId).withToFiscalYearId(toFyId).withEncumbrancesRollover(Collections.singletonList(encumbranceRollover));
CompositePurchaseOrder compPO = new CompositePurchaseOrder().withId(orderId).withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME);
Cost cost1 = new Cost().withListUnitPrice(120d).withQuantityPhysical(1).withExchangeRate(exchangeEurToUsdRate).withCurrency("EUR").withPoLineEstimatedPrice(120d).withFyroAdjustmentAmount(-35.3d);
Transaction fromEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withInitialAmountEncumbered(60d).withAmountExpended(40d)).withAmount(20d).withFiscalYearId(fromFyId).withFromFundId(fund1Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
Transaction fromEncumbrance2 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withInitialAmountEncumbered(60d).withAmountExpended(30d)).withAmount(30d).withFiscalYearId(fromFyId).withFromFundId(fund2Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
FundDistribution fundDistribution1 = new FundDistribution().withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withValue(50d).withEncumbrance(fromEncumbrance1.getId()).withFundId(fund1Id);
FundDistribution fundDistribution2 = new FundDistribution().withDistributionType(FundDistribution.DistributionType.AMOUNT).withValue(42.35d).withEncumbrance(fromEncumbrance2.getId()).withFundId(fund2Id);
CompositePoLine line1 = new CompositePoLine().withId(UUID.randomUUID().toString()).withCost(cost1).withFundDistribution(List.of(fundDistribution1, fundDistribution2));
ManualCurrencyConversion poLineToFyConversion = mock(ManualCurrencyConversion.class, withSettings().name("poLineToFyConversion"));
ManualCurrencyConversion poFyToPoLineConversion = mock(ManualCurrencyConversion.class, withSettings().name("poFyToPoLineConversion"));
TransactionCollection toTransactionCollection = new TransactionCollection().withTransactions(Collections.emptyList()).withTotalRecords(0);
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line1).withFundDistribution(fundDistribution1).withEncumbranceRollover(encumbranceRollover).withPreviousFyEncumbrance(fromEncumbrance1).withPoLineToFyConversion(poLineToFyConversion).withFyToPoLineConversion(poFyToPoLineConversion).withCurrency("USD");
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line1).withFundDistribution(fundDistribution2).withEncumbranceRollover(encumbranceRollover).withPreviousFyEncumbrance(fromEncumbrance2).withPoLineToFyConversion(poLineToFyConversion).withFyToPoLineConversion(poFyToPoLineConversion).withCurrency("USD");
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
when(transactionService.getTransactions(contains(toFyId), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(toTransactionCollection));
when(poLineToFyConversion.with(any())).thenReturn(poLineToFyConversion);
when(poLineToFyConversion.apply(any(MonetaryAmount.class))).thenAnswer(invocation -> {
MonetaryAmount amount = invocation.getArgument(0);
return Money.of(amount.getNumber(), "USD").multiply(exchangeEurToUsdRate);
});
when(poFyToPoLineConversion.getCurrency()).thenReturn(Monetary.getCurrency("USD"));
when(exchangeRateProviderResolver.resolve(any(), any())).thenReturn(exchangeRateProvider);
List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withToEncumbrances(holders, requestContext).join();
assertThat(resultHolders, hasItem(hasProperty("newEncumbrance", allOf(hasProperty("id", nullValue()), hasProperty("currency", is(fromEncumbrance1.getCurrency())), hasProperty("fromFundId", is(fromEncumbrance1.getFromFundId())), hasProperty("amount", is(46.59d)), hasProperty("fiscalYearId", is(toFyId))))));
assertThat(resultHolders, hasItem(hasProperty("newEncumbrance", allOf(hasProperty("id", nullValue()), hasProperty("currency", is(fromEncumbrance2.getCurrency())), hasProperty("fromFundId", is(fromEncumbrance2.getFromFundId())), hasProperty("amount", is(46.58d)), hasProperty("fiscalYearId", is(toFyId))))));
}
use of org.folio.models.ReEncumbranceHolder in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithCorrespondingRollover.
@Test
void shouldPopulateReEncumbranceHoldersWithCorrespondingRollover() {
String ledgerId1 = UUID.randomUUID().toString();
String ledgerId2 = UUID.randomUUID().toString();
Fund fund1 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(ledgerId1);
Fund fund2 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(ledgerId2);
Fund fund3 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(ledgerId2);
Fund fund4 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
FiscalYear currentFiscalYear = new FiscalYear().withId(UUID.randomUUID().toString());
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withLedgerId(fund3.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
ReEncumbranceHolder holder4 = new ReEncumbranceHolder().withLedgerId(fund4.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3, holder4);
LedgerFiscalYearRollover rollover1 = new LedgerFiscalYearRollover().withLedgerId(ledgerId1);
LedgerFiscalYearRollover rollover2 = new LedgerFiscalYearRollover().withLedgerId(ledgerId2);
when(rolloverRetrieveService.getLedgerFyRollovers(anyString(), anyList(), any())).thenReturn(CompletableFuture.completedFuture(Arrays.asList(rollover1, rollover2)));
List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withRollovers(holders, requestContext).join();
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", is(rollover1)), hasProperty("ledgerId", is(fund1.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", is(rollover2)), hasProperty("ledgerId", is(fund2.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", is(rollover2)), hasProperty("ledgerId", is(fund3.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund4.getLedgerId())))));
}
use of org.folio.models.ReEncumbranceHolder in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldNotPopulateReEncumbranceHoldersWithEncumbranceRolloverWhenEncumbranceRolloversNotContainsItemWithOrderType.
@Test
void shouldNotPopulateReEncumbranceHoldersWithEncumbranceRolloverWhenEncumbranceRolloversNotContainsItemWithOrderType() {
EncumbranceRollover oneTimeEncumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.REMAINING).withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withIncreaseBy(10d);
EncumbranceRollover ongoingEncumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.EXPENDED).withOrderType(EncumbranceRollover.OrderType.ONGOING).withIncreaseBy(10d);
CompositePurchaseOrder compPO = new CompositePurchaseOrder().withOrderType(CompositePurchaseOrder.OrderType.ONGOING).withOngoing(new Ongoing().withIsSubscription(true));
LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withEncumbrancesRollover(Arrays.asList(oneTimeEncumbranceRollover, ongoingEncumbranceRollover));
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover);
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover);
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withEncumbranceRollover(holders);
assertThat(resultHolders, everyItem(hasProperty("encumbranceRollover", nullValue())));
}
Aggregations