Search in sources :

Example 11 with FiscalYear

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());
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) CompletableFuture(java.util.concurrent.CompletableFuture) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) CompletionException(java.util.concurrent.CompletionException) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) HttpException(org.folio.rest.core.exceptions.HttpException) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) Test(org.junit.jupiter.api.Test)

Example 12 with FiscalYear

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());
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) CompletableFuture(java.util.concurrent.CompletableFuture) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) HttpException(org.folio.rest.core.exceptions.HttpException) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) Test(org.junit.jupiter.api.Test)

Example 13 with FiscalYear

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());
}
Also used : ConversionQuery(javax.money.convert.ConversionQuery) DefaultNumberValue(org.javamoney.moneta.spi.DefaultNumberValue) ExchangeRate(javax.money.convert.ExchangeRate) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ManualCurrencyConversion(org.folio.service.exchange.ManualCurrencyConversion) CurrencyConversion(javax.money.convert.CurrencyConversion) Cost(org.folio.rest.jaxrs.model.Cost) Test(org.junit.jupiter.api.Test)

Example 14 with FiscalYear

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()))));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Test(org.junit.jupiter.api.Test)

Example 15 with FiscalYear

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())))));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Test(org.junit.jupiter.api.Test)

Aggregations

FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)26 Test (org.junit.jupiter.api.Test)22 Fund (org.folio.rest.acq.model.finance.Fund)11 ArrayList (java.util.ArrayList)9 Transaction (org.folio.rest.acq.model.finance.Transaction)9 InvoiceWorkflowDataHolder (org.folio.models.InvoiceWorkflowDataHolder)7 Budget (org.folio.rest.acq.model.finance.Budget)7 HttpException (org.folio.invoices.rest.exceptions.HttpException)4 CompositeOrderRetrieveHolder (org.folio.models.CompositeOrderRetrieveHolder)4 ReEncumbranceHolder (org.folio.models.ReEncumbranceHolder)4 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)4 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)4 Error (org.folio.rest.jaxrs.model.Error)4 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 TransactionCollection (org.folio.rest.acq.model.finance.TransactionCollection)3 HttpException (org.folio.rest.core.exceptions.HttpException)3 JsonObject (io.vertx.core.json.JsonObject)2 LocalDate (java.time.LocalDate)2 Date (java.util.Date)2