Search in sources :

Example 21 with ReEncumbranceHolder

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());
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Test(org.junit.jupiter.api.Test)

Example 22 with ReEncumbranceHolder

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()))));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Test(org.junit.jupiter.api.Test)

Example 23 with ReEncumbranceHolder

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))))));
}
Also used : EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) MonetaryAmount(javax.money.MonetaryAmount) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) ManualCurrencyConversion(org.folio.service.exchange.ManualCurrencyConversion) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) Test(org.junit.jupiter.api.Test)

Example 24 with ReEncumbranceHolder

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())))));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Test(org.junit.jupiter.api.Test)

Example 25 with ReEncumbranceHolder

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())));
}
Also used : EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Ongoing(org.folio.rest.jaxrs.model.Ongoing) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Test(org.junit.jupiter.api.Test)

Aggregations

ReEncumbranceHolder (org.folio.models.ReEncumbranceHolder)31 Test (org.junit.jupiter.api.Test)28 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)16 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)14 LedgerFiscalYearRollover (org.folio.rest.jaxrs.model.LedgerFiscalYearRollover)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 Fund (org.folio.rest.acq.model.finance.Fund)11 EncumbranceRollover (org.folio.rest.jaxrs.model.EncumbranceRollover)10 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)9 Transaction (org.folio.rest.acq.model.finance.Transaction)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 TransactionCollection (org.folio.rest.acq.model.finance.TransactionCollection)6 Encumbrance (org.folio.rest.acq.model.finance.Encumbrance)5 Cost (org.folio.rest.jaxrs.model.Cost)5 CompletionException (java.util.concurrent.CompletionException)4 FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)4 Ledger (org.folio.rest.acq.model.finance.Ledger)4 HttpException (org.folio.rest.core.exceptions.HttpException)4 Parameter (org.folio.rest.jaxrs.model.Parameter)4 ConversionQuery (javax.money.convert.ConversionQuery)3