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());
}
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))));
}
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))));
}
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))));
}
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)));
}
Aggregations