Search in sources :

Example 1 with LedgerFiscalYearRolloverError

use of org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverError in project mod-orders by folio-org.

the class OrderReEncumberServiceTest method testPopulateNeedReEncumberField.

@Test
void testPopulateNeedReEncumberField() {
    // given
    CompositePurchaseOrder order = getMockAsJson(ORDER_PATH).mapTo(CompositePurchaseOrder.class);
    String ledgerId = UUID.randomUUID().toString();
    Fund sampleFund = new Fund().withLedgerId(UUID.randomUUID().toString()).withFundStatus(Fund.FundStatus.ACTIVE).withCode(UUID.randomUUID().toString());
    LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withLedgerId(ledgerId);
    LedgerFiscalYearRolloverErrorCollection ledgerFiscalYearRolloverErrors = new LedgerFiscalYearRolloverErrorCollection().withLedgerFiscalYearRolloverErrors(Collections.singletonList(new LedgerFiscalYearRolloverError()));
    CompositePoLine line = order.getCompositePoLines().get(0);
    FundDistribution fundDistribution1 = line.getFundDistribution().get(0);
    String fiscalYearId = UUID.randomUUID().toString();
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(line).withFundDistribution(fundDistribution1).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
    FundDistribution fundDistribution2 = line.getFundDistribution().get(1);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(order.getCompositePoLines().get(0)).withFundDistribution(fundDistribution2).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
    FundDistribution fundDistribution3 = line.getFundDistribution().get(1);
    ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(order.getCompositePoLines().get(0)).withFundDistribution(fundDistribution3).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
    List<LedgerFiscalYearRolloverProgress> progresses = Collections.singletonList(success);
    List<ReEncumbranceHolder> holders = List.of(holder1, holder2, holder3);
    // LedgerFiscalYearRolloverErrorCollection is not empty. Expected "needReEncumber" = true
    doReturn(holders).when(spyReEncumbranceHoldersBuilder).buildReEncumbranceHoldersWithOrdersData(any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withFundsData(any(), any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withCurrentFiscalYearData(any(), any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withRollovers(any(), any());
    doReturn(completedFuture(progresses)).when(rolloverRetrieveService).getRolloversProgress(anyString(), any());
    doReturn(completedFuture(ledgerFiscalYearRolloverErrors)).when(rolloverErrorService).getLedgerFyRolloverErrors(any(), any());
    CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order);
    CompositePurchaseOrder compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
    assertTrue(compOrder.getNeedReEncumber());
    // LedgerFiscalYearRolloverErrorCollection is empty. Expected "needReEncumber" = false
    doReturn(completedFuture(new LedgerFiscalYearRolloverErrorCollection())).when(rolloverErrorService).getLedgerFyRolloverErrors(any(), any());
    compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
    assertFalse(compOrder.getNeedReEncumber());
    // LedgerFyRollover not exists. Expected "needReEncumber" = false
    doReturn(completedFuture(new LedgerFiscalYearRolloverCollection())).when(rolloverRetrieveService).getLedgerFyRollovers(anyString(), anyString(), any());
    compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
    assertFalse(compOrder.getNeedReEncumber());
}
Also used : LedgerFiscalYearRolloverErrorCollection(org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverErrorCollection) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) LedgerFiscalYearRolloverCollection(org.folio.rest.jaxrs.model.LedgerFiscalYearRolloverCollection) LedgerFiscalYearRolloverProgress(org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverProgress) LedgerFiscalYearRolloverError(org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverError) Test(org.junit.jupiter.api.Test)

Aggregations

CompositeOrderRetrieveHolder (org.folio.models.CompositeOrderRetrieveHolder)1 ReEncumbranceHolder (org.folio.models.ReEncumbranceHolder)1 Fund (org.folio.rest.acq.model.finance.Fund)1 LedgerFiscalYearRolloverError (org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverError)1 LedgerFiscalYearRolloverErrorCollection (org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverErrorCollection)1 LedgerFiscalYearRolloverProgress (org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverProgress)1 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)1 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)1 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)1 LedgerFiscalYearRollover (org.folio.rest.jaxrs.model.LedgerFiscalYearRollover)1 LedgerFiscalYearRolloverCollection (org.folio.rest.jaxrs.model.LedgerFiscalYearRolloverCollection)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1