Search in sources :

Example 1 with BatchVoucher

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

the class BatchVoucherGenerateServiceTest method positiveGenerateBatchVoucherTest.

@Test
public void positiveGenerateBatchVoucherTest() throws IOException, ExecutionException, InterruptedException {
    RestClient restClient = new RestClient();
    VoucherRetrieveService voucherRetrieveService = new VoucherRetrieveService(restClient);
    ConfigurationService configurationService = new ConfigurationService(new RestClient());
    VoucherCommandService voucherCommandService = new VoucherCommandService(restClient, new VoucherNumberService(new RestClient()), voucherRetrieveService, new VoucherValidator(), configurationService, new ExchangeRateProviderResolver());
    VendorRetrieveService vendorRetrieveService = new VendorRetrieveService(restClient);
    AddressConverter addressConverter = AddressConverter.getInstance();
    VoucherService voucherService = new VoucherService(voucherRetrieveService, voucherCommandService, vendorRetrieveService, addressConverter);
    InvoiceLinesRetrieveService invoiceLinesRetrieveService = new InvoiceLinesRetrieveService(new InvoiceLineService(restClient));
    InvoiceLineService invoiceLineService = new InvoiceLineService(new RestClient());
    OrderLineService orderLineService = new OrderLineService(restClient);
    InvoiceService invoiceService = new BaseInvoiceService(new RestClient(), invoiceLineService, new OrderService(new RestClient(), invoiceLineService, orderLineService));
    InvoiceRetrieveService invoiceRetrieveService = new InvoiceRetrieveService(invoiceService);
    BatchVoucherGenerateService service = new BatchVoucherGenerateService(okapiHeaders, context, "en", vendorRetrieveService, invoiceRetrieveService, invoiceLinesRetrieveService, voucherService, addressConverter);
    BatchVoucherExport batchVoucherExport = new JsonObject(getMockData(BATCH_VOUCHER_EXPORT_SAMPLE_PATH)).mapTo(BatchVoucherExport.class);
    CompletableFuture<BatchVoucher> future = service.generateBatchVoucher(batchVoucherExport, new RequestContext(context, okapiHeaders));
    BatchVoucher batchVoucher = future.get();
    Assertions.assertNotNull(batchVoucher);
}
Also used : VendorRetrieveService(org.folio.services.VendorRetrieveService) RestClient(org.folio.rest.core.RestClient) AddressConverter(org.folio.converters.AddressConverter) InvoiceService(org.folio.services.invoice.InvoiceService) BaseInvoiceService(org.folio.services.invoice.BaseInvoiceService) BaseInvoiceService(org.folio.services.invoice.BaseInvoiceService) JsonObject(io.vertx.core.json.JsonObject) VoucherService(org.folio.rest.impl.VoucherService) ExchangeRateProviderResolver(org.folio.services.exchange.ExchangeRateProviderResolver) InvoiceLinesRetrieveService(org.folio.services.InvoiceLinesRetrieveService) OrderLineService(org.folio.services.order.OrderLineService) VoucherValidator(org.folio.services.validator.VoucherValidator) BatchVoucher(org.folio.rest.jaxrs.model.BatchVoucher) InvoiceLineService(org.folio.services.invoice.InvoiceLineService) ConfigurationService(org.folio.services.configuration.ConfigurationService) RequestContext(org.folio.rest.core.models.RequestContext) OrderService(org.folio.services.order.OrderService) InvoiceRetrieveService(org.folio.services.InvoiceRetrieveService) BatchVoucherExport(org.folio.rest.jaxrs.model.BatchVoucherExport) Test(org.junit.jupiter.api.Test)

Example 2 with BatchVoucher

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

the class BatchVoucherGenerateServiceTest method negativeGetBatchVoucherIfVouchersIsAbsentTest.

@Test
public void negativeGetBatchVoucherIfVouchersIsAbsentTest() {
    Assertions.assertThrows(CompletionException.class, () -> {
        RestClient restClient = new RestClient();
        VoucherRetrieveService voucherRetrieveService = new VoucherRetrieveService(restClient);
        ConfigurationService configurationService = new ConfigurationService(restClient);
        VoucherCommandService voucherCommandService = new VoucherCommandService(restClient, new VoucherNumberService(restClient), voucherRetrieveService, new VoucherValidator(), configurationService, new ExchangeRateProviderResolver());
        VendorRetrieveService vendorRetrieveService = new VendorRetrieveService(restClient);
        AddressConverter addressConverter = AddressConverter.getInstance();
        VoucherService voucherService = new VoucherService(voucherRetrieveService, voucherCommandService, vendorRetrieveService, addressConverter);
        InvoiceLinesRetrieveService invoiceLinesRetrieveService = new InvoiceLinesRetrieveService(new InvoiceLineService(restClient));
        InvoiceLineService invoiceLineService = new InvoiceLineService(new RestClient());
        OrderLineService orderLineService = new OrderLineService(restClient);
        InvoiceService invoiceService = new BaseInvoiceService(new RestClient(), invoiceLineService, new OrderService(new RestClient(), invoiceLineService, orderLineService));
        InvoiceRetrieveService invoiceRetrieveService = new InvoiceRetrieveService(invoiceService);
        BatchVoucherGenerateService service = new BatchVoucherGenerateService(okapiHeaders, context, "en", vendorRetrieveService, invoiceRetrieveService, invoiceLinesRetrieveService, voucherService, addressConverter);
        BatchVoucherExport batchVoucherExport = new BatchVoucherExport();
        CompletableFuture<BatchVoucher> future = service.generateBatchVoucher(batchVoucherExport, new RequestContext(context, okapiHeaders));
        future.join();
    });
}
Also used : VendorRetrieveService(org.folio.services.VendorRetrieveService) RestClient(org.folio.rest.core.RestClient) AddressConverter(org.folio.converters.AddressConverter) InvoiceService(org.folio.services.invoice.InvoiceService) BaseInvoiceService(org.folio.services.invoice.BaseInvoiceService) BaseInvoiceService(org.folio.services.invoice.BaseInvoiceService) VoucherService(org.folio.rest.impl.VoucherService) ExchangeRateProviderResolver(org.folio.services.exchange.ExchangeRateProviderResolver) InvoiceLinesRetrieveService(org.folio.services.InvoiceLinesRetrieveService) OrderLineService(org.folio.services.order.OrderLineService) VoucherValidator(org.folio.services.validator.VoucherValidator) BatchVoucher(org.folio.rest.jaxrs.model.BatchVoucher) InvoiceLineService(org.folio.services.invoice.InvoiceLineService) ConfigurationService(org.folio.services.configuration.ConfigurationService) RequestContext(org.folio.rest.core.models.RequestContext) OrderService(org.folio.services.order.OrderService) InvoiceRetrieveService(org.folio.services.InvoiceRetrieveService) BatchVoucherExport(org.folio.rest.jaxrs.model.BatchVoucherExport) Test(org.junit.jupiter.api.Test)

Example 3 with BatchVoucher

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

the class UploadBatchVoucherExportServiceTest method testFineNameGenerateLogicIdThereIsSeparatorInUUID.

@Test
public void testFineNameGenerateLogicIdThereIsSeparatorInUUID() throws ExecutionException, InterruptedException {
    // given
    UploadBatchVoucherExportService serviceSpy = spy(new UploadBatchVoucherExportService(ctxMock, bvHelper, bvExportConfigHelper, bvExportsHelper));
    BatchVoucher bv = getMockAsJson(BATCH_VOUCHERS_PATH).mapTo(BatchVoucher.class);
    String expId = "b58dcd02ee14";
    bv.setId("xxx-yyy-zzz-" + expId);
    // When
    String actFileName = serviceSpy.generateFileName(bv, "json");
    // Then
    Assertions.assertEquals("bv_" + expId + "_Amherst College (AC)_2019-12-06_2019-12-07.json", actFileName);
}
Also used : BatchVoucher(org.folio.rest.jaxrs.model.BatchVoucher) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 4 with BatchVoucher

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

the class UploadBatchVoucherExportServiceTest method testShouldSuccessUploadBatchVoucherExport.

@Test
public void testShouldSuccessUploadBatchVoucherExport() throws ExecutionException, InterruptedException {
    // given
    UploadBatchVoucherExportService serviceSpy = spy(new UploadBatchVoucherExportService(ctxMock, bvHelper, bvExportConfigHelper, bvExportsHelper));
    BatchVoucher bv = getMockAsJson(BATCH_VOUCHERS_PATH).mapTo(BatchVoucher.class);
    Response.ResponseBuilder responseBuilder = Response.status(200).header("Content-Type", "application/json");
    BatchVoucherExport bvExport = getMockAsJson(BATCH_VOUCHERS_EXPORT_PATH).mapTo(BatchVoucherExport.class);
    ExportConfigCollection bvExportConf = getMockAsJson(BATCH_VOUCHERS_EXPORT_CONF_PATH).mapTo(ExportConfigCollection.class);
    Credentials credentials = getMockAsJson(CRED_PATH).mapTo(Credentials.class);
    doReturn(completedFuture(bvExport)).when(bvExportsHelper).getBatchVoucherExportById(BV_EXPORT_ID);
    doReturn(completedFuture(credentials)).when(bvExportConfigHelper).getExportConfigCredentials(bvExportConf.getExportConfigs().get(0).getId());
    doReturn(completedFuture(bvExportConf)).when(bvExportConfigHelper).getExportConfigs(1, 0, "batchGroupId==" + bvExport.getBatchGroupId());
    doReturn(completedFuture(null)).when(bvExportsHelper).updateBatchVoucherExportRecord(eq(bvExport));
    doReturn(completedFuture(bv)).when(bvHelper).getBatchVoucherById(BV_ID);
    doReturn(completedFuture(null)).when(serviceSpy).uploadBatchVoucher(any());
    // When
    serviceSpy.uploadBatchVoucherExport(BV_EXPORT_ID).get();
    // Then
    verify(bvExportsHelper).getBatchVoucherExportById(BV_EXPORT_ID);
    verify(bvExportConfigHelper).getExportConfigCredentials(bvExportConf.getExportConfigs().get(0).getId());
    verify(bvHelper).getBatchVoucherById(BV_ID);
    verify(bvExportsHelper).updateBatchVoucherExportRecord(eq(bvExport));
    verify(bvExportConfigHelper).getExportConfigs(eq(1), eq(0), anyString());
    Assertions.assertEquals(BatchVoucherExport.Status.UPLOADED, bvExport.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ExportConfigCollection(org.folio.rest.jaxrs.model.ExportConfigCollection) BatchVoucher(org.folio.rest.jaxrs.model.BatchVoucher) BatchVoucherExport(org.folio.rest.jaxrs.model.BatchVoucherExport) Credentials(org.folio.rest.jaxrs.model.Credentials) Test(org.junit.jupiter.api.Test)

Example 5 with BatchVoucher

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

the class UploadBatchVoucherExportServiceTest method testFineNameGenerateLogicIdThereNoSeparatorInUUID.

@Test
public void testFineNameGenerateLogicIdThereNoSeparatorInUUID() throws ExecutionException, InterruptedException {
    // given
    UploadBatchVoucherExportService serviceSpy = spy(new UploadBatchVoucherExportService(ctxMock, bvHelper, bvExportConfigHelper, bvExportsHelper));
    BatchVoucher bv = getMockAsJson(BATCH_VOUCHERS_PATH).mapTo(BatchVoucher.class);
    bv.setId("xxxyyyzzb58dcd02ee14");
    // When
    String actFileName = serviceSpy.generateFileName(bv, "json");
    // Then
    Assertions.assertEquals("bv_" + bv.getId() + "_Amherst College (AC)_2019-12-06_2019-12-07.json", actFileName);
}
Also used : BatchVoucher(org.folio.rest.jaxrs.model.BatchVoucher) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

BatchVoucher (org.folio.rest.jaxrs.model.BatchVoucher)14 Test (org.junit.jupiter.api.Test)12 JsonObject (io.vertx.core.json.JsonObject)10 BatchVoucherExport (org.folio.rest.jaxrs.model.BatchVoucherExport)4 Context (io.vertx.core.Context)3 URISyntaxException (java.net.URISyntaxException)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 Vertx (io.vertx.core.Vertx)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Locale (java.util.Locale)2 TimeZone (java.util.TimeZone)2 UUID (java.util.UUID)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeUnit (java.util.concurrent.TimeUnit)2 TimeoutException (java.util.concurrent.TimeoutException)2 AddressConverter (org.folio.converters.AddressConverter)2 FtpException (org.folio.exceptions.FtpException)2 RestClient (org.folio.rest.core.RestClient)2