Search in sources :

Example 26 with ReEncumbranceHolder

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

the class ReEncumbranceHoldersBuilderTest method shouldNotPopulateRestrictEncumbranceForReEncumbranceHoldersWithoutLedgerId.

@Test
void shouldNotPopulateRestrictEncumbranceForReEncumbranceHoldersWithoutLedgerId() {
    Fund fund1 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId());
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder();
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
    Ledger ledger1 = new Ledger().withId(fund1.getLedgerId()).withRestrictEncumbrance(true);
    when(ledgerService.getLedgersByIds(anyCollection(), any())).thenReturn(CompletableFuture.completedFuture(Collections.singletonList(ledger1)));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withLedgersData(holders, requestContext).join();
    assertThat(resultHolders, hasItem(hasProperty("restrictEncumbrance", is(false))));
    assertThat(resultHolders, hasItem(hasProperty("restrictEncumbrance", is(true))));
}
Also used : Fund(org.folio.rest.acq.model.finance.Fund) Ledger(org.folio.rest.acq.model.finance.Ledger) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Test(org.junit.jupiter.api.Test)

Example 27 with ReEncumbranceHolder

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

the class ReEncumbranceHoldersBuilderTest method shouldPopulateEachReEncumbranceHolderContainingFundWithCorrespondingLedgerData.

@Test
void shouldPopulateEachReEncumbranceHolderContainingFundWithCorrespondingLedgerData() {
    String ledgerId1 = UUID.randomUUID().toString();
    String ledgerId2 = UUID.randomUUID().toString();
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(ledgerId1);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(ledgerId2);
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
    Ledger ledger1 = new Ledger().withId(ledgerId1).withRestrictEncumbrance(true);
    Ledger ledger2 = new Ledger().withId(ledgerId2).withRestrictEncumbrance(false);
    when(ledgerService.getLedgersByIds(anyCollection(), any())).thenReturn(CompletableFuture.completedFuture(Arrays.asList(ledger1, ledger2)));
    reEncumbranceHoldersBuilder.withLedgersData(holders, requestContext).join();
    assertTrue(holder1.getRestrictEncumbrance());
    assertFalse(holder2.getRestrictEncumbrance());
}
Also used : Ledger(org.folio.rest.acq.model.finance.Ledger) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 28 with ReEncumbranceHolder

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

the class ReEncumbranceHoldersBuilderTest method shouldPopulateCurrentFiscalYearDataForReEncumbranceHoldersIfAnyHolderHasFund.

@Test
void shouldPopulateCurrentFiscalYearDataForReEncumbranceHoldersIfAnyHolderHasFund() {
    Fund fund2 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
    Fund fund3 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder();
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId());
    ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withLedgerId(fund3.getLedgerId());
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3);
    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 29 with ReEncumbranceHolder

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

the class ReEncumbranceHoldersBuilderTest method shouldNotRetrieveRolloversIfReEncumbranceHoldersCurrentFundNull.

@Test
void shouldNotRetrieveRolloversIfReEncumbranceHoldersCurrentFundNull() {
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder();
    List<ReEncumbranceHolder> holders = Collections.singletonList(holder1);
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withRollovers(holders, requestContext).join();
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId"))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId"))));
    verify(rolloverRetrieveService, never()).getLedgerFyRollovers(anyString(), anyList(), any());
}
Also used : ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Test(org.junit.jupiter.api.Test)

Example 30 with ReEncumbranceHolder

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

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithOngoingSubscriptionEncumbranceRolloverWhenOrderTypeOngoingAndSubscriptionTrue.

@Test
void shouldPopulateReEncumbranceHoldersWithOngoingSubscriptionEncumbranceRolloverWhenOrderTypeOngoingAndSubscriptionTrue() {
    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.ONGOING).withOngoing(new Ongoing().withIsSubscription(true));
    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(subscriptionEncumbranceRollover))));
}
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