use of org.folio.rest.acq.model.finance.FiscalYear in project mod-orders by folio-org.
the class CompositeOrderRetrieveHolderBuilderTest method shouldFailWhenWhenRetrieveFiscalYearReturnsDifferentFrom404Status.
@Test
void shouldFailWhenWhenRetrieveFiscalYearReturnsDifferentFrom404Status() {
FundDistribution fundDistribution = new FundDistribution().withFundId(UUID.randomUUID().toString());
CompositePoLine poLine = new CompositePoLine().withFundDistribution(List.of(fundDistribution));
CompositePurchaseOrder order = new CompositePurchaseOrder().withId(UUID.randomUUID().toString()).withCompositePoLines(Collections.singletonList(poLine));
CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order);
CompletableFuture<FiscalYear> failedFuture = new CompletableFuture<>();
HttpException thrownException = new HttpException(500, ErrorCodes.GENERIC_ERROR_CODE);
failedFuture.completeExceptionally(thrownException);
when(fiscalYearService.getCurrentFiscalYearByFundId(anyString(), any())).thenReturn(failedFuture);
CompletionException exception = assertThrows(CompletionException.class, () -> holderBuilder.withCurrentFiscalYear(holder, requestContext).join());
assertEquals(thrownException, exception.getCause());
}
use of org.folio.rest.acq.model.finance.FiscalYear in project mod-orders by folio-org.
the class CompositeOrderRetrieveHolderBuilderTest method shouldNotFailWhenRetrieveFiscalYearReturns404Status.
@Test
void shouldNotFailWhenRetrieveFiscalYearReturns404Status() {
FundDistribution fundDistribution = new FundDistribution().withFundId(UUID.randomUUID().toString());
CompositePoLine poLine = new CompositePoLine().withFundDistribution(List.of(fundDistribution));
CompositePurchaseOrder order = new CompositePurchaseOrder().withId(UUID.randomUUID().toString()).withCompositePoLines(Collections.singletonList(poLine));
CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order);
CompletableFuture<FiscalYear> failedFuture = new CompletableFuture<>();
failedFuture.completeExceptionally(new HttpException(404, ErrorCodes.CURRENT_FISCAL_YEAR_NOT_FOUND));
when(fiscalYearService.getCurrentFiscalYearByFundId(anyString(), any())).thenReturn(failedFuture);
CompositeOrderRetrieveHolder resultHolder = holderBuilder.withCurrentFiscalYear(holder, requestContext).join();
assertNull(resultHolder.getFiscalYear());
}
use of org.folio.rest.acq.model.finance.FiscalYear in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithConversionWhenHoldersContainsCurrency.
@Test
void shouldPopulateReEncumbranceHoldersWithConversionWhenHoldersContainsCurrency() {
FiscalYear fiscalYear = new FiscalYear().withCurrency("USD");
CompositePoLine line1 = new CompositePoLine().withCost(new Cost().withCurrency("EUR"));
CompositePoLine line2 = new CompositePoLine().withCost(new Cost().withCurrency("EUR"));
double exchangeEurToUsdRate = 1.1d;
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withCurrency(fiscalYear.getCurrency()).withPoLine(line1);
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withCurrency(fiscalYear.getCurrency()).withPoLine(line2);
CurrencyConversion poLineToFyConversion = mock(ManualCurrencyConversion.class, withSettings().name("poLineToFyConversion"));
CurrencyConversion poFyToPoLineConversion = mock(ManualCurrencyConversion.class, withSettings().name("poFyToPoLineConversion"));
ExchangeRate exchangeRate = mock(ExchangeRate.class);
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
when(exchangeRateProviderResolver.resolve(any(), any())).thenReturn(exchangeRateProvider);
when(exchangeRateProvider.getCurrencyConversion(any(ConversionQuery.class))).thenReturn(poLineToFyConversion, poFyToPoLineConversion);
when(exchangeRate.getFactor()).thenReturn(new DefaultNumberValue(exchangeEurToUsdRate));
when(poLineToFyConversion.getCurrency()).thenReturn(Monetary.getCurrency("EUR"));
when(poLineToFyConversion.getExchangeRate(any())).thenReturn(exchangeRate);
when(poFyToPoLineConversion.getCurrency()).thenReturn(Monetary.getCurrency("USD"));
when(requestContext.getContext()).thenReturn(Vertx.vertx().getOrCreateContext());
List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withConversions(holders, requestContext).join();
assertEquals(resultHolders.get(0).getPoLineToFyConversion().getCurrency(), poLineToFyConversion.getCurrency());
assertEquals(resultHolders.get(1).getPoLineToFyConversion().getCurrency(), poLineToFyConversion.getCurrency());
assertEquals(resultHolders.get(0).getFyToPoLineConversion().getCurrency(), poFyToPoLineConversion.getCurrency());
assertEquals(resultHolders.get(1).getFyToPoLineConversion().getCurrency(), poFyToPoLineConversion.getCurrency());
}
use of org.folio.rest.acq.model.finance.FiscalYear in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldPopulateEachReEncumbranceHolderWithFiscalYearIfFundExist.
@Test
void shouldPopulateEachReEncumbranceHolderWithFiscalYearIfFundExist() {
Fund fund1 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
Fund fund2 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId());
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId());
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
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()))));
}
use of org.folio.rest.acq.model.finance.FiscalYear in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithCorrespondingRollover.
@Test
void shouldPopulateReEncumbranceHoldersWithCorrespondingRollover() {
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());
FiscalYear currentFiscalYear = new FiscalYear().withId(UUID.randomUUID().toString());
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withLedgerId(fund3.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
ReEncumbranceHolder holder4 = new ReEncumbranceHolder().withLedgerId(fund4.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3, holder4);
LedgerFiscalYearRollover rollover1 = new LedgerFiscalYearRollover().withLedgerId(ledgerId1);
LedgerFiscalYearRollover rollover2 = new LedgerFiscalYearRollover().withLedgerId(ledgerId2);
when(rolloverRetrieveService.getLedgerFyRollovers(anyString(), anyList(), any())).thenReturn(CompletableFuture.completedFuture(Arrays.asList(rollover1, rollover2)));
List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withRollovers(holders, requestContext).join();
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", is(rollover1)), hasProperty("ledgerId", is(fund1.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", is(rollover2)), hasProperty("ledgerId", is(fund2.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", is(rollover2)), hasProperty("ledgerId", is(fund3.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund4.getLedgerId())))));
}
Aggregations