use of org.folio.rest.core.RestClient 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.core.RestClient 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.core.RestClient 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.RestClient 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.RestClient 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));
}
Aggregations