use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupGetTransactions.
private void setupGetTransactions(Invoice invoice) throws IOException {
TransactionCollection creditCollection = getMockAs(MOCK_CREDITS_LIST, TransactionCollection.class);
TransactionCollection encumbranceCollection = getMockAs(MOCK_ENCUMBRANCES_LIST, TransactionCollection.class);
TransactionCollection paymentCollection = getMockAs(MOCK_PAYMENTS_LIST, TransactionCollection.class);
TransactionCollection pendingPaymentCollection = getMockAs(MOCK_PENDING_PAYMENTS_LIST, TransactionCollection.class);
TransactionCollection trCollection = mergeCollections(List.of(creditCollection, encumbranceCollection, paymentCollection, pendingPaymentCollection));
String query = String.format("sourceInvoiceId==%s", invoice.getId());
RequestEntry requestEntry = new RequestEntry(TRANSACTIONS_ENDPOINT).withQuery(query).withLimit(Integer.MAX_VALUE).withOffset(0);
doReturn(completedFuture(trCollection)).when(restClient).get(argThat(re -> sameRequestEntry(requestEntry, re)), eq(requestContextMock), eq(TransactionCollection.class));
}
use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupOrderQuery.
private void setupOrderQuery(List<PurchaseOrder> orders) {
List<String> orderIds = orders.stream().map(PurchaseOrder::getId).collect(toList());
List<PurchaseOrder> openOrders = List.of(orders.get(1));
String orderIdsQuery = String.join(" or ", orderIds);
String orderQuery = "workflowStatus==\"Open\" AND id==(" + orderIdsQuery + ")";
PurchaseOrderCollection orderCollection = new PurchaseOrderCollection().withPurchaseOrders(openOrders).withTotalRecords(openOrders.size());
RequestEntry requestEntry = new RequestEntry("/orders/composite-orders").withQuery(orderQuery).withOffset(0).withLimit(Integer.MAX_VALUE);
doReturn(completedFuture(orderCollection)).when(restClient).get(argThat(re -> sameRequestEntry(requestEntry, re)), eq(requestContextMock), eq(PurchaseOrderCollection.class));
}
use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupUpdateVoucher.
private void setupUpdateVoucher(Invoice invoice) throws IOException {
// GET Voucher
Voucher voucher = getMockAs(VOUCHER_SAMPLE_PATH, Voucher.class);
VoucherCollection voucherCollection = new VoucherCollection().withVouchers(singletonList(voucher)).withTotalRecords(1);
RequestEntry getRequestEntry = new RequestEntry(VOUCHER_ENDPOINT).withQuery(String.format("invoiceId==%s", invoice.getId())).withLimit(1).withOffset(0);
doReturn(completedFuture(voucherCollection)).when(restClient).get(argThat(re -> sameRequestEntry(getRequestEntry, re)), eq(requestContextMock), eq(VoucherCollection.class));
// PUT Voucher
RequestEntry putRequestEntry = new RequestEntry(VOUCHER_BY_ID_ENDPOINT).withId(voucher.getId());
doReturn(completedFuture(null)).when(restClient).put(argThat(re -> sameRequestEntry(putRequestEntry, re)), any(Voucher.class), eq(requestContextMock));
}
use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupUpdateTransactionSummary.
private void setupUpdateTransactionSummary(Invoice invoice) {
RequestEntry requestEntry = new RequestEntry(INVOICE_TRANSACTION_SUMMARIES_BY_ID_ENDPOINT).withPathParameter("id", invoice.getId());
InvoiceTransactionSummary summary = new InvoiceTransactionSummary().withId(invoice.getId()).withNumPaymentsCredits(3).withNumPendingPayments(1);
doReturn(completedFuture(null)).when(restClient).put(argThat(re -> sameRequestEntry(requestEntry, re)), eq(summary), eq(requestContextMock));
}
use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class BudgetExpenseClassTest method shouldThrowExceptionWithBudgetExpenseClassNotFoundCodeWhenCheckExpenseClassesWithoutExpenseClasses.
@Test
void shouldThrowExceptionWithBudgetExpenseClassNotFoundCodeWhenCheckExpenseClassesWithoutExpenseClasses() {
String notAssignedExpenseClassId = UUID.randomUUID().toString();
String activeExpenseClassId = UUID.randomUUID().toString();
FundDistribution fundDistributionWithActiveExpenseClass = new FundDistribution().withFundId(UUID.randomUUID().toString()).withExpenseClassId(activeExpenseClassId);
FundDistribution fundDistributionWithNotAssignedExpenseClass = new FundDistribution().withFundId(UUID.randomUUID().toString()).withExpenseClassId(notAssignedExpenseClassId);
FundDistribution fundDistributionWithoutExpenseClass = new FundDistribution().withFundId(UUID.randomUUID().toString());
InvoiceLine invoiceLine = new InvoiceLine().withFundDistributions(Arrays.asList(fundDistributionWithActiveExpenseClass, fundDistributionWithoutExpenseClass));
List<InvoiceLine> invoiceLines = Collections.singletonList(invoiceLine);
Adjustment adjustment = new Adjustment().withFundDistributions(Collections.singletonList(fundDistributionWithNotAssignedExpenseClass));
Invoice invoice = new Invoice().withAdjustments(Collections.singletonList(adjustment));
BudgetExpenseClass active = new BudgetExpenseClass().withBudgetId(UUID.randomUUID().toString()).withExpenseClassId(activeExpenseClassId).withStatus(BudgetExpenseClass.Status.ACTIVE).withId(UUID.randomUUID().toString());
Fund noExpenseClassFund = new Fund().withCode("no expense class fund");
ExpenseClass notAssignedExpenseClass = new ExpenseClass().withName("not assigned class");
List<InvoiceWorkflowDataHolder> holders = new ArrayList<>();
InvoiceWorkflowDataHolder holder1 = new InvoiceWorkflowDataHolder().withInvoice(invoice).withInvoiceLine(invoiceLine).withFundDistribution(fundDistributionWithActiveExpenseClass).withBudget(new Budget().withFundId(UUID.randomUUID().toString())).withExpenseClass(new ExpenseClass().withId(activeExpenseClassId));
InvoiceWorkflowDataHolder holder2 = new InvoiceWorkflowDataHolder().withInvoice(invoice).withInvoiceLine(invoiceLine).withBudget(new Budget().withFundId(UUID.randomUUID().toString())).withFundDistribution(fundDistributionWithoutExpenseClass);
InvoiceWorkflowDataHolder holder3 = new InvoiceWorkflowDataHolder().withInvoice(invoice).withAdjustment(adjustment).withFundDistribution(fundDistributionWithNotAssignedExpenseClass).withExpenseClass(notAssignedExpenseClass).withBudget(new Budget().withFundId(UUID.randomUUID().toString())).withFund(noExpenseClassFund);
holders.add(holder1);
holders.add(holder2);
holders.add(holder3);
when(restClient.get(any(RequestEntry.class), any(), any())).thenAnswer(invocation -> {
RequestEntry requestEntry = invocation.getArgument(0);
List<BudgetExpenseClass> budgetExpenseClasses = requestEntry.buildEndpoint().contains(notAssignedExpenseClassId) ? Collections.emptyList() : Collections.singletonList(active);
return CompletableFuture.completedFuture(new BudgetExpenseClassCollection().withBudgetExpenseClasses(budgetExpenseClasses).withTotalRecords(1));
});
when(requestContext.getContext()).thenReturn(Vertx.vertx().getOrCreateContext());
CompletableFuture<List<InvoiceWorkflowDataHolder>> future = budgetExpenseClassService.checkExpenseClasses(holders, requestContext);
ExecutionException executionException = assertThrows(ExecutionException.class, future::get);
assertThat(executionException.getCause(), instanceOf(HttpException.class));
HttpException exception = (HttpException) executionException.getCause();
assertEquals(400, exception.getCode());
Errors errors = exception.getErrors();
Error error = errors.getErrors().get(0);
assertEquals(BUDGET_EXPENSE_CLASS_NOT_FOUND.getCode(), error.getCode());
String expenseClassNameFromError = error.getParameters().stream().filter(parameter -> parameter.getKey().equals(EXPENSE_CLASS_NAME)).findFirst().get().getValue();
assertEquals(notAssignedExpenseClass.getName(), expenseClassNameFromError);
String fundCodeFromError = error.getParameters().stream().filter(parameter -> parameter.getKey().equals(FUND_CODE)).findFirst().get().getValue();
assertEquals(noExpenseClassFund.getCode(), fundCodeFromError);
}
Aggregations