use of org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverProgress 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());
}
Aggregations