use of org.folio.rest.jaxrs.model.BatchVoucherExport in project mod-invoice by folio-org.
the class BatchVoucherExportsHelper method createBatchVoucherExports.
/**
* Creates a batch voucher export
*
* @param batchVoucherExport {@link BatchVoucherExport} to be created
* @return completable future with {@link BatchVoucherExport} on success or an exception if processing fails
*/
public CompletableFuture<BatchVoucherExport> createBatchVoucherExports(BatchVoucherExport batchVoucherExport) {
CompletableFuture<BatchVoucherExport> future = new CompletableFuture<>();
createRecordInStorage(JsonObject.mapFrom(batchVoucherExport), resourcesPath(BATCH_VOUCHER_EXPORTS_STORAGE)).thenApply(batchVoucherExportId -> {
BatchVoucherExport batchVoucherExportWitId = batchVoucherExport.withId(batchVoucherExportId);
future.complete(batchVoucherExportWitId);
return batchVoucherExportWitId;
}).thenAccept(this::persistBatchVoucher).exceptionally(t -> {
logger.error("Create batch voucher export error.");
future.completeExceptionally(t);
return null;
});
return future;
}
use of org.folio.rest.jaxrs.model.BatchVoucherExport 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);
}
use of org.folio.rest.jaxrs.model.BatchVoucherExport 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();
});
}
use of org.folio.rest.jaxrs.model.BatchVoucherExport 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());
}
use of org.folio.rest.jaxrs.model.BatchVoucherExport in project mod-invoice by folio-org.
the class UploadBatchVoucherExportServiceTest method testShouldFailIfBatchVoucherExportNotFound.
@Test
public void testShouldFailIfBatchVoucherExportNotFound() {
// given
CompletableFuture<BatchVoucherExport> future = new CompletableFuture<>();
future.completeExceptionally(new HttpException(404, "Not found"));
when(bvExportsHelper.getBatchVoucherExportById(BV_EXPORT_ID)).thenReturn(future);
// When
CompletableFuture<Void> actFuture = service.uploadBatchVoucherExport(BV_EXPORT_ID);
// Then
actFuture.join();
verify(bvExportsHelper).getBatchVoucherExportById(BV_EXPORT_ID);
}
Aggregations