Search in sources :

Example 1 with VoucherCollection

use of org.folio.rest.jaxrs.model.VoucherCollection 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));
}
Also used : VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) INVOICE_MOCK_DATA_PATH(org.folio.TestMockDataConstants.INVOICE_MOCK_DATA_PATH) BeforeEach(org.junit.jupiter.api.BeforeEach) TransactionType(org.folio.rest.acq.model.finance.Transaction.TransactionType) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) PurchaseOrder(org.folio.rest.acq.model.orders.PurchaseOrder) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) PoLine(org.folio.rest.acq.model.orders.PoLine) OrderLineService(org.folio.services.order.OrderLineService) VOUCHERS_STORAGE(org.folio.invoices.utils.ResourcePathResolver.VOUCHERS_STORAGE) INVOICE_TRANSACTION_SUMMARIES(org.folio.invoices.utils.ResourcePathResolver.INVOICE_TRANSACTION_SUMMARIES) Mockito.argThat(org.mockito.Mockito.argThat) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) MOCK_CREDITS_LIST(org.folio.TestMockDataConstants.MOCK_CREDITS_LIST) Collections.singletonList(java.util.Collections.singletonList) VOUCHER_MOCK_DATA_PATH(org.folio.TestMockDataConstants.VOUCHER_MOCK_DATA_PATH) HttpException(org.folio.invoices.rest.exceptions.HttpException) Voucher(org.folio.rest.jaxrs.model.Voucher) InvoiceTransactionSummaryService(org.folio.services.finance.transaction.InvoiceTransactionSummaryService) VoucherCommandService(org.folio.services.voucher.VoucherCommandService) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) InvoiceTransactionSummary(org.folio.rest.acq.model.finance.InvoiceTransactionSummary) JsonObject(io.vertx.core.json.JsonObject) Method(java.lang.reflect.Method) ERROR_UNRELEASING_ENCUMBRANCES(org.folio.invoices.utils.ErrorCodes.ERROR_UNRELEASING_ENCUMBRANCES) Mockito.doReturn(org.mockito.Mockito.doReturn) RELEASED(org.folio.rest.acq.model.finance.Encumbrance.Status.RELEASED) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) ORDER_TRANSACTION_SUMMARIES(org.folio.invoices.utils.ResourcePathResolver.ORDER_TRANSACTION_SUMMARIES) CompletionException(java.util.concurrent.CompletionException) MOCK_ENCUMBRANCES_LIST(org.folio.TestMockDataConstants.MOCK_ENCUMBRANCES_LIST) UUID(java.util.UUID) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) CompletableFuture.failedFuture(java.util.concurrent.CompletableFuture.failedFuture) List(java.util.List) FINANCE_TRANSACTIONS(org.folio.invoices.utils.ResourcePathResolver.FINANCE_TRANSACTIONS) PENDING(org.folio.rest.acq.model.finance.Encumbrance.Status.PENDING) PurchaseOrderCollection(org.folio.rest.acq.model.orders.PurchaseOrderCollection) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UNRELEASED(org.folio.rest.acq.model.finance.Encumbrance.Status.UNRELEASED) WorkflowStatus(org.folio.rest.acq.model.orders.PurchaseOrder.WorkflowStatus) Invoice(org.folio.rest.jaxrs.model.Invoice) MOCK_PAYMENTS_LIST(org.folio.TestMockDataConstants.MOCK_PAYMENTS_LIST) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RestClient(org.folio.rest.core.RestClient) EncumbranceService(org.folio.services.finance.transaction.EncumbranceService) CANNOT_CANCEL_INVOICE(org.folio.invoices.utils.ErrorCodes.CANNOT_CANCEL_INVOICE) PoLineCollection(org.folio.rest.acq.model.orders.PoLineCollection) CompletableFuture(java.util.concurrent.CompletableFuture) Transaction(org.folio.rest.acq.model.finance.Transaction) VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) InvoiceLineCollection(org.folio.rest.jaxrs.model.InvoiceLineCollection) Answer(org.mockito.stubbing.Answer) OrderTransactionSummary(org.folio.rest.acq.model.finance.OrderTransactionSummary) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RequestContext(org.folio.rest.core.models.RequestContext) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) BaseTransactionService(org.folio.services.finance.transaction.BaseTransactionService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MOCK_PENDING_PAYMENTS_LIST(org.folio.TestMockDataConstants.MOCK_PENDING_PAYMENTS_LIST) OrderService(org.folio.services.order.OrderService) ResourcePathResolver.resourcesPath(org.folio.invoices.utils.ResourcePathResolver.resourcesPath) Files(java.nio.file.Files) VoucherRetrieveService(org.folio.services.voucher.VoucherRetrieveService) Vertx(io.vertx.core.Vertx) RequestEntry(org.folio.rest.core.models.RequestEntry) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) Paths(java.nio.file.Paths) INVOICE_LINES_LIST_PATH(org.folio.TestMockDataConstants.INVOICE_LINES_LIST_PATH) OrderTransactionSummaryService(org.folio.services.finance.transaction.OrderTransactionSummaryService) RequestEntry(org.folio.rest.core.models.RequestEntry) Voucher(org.folio.rest.jaxrs.model.Voucher)

Example 2 with VoucherCollection

use of org.folio.rest.jaxrs.model.VoucherCollection in project mod-invoice by folio-org.

the class MockServer method handleGetVouchers.

private void handleGetVouchers(RoutingContext ctx) {
    logger.info("handleGetVoucher got: {}?{}", ctx.request().path(), ctx.request().query());
    String queryParam = StringUtils.trimToEmpty(ctx.request().getParam(QUERY));
    String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
    String invoiceId = EMPTY;
    if (queryParam.contains(INVOICE_ID)) {
        invoiceId = queryParam.split(INVOICE_ID + "==")[1];
    }
    if (EXCEPTION_CASE_BATCH_VOUCHER_EXPORT_GENERATION.equals(queryParam)) {
        VoucherCollection voucherCollection = new VoucherCollection();
        voucherCollection.withVouchers(new ArrayList<>());
        JsonObject vouchersJson = JsonObject.mapFrom(voucherCollection);
        addServerRqRsData(HttpMethod.GET, VOUCHERS_STORAGE, vouchersJson);
        serverResponse(ctx, 200, APPLICATION_JSON, vouchersJson.encode());
        return;
    }
    if (queryParam.contains("batchGroupId") && queryParam.contains("voucherDate")) {
        invoiceId = "c0d08448-347b-418a-8c2f-5fb50248d67e";
    }
    if (queryParam.contains(BAD_QUERY)) {
        serverResponse(ctx, 400, APPLICATION_JSON, Response.Status.BAD_REQUEST.getReasonPhrase());
    } else if (queryParam.contains(ID_FOR_INTERNAL_SERVER_ERROR) || GET_VOUCHERS_ERROR_TENANT.equals(tenant)) {
        serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else {
        Supplier<List<Voucher>> getFromFile = () -> {
            try {
                return new JsonObject(getMockData(VOUCHERS_LIST_PATH)).mapTo(VoucherCollection.class).getVouchers();
            } catch (IOException e) {
                return Collections.emptyList();
            }
        };
        VoucherCollection voucherCollection = new VoucherCollection();
        List<Voucher> vouchers = getMockEntries(VOUCHERS_STORAGE, Voucher.class).orElseGet(getFromFile);
        Function<Voucher, String> invoiceIdGetter = Voucher::getInvoiceId;
        voucherCollection.setVouchers(filterEntriesByStringValue(invoiceId, vouchers, invoiceIdGetter));
        voucherCollection.setTotalRecords(voucherCollection.getVouchers().size());
        JsonObject vouchersJson = JsonObject.mapFrom(voucherCollection);
        logger.info(vouchersJson.encodePrettily());
        addServerRqRsData(HttpMethod.GET, VOUCHERS_STORAGE, vouchersJson);
        serverResponse(ctx, 200, APPLICATION_JSON, vouchersJson.encode());
    }
}
Also used : VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) Function(java.util.function.Function) JsonObject(io.vertx.core.json.JsonObject) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) IOException(java.io.IOException) Voucher(org.folio.rest.jaxrs.model.Voucher) BatchVoucher(org.folio.rest.jaxrs.model.BatchVoucher)

Example 3 with VoucherCollection

use of org.folio.rest.jaxrs.model.VoucherCollection in project mod-invoice by folio-org.

the class VouchersApiTest method testGetVoucherVouchers.

@Test
public void testGetVoucherVouchers() {
    logger.info("=== Test Get Vouchers by without query - get 200 by successful retrieval of vouchers ===");
    final VoucherCollection resp = verifySuccessGet(VOUCHER_PATH, VoucherCollection.class);
    assertEquals(2, resp.getTotalRecords().intValue());
}
Also used : VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) Test(org.junit.jupiter.api.Test)

Example 4 with VoucherCollection

use of org.folio.rest.jaxrs.model.VoucherCollection in project mod-invoice by folio-org.

the class VouchersApiTest method testGetVoucherVouchersWithQueryParam.

@Test
public void testGetVoucherVouchersWithQueryParam() {
    logger.info("=== Test Get Vouchers with query - get 200 by successful retrieval of vouchers by query ===");
    String endpointQuery = String.format("%s?query=%s==%s", VOUCHER_PATH, INVOICE_ID, APPROVED_INVOICE_ID);
    final VoucherCollection resp = verifySuccessGet(endpointQuery, VoucherCollection.class);
    assertEquals(1, resp.getTotalRecords().intValue());
}
Also used : VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) Test(org.junit.jupiter.api.Test)

Example 5 with VoucherCollection

use of org.folio.rest.jaxrs.model.VoucherCollection in project mod-invoice by folio-org.

the class InvoiceLinesRetrieveServiceTest method positiveGetInvoiceMapTest.

@Test
public void positiveGetInvoiceMapTest() throws IOException, ExecutionException, InterruptedException {
    RestClient restClient = new RestClient();
    InvoiceLinesRetrieveService service = new InvoiceLinesRetrieveService(new InvoiceLineService(restClient));
    JsonObject vouchersList = new JsonObject(getMockData(VOUCHERS_LIST_PATH));
    List<Voucher> vouchers = vouchersList.getJsonArray("vouchers").stream().map(obj -> ((JsonObject) obj).mapTo(Voucher.class)).collect(toList());
    vouchers.remove(1);
    VoucherCollection voucherCollection = new VoucherCollection();
    voucherCollection.setVouchers(vouchers);
    CompletableFuture<Map<String, List<InvoiceLine>>> future = service.getInvoiceLineMap(voucherCollection, new RequestContext(context, okapiHeaders));
    Map<String, List<InvoiceLine>> listMap = future.get();
    Assertions.assertEquals(1, listMap.values().size());
}
Also used : RestClient(org.folio.rest.core.RestClient) BeforeEach(org.junit.jupiter.api.BeforeEach) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Vertx(io.vertx.core.Vertx) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) ApiTestSuite.mockPort(org.folio.ApiTestSuite.mockPort) Context(io.vertx.core.Context) ApiTestBase(org.folio.rest.impl.ApiTestBase) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) InvoiceLineCollection(org.folio.rest.jaxrs.model.InvoiceLineCollection) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Voucher(org.folio.rest.jaxrs.model.Voucher) Map(java.util.Map) RequestContext(org.folio.rest.core.models.RequestContext) Assertions(org.junit.jupiter.api.Assertions) InvoiceLineService(org.folio.services.invoice.InvoiceLineService) JsonObject(io.vertx.core.json.JsonObject) OKAPI_URL(org.folio.rest.RestConstants.OKAPI_URL) VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) RestClient(org.folio.rest.core.RestClient) JsonObject(io.vertx.core.json.JsonObject) Voucher(org.folio.rest.jaxrs.model.Voucher) InvoiceLineService(org.folio.services.invoice.InvoiceLineService) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) RequestContext(org.folio.rest.core.models.RequestContext) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

VoucherCollection (org.folio.rest.jaxrs.model.VoucherCollection)6 JsonObject (io.vertx.core.json.JsonObject)5 IOException (java.io.IOException)5 List (java.util.List)5 Collectors.toList (java.util.stream.Collectors.toList)5 Test (org.junit.jupiter.api.Test)5 Vertx (io.vertx.core.Vertx)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Voucher (org.folio.rest.jaxrs.model.Voucher)4 Context (io.vertx.core.Context)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 ApiTestSuite.mockPort (org.folio.ApiTestSuite.mockPort)3 OKAPI_URL (org.folio.rest.RestConstants.OKAPI_URL)3 ApiTestBase (org.folio.rest.impl.ApiTestBase)3 Assertions (org.junit.jupiter.api.Assertions)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 RestClient (org.folio.rest.core.RestClient)2 RequestContext (org.folio.rest.core.models.RequestContext)2