Search in sources :

Example 21 with Voucher

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

the class VouchersApiTest method testGetVouchersVoucherById.

@Test
public void testGetVouchersVoucherById() throws IOException {
    logger.info("=== Test Get Voucher By Id ===");
    JsonObject vouchersList = new JsonObject(getMockData(VOUCHERS_LIST_PATH));
    String id = vouchersList.getJsonArray("vouchers").getJsonObject(0).getString(ID);
    logger.info(String.format("using mock datafile: %s%s.json", VOUCHERS_LIST_PATH, id));
    final Voucher resp = verifySuccessGet(String.format(VOUCHER_ID_PATH, id), Voucher.class);
    assertNotNull(resp.getVendorAddress());
    assertThat(resp.getVendorAddress()).hasFieldOrPropertyWithValue("addressLine1", "10 Estes Street").hasFieldOrPropertyWithValue("addressLine2", "22").hasFieldOrPropertyWithValue("city", "Ipswich").hasFieldOrPropertyWithValue("stateRegion", "MA").hasFieldOrPropertyWithValue("zipCode", "01938").hasFieldOrPropertyWithValue("country", "USA");
    logger.info(JsonObject.mapFrom(resp).encodePrettily());
    assertEquals(id, resp.getId());
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Voucher(org.folio.rest.jaxrs.model.Voucher) Test(org.junit.jupiter.api.Test)

Example 22 with Voucher

use of org.folio.rest.jaxrs.model.Voucher 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)

Example 23 with Voucher

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

the class InvoiceRetrieveServiceTest method positiveGetInvoiceMapTest.

@Test
public void positiveGetInvoiceMapTest() throws IOException, ExecutionException, InterruptedException {
    InvoiceService invoiceService = new BaseInvoiceService(new RestClient(), invoiceLineService, orderService);
    InvoiceRetrieveService service = new InvoiceRetrieveService(invoiceService);
    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, Invoice>> future = service.getInvoiceMap(voucherCollection, new RequestContext(context, okapiHeaders));
    Map<String, Invoice> lineMap = future.get();
    Assertions.assertEquals(3, lineMap.values().size());
}
Also used : RestClient(org.folio.rest.core.RestClient) BeforeEach(org.junit.jupiter.api.BeforeEach) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) Context(io.vertx.core.Context) InvoiceService(org.folio.services.invoice.InvoiceService) Voucher(org.folio.rest.jaxrs.model.Voucher) Map(java.util.Map) RequestContext(org.folio.rest.core.models.RequestContext) InvoiceLineService(org.folio.services.invoice.InvoiceLineService) JsonObject(io.vertx.core.json.JsonObject) OKAPI_URL(org.folio.rest.RestConstants.OKAPI_URL) OrderService(org.folio.services.order.OrderService) InvoiceCollection(org.folio.rest.jaxrs.model.InvoiceCollection) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) ApiTestSuite.mockPort(org.folio.ApiTestSuite.mockPort) ApiTestBase(org.folio.rest.impl.ApiTestBase) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) BaseInvoiceService(org.folio.services.invoice.BaseInvoiceService) Assertions(org.junit.jupiter.api.Assertions) Invoice(org.folio.rest.jaxrs.model.Invoice) VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) Invoice(org.folio.rest.jaxrs.model.Invoice) InvoiceService(org.folio.services.invoice.InvoiceService) BaseInvoiceService(org.folio.services.invoice.BaseInvoiceService) BaseInvoiceService(org.folio.services.invoice.BaseInvoiceService) RestClient(org.folio.rest.core.RestClient) JsonObject(io.vertx.core.json.JsonObject) Voucher(org.folio.rest.jaxrs.model.Voucher) RequestContext(org.folio.rest.core.models.RequestContext) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 24 with Voucher

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

the class VoucherLinesRetrieveServiceTest method positiveGetInvoiceMapTest.

@Test
public void positiveGetInvoiceMapTest() throws IOException, ExecutionException, InterruptedException {
    VoucherLinesRetrieveService service = new VoucherLinesRetrieveService(okapiHeaders, context, "en");
    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<VoucherLine>>> future = service.getVoucherLinesMap(voucherCollection);
    Map<String, List<VoucherLine>> lineMap = future.get();
    Assertions.assertEquals(3, lineMap.get("a9b99f8a-7100-47f2-9903-6293d44a9905").size());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) VoucherLineCollection(org.folio.rest.acq.model.VoucherLineCollection) Vertx(io.vertx.core.Vertx) 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) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) VoucherLine(org.folio.rest.acq.model.VoucherLine) Voucher(org.folio.rest.jaxrs.model.Voucher) Map(java.util.Map) Assertions(org.junit.jupiter.api.Assertions) JsonObject(io.vertx.core.json.JsonObject) OKAPI_URL(org.folio.rest.RestConstants.OKAPI_URL) VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) VoucherLine(org.folio.rest.acq.model.VoucherLine) JsonObject(io.vertx.core.json.JsonObject) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Voucher(org.folio.rest.jaxrs.model.Voucher) Test(org.junit.jupiter.api.Test)

Example 25 with Voucher

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

the class VoucherCommandService method buildNewVoucher.

/**
 * Build new {@link Voucher} based on processed {@link Invoice}
 *
 * @param invoice invoice {@link Invoice} to be approved
 * @return completable future with {@link Voucher}
 */
public CompletableFuture<Voucher> buildNewVoucher(Invoice invoice, RequestContext requestContext) {
    Voucher voucher = new Voucher();
    voucher.setInvoiceId(invoice.getId());
    return getVoucherNumberWithPrefix(requestContext).thenApply(voucher::withVoucherNumber);
}
Also used : Voucher(org.folio.rest.jaxrs.model.Voucher)

Aggregations

Voucher (org.folio.rest.jaxrs.model.Voucher)28 JsonObject (io.vertx.core.json.JsonObject)24 Test (org.junit.jupiter.api.Test)18 Invoice (org.folio.rest.jaxrs.model.Invoice)17 InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)15 Vertx (io.vertx.core.Vertx)13 List (java.util.List)12 Map (java.util.Map)12 Collectors.toList (java.util.stream.Collectors.toList)12 RequestContext (org.folio.rest.core.models.RequestContext)11 Context (io.vertx.core.Context)10 IOException (java.io.IOException)10 HashMap (java.util.HashMap)10 VoucherCollection (org.folio.rest.jaxrs.model.VoucherCollection)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 Headers (io.restassured.http.Headers)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 Fund (org.folio.rest.acq.model.finance.Fund)9 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)9 FundCollection (org.folio.rest.acq.model.finance.FundCollection)7