Search in sources :

Example 6 with ReEncumbranceHolder

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

the class ReEncumbranceHoldersBuilderTest method shouldNotRetrieveRolloversIfReEncumbranceHoldersCurrentFiscalYearNull.

@Test
void shouldNotRetrieveRolloversIfReEncumbranceHoldersCurrentFiscalYearNull() {
    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());
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId());
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId());
    ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withLedgerId(fund3.getLedgerId());
    ReEncumbranceHolder holder4 = new ReEncumbranceHolder().withLedgerId(fund4.getLedgerId());
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3, holder4);
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withRollovers(holders, requestContext).join();
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund1.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund2.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund3.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund4.getLedgerId())))));
    verify(rolloverRetrieveService, never()).getLedgerFyRollovers(anyString(), anyList(), any());
}
Also used : Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 7 with ReEncumbranceHolder

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

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithFromFyEncumbrances.

@Test
void shouldPopulateReEncumbranceHoldersWithFromFyEncumbrances() {
    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();
    EncumbranceRollover encumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.REMAINING).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);
    Transaction fromEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId)).withAmount(10d).withFiscalYearId(fromFyId).withFromFundId(fund1Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    Transaction fromEncumbrance2 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId)).withAmount(100d).withFiscalYearId(fromFyId).withFromFundId(fund2Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    FundDistribution fundDistribution1 = new FundDistribution().withFundId(fund1Id).withEncumbrance(fromEncumbrance1.getId());
    FundDistribution fundDistribution2 = new FundDistribution().withFundId(fund2Id).withEncumbrance(fromEncumbrance2.getId());
    CompositePoLine line1 = new CompositePoLine().withId(UUID.randomUUID().toString()).withFundDistribution(Collections.singletonList(fundDistribution1));
    CompositePoLine line2 = new CompositePoLine().withId(UUID.randomUUID().toString()).withFundDistribution(Collections.singletonList(fundDistribution2));
    Transaction toEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(line1.getId())).withId(UUID.randomUUID().toString()).withFiscalYearId(toFyId).withFromFundId(fund1Id).withCurrency("USD");
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line1).withFundDistribution(fundDistribution1).withEncumbranceRollover(encumbranceRollover);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line2).withFundDistribution(fundDistribution2).withEncumbranceRollover(encumbranceRollover);
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
    TransactionCollection fromTransactionCollection = new TransactionCollection().withTransactions(Arrays.asList(fromEncumbrance1, fromEncumbrance2)).withTotalRecords(2);
    TransactionCollection toTransactionCollection = new TransactionCollection().withTransactions(Collections.singletonList(toEncumbrance1)).withTotalRecords(1);
    when(transactionService.getTransactions(contains(fromFyId), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(fromTransactionCollection));
    when(transactionService.getTransactions(contains(toFyId), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(toTransactionCollection));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withPreviousFyEncumbrances(holders, requestContext).join();
    assertThat(resultHolders, hasItem(hasProperty("previousFyEncumbrance", is(fromEncumbrance1))));
    assertThat(resultHolders, hasItem(hasProperty("previousFyEncumbrance", is(fromEncumbrance2))));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) 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) Test(org.junit.jupiter.api.Test)

Example 8 with ReEncumbranceHolder

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

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithFromFyEncumbrancesWhenBasedOnExpended.

@Test
void shouldPopulateReEncumbranceHoldersWithFromFyEncumbrancesWhenBasedOnExpended() {
    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();
    EncumbranceRollover encumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.EXPENDED).withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withIncreaseBy(0d);
    LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withFromFiscalYearId(fromFyId).withToFiscalYearId(toFyId).withEncumbrancesRollover(Collections.singletonList(encumbranceRollover));
    CompositePurchaseOrder compPO = new CompositePurchaseOrder().withId(orderId).withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME);
    Transaction fromEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withAmountExpended(20d)).withAmount(10d).withFiscalYearId(fromFyId).withFromFundId(fund1Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    Transaction fromEncumbrance2 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withAmountExpended(10d)).withAmount(100d).withFiscalYearId(fromFyId).withFromFundId(fund2Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    FundDistribution fundDistribution1 = new FundDistribution().withFundId(fund1Id).withEncumbrance(fromEncumbrance1.getId());
    FundDistribution fundDistribution2 = new FundDistribution().withFundId(fund2Id).withEncumbrance(fromEncumbrance2.getId());
    CompositePoLine line1 = new CompositePoLine().withId(UUID.randomUUID().toString()).withFundDistribution(Collections.singletonList(fundDistribution1));
    CompositePoLine line2 = new CompositePoLine().withId(UUID.randomUUID().toString()).withFundDistribution(Collections.singletonList(fundDistribution2));
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line1).withFundDistribution(fundDistribution1).withEncumbranceRollover(encumbranceRollover);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line2).withFundDistribution(fundDistribution2).withEncumbranceRollover(encumbranceRollover);
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
    TransactionCollection fromTransactionCollection = new TransactionCollection().withTransactions(Arrays.asList(fromEncumbrance1, fromEncumbrance2)).withTotalRecords(2);
    TransactionCollection toTransactionCollection = new TransactionCollection().withTransactions(Collections.emptyList()).withTotalRecords(0);
    when(transactionService.getTransactions(contains(fromFyId), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(fromTransactionCollection));
    when(transactionService.getTransactions(contains(toFyId), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(toTransactionCollection));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withPreviousFyEncumbrances(holders, requestContext).join();
    assertThat(resultHolders, hasItem(hasProperty("previousFyEncumbrance", is(fromEncumbrance1))));
    assertThat(resultHolders, hasItem(hasProperty("previousFyEncumbrance", is(fromEncumbrance2))));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) 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) Test(org.junit.jupiter.api.Test)

Example 9 with ReEncumbranceHolder

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

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithOngoingEncumbranceRolloverWhenOrderTypeOngoingAndSubscriptionFalse.

@Test
void shouldPopulateReEncumbranceHoldersWithOngoingEncumbranceRolloverWhenOrderTypeOngoingAndSubscriptionFalse() {
    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 10 with ReEncumbranceHolder

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

the class OrderReEncumberServiceTest method shouldThrowHttpExceptionWithFundsNotFoundCodeWhenAtLeastOneFundIsMissing.

@Test
void shouldThrowHttpExceptionWithFundsNotFoundCodeWhenAtLeastOneFundIsMissing() {
    String orderId = UUID.randomUUID().toString();
    String fundId1 = UUID.randomUUID().toString();
    String fundId2 = UUID.randomUUID().toString();
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withFundDistribution(new FundDistribution().withFundId(fundId1)).withLedgerId(UUID.randomUUID().toString());
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withFundDistribution(new FundDistribution().withFundId(fundId2));
    List<ReEncumbranceHolder> holders = List.of(holder1, holder2);
    when(purchaseOrderStorageService.getCompositeOrderById(anyString(), any())).thenReturn(completedFuture(new CompositePurchaseOrder()));
    when(spyReEncumbranceHoldersBuilder.buildReEncumbranceHoldersWithOrdersData(any())).thenReturn(holders);
    when(spyReEncumbranceHoldersBuilder.withFundsData(any(), any())).thenReturn(completedFuture(holders));
    CompletionException completionException = assertThrows(CompletionException.class, () -> orderReEncumberService.reEncumber(orderId, requestContext).join());
    assertNotNull(completionException.getCause());
    assertThat(completionException.getCause(), instanceOf(HttpException.class));
    HttpException e = (HttpException) completionException.getCause();
    assertEquals(FUNDS_NOT_FOUND.getCode(), e.getError().getCode());
    assertEquals(e.getError().getParameters(), Collections.singletonList(new Parameter().withKey("fund").withValue(fundId2)));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) CompletionException(java.util.concurrent.CompletionException) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Parameter(org.folio.rest.jaxrs.model.Parameter) HttpException(org.folio.rest.core.exceptions.HttpException) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) 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