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