Search in sources :

Example 6 with FiscalYear

use of org.folio.rest.acq.model.finance.FiscalYear in project mod-orders by folio-org.

the class TransactionsTotalFieldsPopulateServiceTest method shouldPopulateTotalEncumberedAndTotalExpendedFieldsWithZeroWhenTransactionsNotFound.

@Test
void shouldPopulateTotalEncumberedAndTotalExpendedFieldsWithZeroWhenTransactionsNotFound() {
    CompositePurchaseOrder order = new CompositePurchaseOrder().withId(UUID.randomUUID().toString());
    CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order).withFiscalYear(new FiscalYear().withId(UUID.randomUUID().toString()));
    when(transactionService.getTransactions(anyString(), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(new TransactionCollection()));
    CompositeOrderRetrieveHolder resultHolder = populateService.populate(holder, requestContext).join();
    assertEquals(0d, resultHolder.getOrder().getTotalExpended());
}
Also used : TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) Test(org.junit.jupiter.api.Test)

Example 7 with FiscalYear

use of org.folio.rest.acq.model.finance.FiscalYear in project mod-orders by folio-org.

the class MockServer method handleGetCurrentFiscalYearByLedgerId.

private void handleGetCurrentFiscalYearByLedgerId(RoutingContext ctx) {
    logger.info("got: " + ctx.request().path());
    String id = ctx.request().getParam(ID);
    logger.info("id: " + id);
    addServerRqRsData(HttpMethod.GET, PO_LINES_STORAGE, new JsonObject().put(ID, id));
    if (ID_FOR_INTERNAL_SERVER_ERROR.equals(id)) {
        serverResponse(ctx, 500, APPLICATION_JSON, INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else if (ID_DOES_NOT_EXIST.equals(id)) {
        serverResponse(ctx, 404, APPLICATION_JSON, id);
    } else {
        FiscalYear fiscalYear = new FiscalYear();
        fiscalYear.setId(UUID.randomUUID().toString());
        fiscalYear.setCode("test2020");
        fiscalYear.setName("test");
        fiscalYear.setCurrency("USD");
        fiscalYear.setPeriodStart(Date.from(Instant.now().minus(365, DAYS)));
        fiscalYear.setPeriodEnd(Date.from(Instant.now().plus(365, DAYS)));
        serverResponse(ctx, 200, APPLICATION_JSON, JsonObject.mapFrom(fiscalYear).encodePrettily());
    }
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) JsonObject(io.vertx.core.json.JsonObject)

Example 8 with FiscalYear

use of org.folio.rest.acq.model.finance.FiscalYear in project mod-orders by folio-org.

the class EncumbranceRelationsHoldersBuilderTest method testShouldPopulateHoldersWithFiscalYearData.

@Test
void testShouldPopulateHoldersWithFiscalYearData() {
    // given
    String fiscalYearId = UUID.randomUUID().toString();
    FiscalYear fiscalYear = new FiscalYear().withId(fiscalYearId).withCurrency("RUB");
    Budget budget1 = new Budget().withId(UUID.randomUUID().toString()).withFundId(holder1.getFundId()).withFiscalYearId(fiscalYearId);
    Budget budget2 = new Budget().withId(UUID.randomUUID().toString()).withFundId(holder2.getFundId()).withFiscalYearId(fiscalYearId);
    Budget budget3 = new Budget().withId(UUID.randomUUID().toString()).withFundId(holder3.getFundId()).withFiscalYearId(fiscalYearId);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    holders.add(holder1.withBudget(budget1));
    holders.add(holder2.withBudget(budget2));
    holders.add(holder3.withBudget(budget3));
    when(fiscalYearService.getFiscalYearById(anyString(), any())).thenReturn(CompletableFuture.completedFuture(fiscalYear));
    // When
    List<EncumbranceRelationsHolder> resultHolders = encumbranceRelationsHoldersBuilder.withFiscalYearData(holders, requestContextMock).join();
    // Then
    assertThat(resultHolders, everyItem(hasProperty("newEncumbrance", allOf(hasProperty("fiscalYearId", is(fiscalYear.getId())), hasProperty("currency", is(fiscalYear.getCurrency()))))));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Budget(org.folio.rest.acq.model.finance.Budget) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 9 with FiscalYear

use of org.folio.rest.acq.model.finance.FiscalYear in project mod-orders by folio-org.

the class EncumbranceServiceTest method test.

@Test
void test() {
    // Given
    String fundId = "df876cba-eeec-4901-bce7-cc2260b0a536";
    FundDistribution fundDistribution = new FundDistribution();
    fundDistribution.setFundId(fundId);
    FiscalYear fiscalYear = new FiscalYear();
    fiscalYear.setId(UUID.randomUUID().toString());
    CompositePoLine poLine = new CompositePoLine();
    poLine.withFundDistribution(List.of(fundDistribution));
    String orderId = UUID.randomUUID().toString();
    Transaction encumbrance = new Transaction().withId(UUID.randomUUID().toString()).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId));
    Transaction encumbrance2 = new Transaction().withId(UUID.randomUUID().toString()).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId));
    List<Transaction> transactions = new ArrayList<>();
    transactions.add(encumbrance);
    transactions.add(encumbrance2);
    TransactionCollection transactionCollection = new TransactionCollection().withTransactions(transactions).withTotalRecords(1);
    doReturn(completedFuture(fiscalYear)).when(fiscalYearService).getCurrentFiscalYearByFundId(anyString(), eq(requestContextMock));
    doReturn(CompletableFuture.completedFuture(transactionCollection)).when(transactionService).getTransactions(anyString(), anyInt(), anyInt(), eq(requestContextMock));
    // When
    CompletableFuture<List<Transaction>> result = encumbranceService.getPoLineReleasedEncumbrances(poLine, requestContextMock);
    assertFalse(result.isCompletedExceptionally());
    result.join();
    // Then
    verify(transactionService, times(1)).getTransactions(anyString(), anyInt(), anyInt(), eq(requestContextMock));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) 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) ArrayList(java.util.ArrayList) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 10 with FiscalYear

use of org.folio.rest.acq.model.finance.FiscalYear in project mod-orders by folio-org.

the class FiscalYearServiceTest method testShouldThrowHttpException.

@Test
void testShouldThrowHttpException() {
    CompletableFuture<FiscalYear> result = fiscalYearService.getCurrentFiscalYear(ID_DOES_NOT_EXIST, requestContextMock);
    CompletionException expectedException = assertThrows(CompletionException.class, result::join);
    HttpException httpException = (HttpException) expectedException.getCause();
    assertEquals(404, httpException.getCode());
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) CompletionException(java.util.concurrent.CompletionException) HttpException(org.folio.rest.core.exceptions.HttpException) 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