Search in sources :

Example 6 with CompositeOrderRetrieveHolder

use of org.folio.models.CompositeOrderRetrieveHolder in project mod-orders by folio-org.

the class CompositeOrderRetrieveHolderBuilderTest method shouldNotPopulateFiscalYearWhenThereAreNoFundDistributions.

@Test
void shouldNotPopulateFiscalYearWhenThereAreNoFundDistributions() {
    CompositePurchaseOrder order = new CompositePurchaseOrder().withId(UUID.randomUUID().toString());
    CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order);
    CompositeOrderRetrieveHolder resultHolder = holderBuilder.withCurrentFiscalYear(holder, requestContext).join();
    assertNull(resultHolder.getFiscalYear());
}
Also used : CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) Test(org.junit.jupiter.api.Test)

Example 7 with CompositeOrderRetrieveHolder

use of org.folio.models.CompositeOrderRetrieveHolder 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 8 with CompositeOrderRetrieveHolder

use of org.folio.models.CompositeOrderRetrieveHolder in project mod-orders by folio-org.

the class TransactionsTotalFieldsPopulateServiceTest method shouldPopulateTotalEncumberedFieldWithZeroWhenFiscalYearIsEmpty.

@Test
void shouldPopulateTotalEncumberedFieldWithZeroWhenFiscalYearIsEmpty() {
    CompositePurchaseOrder order = new CompositePurchaseOrder().withId(UUID.randomUUID().toString());
    CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order);
    CompositeOrderRetrieveHolder resultHolder = populateService.populate(holder, requestContext).join();
    assertEquals(0d, resultHolder.getOrder().getTotalExpended());
    assertEquals(0d, resultHolder.getOrder().getTotalEncumbered());
}
Also used : CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) Test(org.junit.jupiter.api.Test)

Example 9 with CompositeOrderRetrieveHolder

use of org.folio.models.CompositeOrderRetrieveHolder in project mod-orders by folio-org.

the class TransactionsTotalFieldsPopulateServiceTest method shouldPopulateTotalEncumberedFieldWithSumOfEncumbrancesAmount.

@Test
void shouldPopulateTotalEncumberedFieldWithSumOfEncumbrancesAmount() {
    Transaction transaction1 = new Transaction().withId(UUID.randomUUID().toString());
    Transaction transaction2 = new Transaction().withId(UUID.randomUUID().toString());
    CompositePurchaseOrder order = new CompositePurchaseOrder().withId(UUID.randomUUID().toString());
    CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order).withFiscalYear(new FiscalYear().withId(UUID.randomUUID().toString()));
    Transaction paidEncumbrance = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withPaymentEncumbranceId(transaction1.getId()).withAmount(14.11d).withCurrency("USD").withEncumbrance(new Encumbrance().withAmountExpended(13.45));
    Transaction notPaidEncumbrance = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withPaymentEncumbranceId(transaction2.getId()).withAmount(13.43d).withCurrency("USD").withEncumbrance(new Encumbrance().withAmountExpended(0d));
    List<Transaction> transactions = List.of(paidEncumbrance, notPaidEncumbrance);
    TransactionCollection transactionCollection = new TransactionCollection().withTransactions(transactions);
    when(transactionService.getTransactions(anyString(), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(transactionCollection));
    CompositeOrderRetrieveHolder resultHolder = populateService.populate(holder, requestContext).join();
    assertEquals(27.54, resultHolder.getOrder().getTotalEncumbered());
    assertEquals(13.45, resultHolder.getOrder().getTotalExpended());
}
Also used : TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) Test(org.junit.jupiter.api.Test)

Aggregations

CompositeOrderRetrieveHolder (org.folio.models.CompositeOrderRetrieveHolder)9 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)9 Test (org.junit.jupiter.api.Test)8 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)3 HttpException (org.folio.rest.core.exceptions.HttpException)2 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)2 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1