Search in sources :

Example 1 with ReEncumbranceHolder

use of org.folio.models.ReEncumbranceHolder in project mod-orders by folio-org.

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHolderFundWithNullIfCorrespondingFundsFound.

@Test
void shouldPopulateReEncumbranceHolderFundWithNullIfCorrespondingFundsFound() {
    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());
    when(fundService.getFunds(anyCollection(), any())).thenReturn(CompletableFuture.completedFuture(Collections.singletonList(fund1)));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withFundsData(holders, requestContext).join();
    assertThat(resultHolders, hasItem(allOf(hasProperty("ledgerId", is(fund1.getLedgerId())), hasProperty("fundDistribution", is(fundDistribution1)))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("ledgerId", nullValue()), hasProperty("fundDistribution", is(fundDistribution2)))));
}
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 2 with ReEncumbranceHolder

use of org.folio.models.ReEncumbranceHolder in project mod-orders by folio-org.

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithOneTimeEncumbranceRolloverWhenOrderTypeOneTime.

@Test
void shouldPopulateReEncumbranceHoldersWithOneTimeEncumbranceRolloverWhenOrderTypeOneTime() {
    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);
    EncumbranceRollover subscriptionEncumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.REMAINING).withOrderType(EncumbranceRollover.OrderType.ONGOING_SUBSCRIPTION).withIncreaseBy(10d);
    CompositePurchaseOrder compPO = new CompositePurchaseOrder().withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME);
    LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withEncumbrancesRollover(Arrays.asList(oneTimeEncumbranceRollover, ongoingEncumbranceRollover, subscriptionEncumbranceRollover));
    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", is(oneTimeEncumbranceRollover))));
}
Also used : EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Test(org.junit.jupiter.api.Test)

Example 3 with ReEncumbranceHolder

use of org.folio.models.ReEncumbranceHolder in project mod-orders by folio-org.

the class ReEncumbranceHoldersBuilderTest method shouldNotPopulateCurrentFiscalYearForReEncumbranceHoldersIfNoneHolderHasFund.

@Test
void shouldNotPopulateCurrentFiscalYearForReEncumbranceHoldersIfNoneHolderHasFund() {
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder();
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder();
    ReEncumbranceHolder holder3 = new ReEncumbranceHolder();
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3);
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withCurrentFiscalYearData(holders, requestContext).join();
    assertThat(resultHolders, everyItem(hasProperty("currentFiscalYearId", nullValue())));
    assertThat(resultHolders, everyItem(hasProperty("currency", nullValue())));
    verify(fiscalYearService, never()).getCurrentFiscalYear(anyString(), any());
}
Also used : ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Test(org.junit.jupiter.api.Test)

Example 4 with ReEncumbranceHolder

use of org.folio.models.ReEncumbranceHolder in project mod-orders by folio-org.

the class ReEncumbranceHoldersBuilderTest method shouldCreateNewReEncumbranceHoldersForEveryFundDistributions.

@Test
void shouldCreateNewReEncumbranceHoldersForEveryFundDistributions() {
    FundDistribution fundDistribution1 = new FundDistribution().withFundId(UUID.randomUUID().toString());
    FundDistribution fundDistribution2 = new FundDistribution().withFundId(UUID.randomUUID().toString());
    CompositePoLine compositePoLine1 = new CompositePoLine().withId(UUID.randomUUID().toString()).withFundDistribution(Arrays.asList(fundDistribution1, fundDistribution2));
    CompositePoLine compositePoLine2 = new CompositePoLine().withId(UUID.randomUUID().toString());
    CompositePurchaseOrder compPO = new CompositePurchaseOrder().withId(UUID.randomUUID().toString()).withCompositePoLines(Arrays.asList(compositePoLine1, compositePoLine2));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.buildReEncumbranceHoldersWithOrdersData(compPO);
    assertThat(resultHolders, hasSize(2));
    assertThat(resultHolders, everyItem(allOf(hasProperty("purchaseOrder", is(compPO)), hasProperty("poLine", is(compositePoLine1)), hasProperty("fundDistribution", isOneOf(fundDistribution1, fundDistribution2)))));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Example 5 with ReEncumbranceHolder

use of org.folio.models.ReEncumbranceHolder in project mod-orders by folio-org.

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithCorrespondingBudgetsForEveryHolderWithLedgerId.

@Test
void shouldPopulateReEncumbranceHoldersWithCorrespondingBudgetsForEveryHolderWithLedgerId() {
    Fund fund1 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
    Fund fund2 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
    FundDistribution distribution1 = new FundDistribution().withFundId(fund1.getId());
    FundDistribution distribution2 = new FundDistribution().withFundId(fund2.getId());
    FundDistribution distribution3 = new FundDistribution().withFundId(UUID.randomUUID().toString());
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId()).withFundDistribution(distribution1);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId()).withFundDistribution(distribution2);
    ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withFundDistribution(distribution3);
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3);
    Budget budget1 = new Budget().withId(UUID.randomUUID().toString()).withFundId(fund1.getId());
    Budget budget2 = new Budget().withId(UUID.randomUUID().toString()).withFundId(fund2.getId());
    when(budgetService.fetchBudgetsByFundIds(anyList(), any())).thenReturn(CompletableFuture.completedFuture(Arrays.asList(budget1, budget2)));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withBudgets(holders, requestContext).join();
    assertThat(resultHolders, hasItem(allOf(hasProperty("budget", is(budget1)), hasProperty("ledgerId", is(fund1.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("budget", is(budget2)), hasProperty("ledgerId", is(fund2.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("budget", nullValue()), hasProperty("ledgerId", nullValue()))));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Budget(org.folio.rest.acq.model.finance.Budget) 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