use of org.folio.rest.acq.model.finance.Transaction in project mod-invoice by folio-org.
the class BaseTransactionServiceTest method testShouldSuccessRetrieveExistedTransactions.
@Test
public void testShouldSuccessRetrieveExistedTransactions() throws Exception {
// given
BaseTransactionService service = spy(new BaseTransactionService(restClient));
JsonObject encumbranceList = new JsonObject(getMockData(MOCK_ENCUMBRANCES_LIST));
List<Transaction> encumbrances = encumbranceList.getJsonArray("transactions").stream().map(obj -> ((JsonObject) obj).mapTo(Transaction.class)).collect(toList());
TransactionCollection trCollection = new TransactionCollection().withTransactions(encumbrances);
RequestContext requestContext = new RequestContext(ctxMock, okapiHeaders);
doReturn(completedFuture(trCollection)).when(restClient).get(any(RequestEntry.class), any(RequestContext.class), eq(TransactionCollection.class));
// When
List<String> transactionIds = encumbrances.stream().map(Transaction::getId).collect(toList());
List<Transaction> actEncumbrances = service.getTransactions(transactionIds, requestContext).join();
// Then
assertThat(actEncumbrances, hasSize(1));
assertThat(actEncumbrances.get(0).getId(), equalTo(encumbrances.get(0).getId()));
verify(restClient).get(any(RequestEntry.class), any(RequestContext.class), eq(TransactionCollection.class));
}
use of org.folio.rest.acq.model.finance.Transaction in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupEncumbrancePut.
private void setupEncumbrancePut(Transaction transaction) {
RequestEntry requestEntry = new RequestEntry("/finance/encumbrances/{id}").withPathParameter("id", transaction.getId());
Transaction updatedTransaction = JsonObject.mapFrom(transaction).mapTo(Transaction.class);
updatedTransaction.getEncumbrance().setStatus(UNRELEASED);
doReturn(completedFuture(null)).when(restClient).put(argThat(re -> sameRequestEntry(requestEntry, re)), eq(updatedTransaction), eq(requestContextMock));
}
use of org.folio.rest.acq.model.finance.Transaction in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupUnreleaseEncumbrances.
private void setupUnreleaseEncumbrances(boolean withError) {
String orderId1 = UUID.randomUUID().toString();
String orderId2 = UUID.randomUUID().toString();
List<PurchaseOrder> orders = List.of(new PurchaseOrder().withId(orderId1).withWorkflowStatus(WorkflowStatus.PENDING), new PurchaseOrder().withId(orderId2).withWorkflowStatus(WorkflowStatus.OPEN));
List<PoLine> poLines = List.of(new PoLine().withId("2bafc9e1-9dd3-4ede-9f23-c4a03f8bb2d5").withPurchaseOrderId(orderId1), new PoLine().withId("5a34ae0e-5a11-4337-be95-1a20cfdc3161").withPurchaseOrderId(orderId2), new PoLine().withId("0610be6d-0ddd-494b-b867-19f63d8b5d6d").withPurchaseOrderId(orderId2));
List<Transaction> transactions = List.of(new Transaction().withId(UUID.randomUUID().toString()).withTransactionType(TransactionType.ENCUMBRANCE).withEncumbrance(new Encumbrance().withStatus(PENDING).withSourcePurchaseOrderId(orderId2)), new Transaction().withId(UUID.randomUUID().toString()).withTransactionType(TransactionType.ENCUMBRANCE).withEncumbrance(new Encumbrance().withStatus(RELEASED).withSourcePurchaseOrderId(orderId2)), new Transaction().withId(UUID.randomUUID().toString()).withTransactionType(TransactionType.ENCUMBRANCE).withEncumbrance(new Encumbrance().withStatus(UNRELEASED).withSourcePurchaseOrderId(orderId2)));
setupPoLineQuery(poLines);
setupOrderQuery(orders);
setupEncumbranceQuery(orders, poLines, transactions);
setupUpdateOrderTransactionSummary(orders.get(1));
if (withError)
setupEncumbrancePutWithError(transactions.get(1));
else
setupEncumbrancePut(transactions.get(1));
}
use of org.folio.rest.acq.model.finance.Transaction in project mod-invoice by folio-org.
the class FundAvailabilityHolderValidatorTest method checkEnoughMoneyInBudgetShouldThrowFundCannotBePaidIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmount.
@Test
void checkEnoughMoneyInBudgetShouldThrowFundCannotBePaidIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmount() {
String fiscalYearId = UUID.randomUUID().toString();
String fundId = UUID.randomUUID().toString();
String budgetId = UUID.randomUUID().toString();
String ledgerId = UUID.randomUUID().toString();
Transaction existingTransaction = new Transaction().withTransactionType(Transaction.TransactionType.PENDING_PAYMENT).withAmount(50d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.PENDING_PAYMENT).withAmount(60d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
Fund fund = new Fund().withId(fundId).withName("TestFund").withLedgerId(ledgerId).withCode("FC").withFundStatus(Fund.FundStatus.ACTIVE);
Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(59d).withTotalFunding(59d).withAvailable(9d).withUnavailable(50d).withAwaitingPayment(50D).withAllowableExpenditure(100d);
List<InvoiceWorkflowDataHolder> holders = new ArrayList<>();
InvoiceWorkflowDataHolder holder = new InvoiceWorkflowDataHolder().withFund(fund).withExistingTransaction(existingTransaction).withNewTransaction(newTransaction).withBudget(budget).withRestrictExpenditures(true).withFiscalYear(new FiscalYear().withId(fiscalYearId).withCurrency("USD"));
holders.add(holder);
HttpException httpException = assertThrows(HttpException.class, () -> fundAvailabilityValidator.validate(holders));
assertEquals(422, httpException.getCode());
Error error = httpException.getErrors().getErrors().get(0);
assertEquals(FUND_CANNOT_BE_PAID.getCode(), error.getCode());
assertEquals(Collections.singletonList("FC").toString(), error.getParameters().get(0).getValue());
}
use of org.folio.rest.acq.model.finance.Transaction in project mod-invoice by folio-org.
the class FundAvailabilityHolderValidatorTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndBudgetAllowableExpenditureIsNull.
@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndBudgetAllowableExpenditureIsNull() {
String fiscalYearId = UUID.randomUUID().toString();
String fundId = UUID.randomUUID().toString();
String budgetId = UUID.randomUUID().toString();
String ledgerId = UUID.randomUUID().toString();
Transaction existingTransaction = new Transaction().withTransactionType(Transaction.TransactionType.PENDING_PAYMENT).withAmount(50d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.PENDING_PAYMENT).withAmount(60d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
Fund fund = new Fund().withId(fundId).withName("TestFund").withLedgerId(ledgerId).withCode("FC").withFundStatus(Fund.FundStatus.ACTIVE);
Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(59d).withTotalFunding(59d).withAvailable(0d).withUnavailable(50d).withAwaitingPayment(50D).withAllowableExpenditure(null);
List<InvoiceWorkflowDataHolder> holders = new ArrayList<>();
InvoiceWorkflowDataHolder holder = new InvoiceWorkflowDataHolder().withFund(fund).withExistingTransaction(existingTransaction).withNewTransaction(newTransaction).withBudget(budget).withRestrictExpenditures(true).withFiscalYear(new FiscalYear().withId(fiscalYearId).withCurrency("USD"));
holders.add(holder);
assertDoesNotThrow(() -> fundAvailabilityValidator.validate(holders));
}
Aggregations