Search in sources :

Example 1 with VoucherLineCollection

use of org.folio.rest.acq.model.VoucherLineCollection in project mod-invoice by folio-org.

the class InvoicesApiTest method testTransitionToApprovedWithExistingVoucherAndVoucherLines.

@Test
void testTransitionToApprovedWithExistingVoucherAndVoucherLines() {
    logger.info("=== Test transition invoice to Approved with existing voucher and voucherLines ===");
    InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
    Invoice reqData = getMockAsJson(REVIEWED_INVOICE_WITH_EXISTING_VOUCHER_SAMPLE_PATH).mapTo(Invoice.class);
    invoiceLine.setId(UUID.randomUUID().toString());
    invoiceLine.setInvoiceId(reqData.getId());
    invoiceLine.getFundDistributions().forEach(fundDistribution -> fundDistribution.setCode(null));
    prepareMockVoucher(reqData.getId());
    VoucherLine voucherLine = new VoucherLine().withVoucherId(EXISTING_VOUCHER_ID);
    addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
    addMockEntry(VOUCHER_LINES, JsonObject.mapFrom(voucherLine));
    reqData.setStatus(Invoice.Status.APPROVED);
    String id = reqData.getId();
    String jsonBody = JsonObject.mapFrom(reqData).encode();
    Headers headers = prepareHeaders(X_OKAPI_TENANT, X_OKAPI_USER_ID);
    verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, "", 204);
    List<JsonObject> vouchersUpdated = serverRqRs.get(VOUCHERS_STORAGE, HttpMethod.PUT);
    List<JsonObject> voucherLinesDeletions = serverRqRs.get(VOUCHER_LINES, HttpMethod.DELETE);
    List<JsonObject> voucherLinesSearches = serverRqRs.get(VOUCHER_LINES, HttpMethod.GET);
    assertThat(vouchersUpdated, notNullValue());
    assertThat(vouchersUpdated, hasSize(1));
    assertThat(voucherLinesDeletions, notNullValue());
    assertThat(voucherLinesSearches, notNullValue());
    assertThat(voucherLinesSearches, hasSize(1));
    VoucherLineCollection voucherLineCollection = voucherLinesSearches.get(0).mapTo(VoucherLineCollection.class);
    assertThat(voucherLinesDeletions, hasSize(voucherLineCollection.getTotalRecords()));
    Voucher updatedVoucher = vouchersUpdated.get(0).mapTo(Voucher.class);
    Invoice updatedInvoice = serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).mapTo(Invoice.class);
    List<JsonObject> fundsSearches = serverRqRs.get(FUNDS, HttpMethod.GET);
    List<Fund> funds = fundsSearches.get(0).mapTo(FundCollection.class).getFunds();
    verifyTransitionToApproved(updatedVoucher, Collections.singletonList(invoiceLine), updatedInvoice, getExpectedVoucherLinesQuantity(funds));
}
Also used : VoucherLine(org.folio.rest.jaxrs.model.VoucherLine) Invoice(org.folio.rest.jaxrs.model.Invoice) Fund(org.folio.rest.acq.model.finance.Fund) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Headers(io.restassured.http.Headers) VoucherLineCollection(org.folio.rest.acq.model.VoucherLineCollection) JsonObject(io.vertx.core.json.JsonObject) FundCollection(org.folio.rest.acq.model.finance.FundCollection) Matchers.containsString(org.hamcrest.Matchers.containsString) Voucher(org.folio.rest.jaxrs.model.Voucher) Test(org.junit.jupiter.api.Test)

Example 2 with VoucherLineCollection

use of org.folio.rest.acq.model.VoucherLineCollection in project mod-invoice by folio-org.

the class MockServer method handleGetVoucherLines.

private void handleGetVoucherLines(RoutingContext ctx) {
    logger.info("handleGetVoucherLines got: {}?{}", ctx.request().path(), ctx.request().query());
    String queryParam = StringUtils.trimToEmpty(ctx.request().getParam(QUERY));
    String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
    String voucherId = EMPTY;
    if (queryParam.contains(VOUCHER_ID)) {
        voucherId = queryParam.split(VOUCHER_ID + "==")[1];
    }
    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_VOUCHER_LINES_ERROR_TENANT.equals(tenant)) {
        serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else {
        Supplier<List<VoucherLine>> getFromFile = () -> {
            try {
                return new JsonObject(getMockData(VOUCHER_LINES_COLLECTION)).mapTo(VoucherLineCollection.class).getVoucherLines();
            } catch (IOException e) {
                return Collections.emptyList();
            }
        };
        VoucherLineCollection voucherLineCollection = new VoucherLineCollection();
        List<VoucherLine> voucherLines = getMockEntries(VOUCHER_LINES, VoucherLine.class).orElseGet(getFromFile);
        Function<VoucherLine, String> voucherIdGetter = VoucherLine::getVoucherId;
        voucherLineCollection.setVoucherLines(filterEntriesByStringValue(voucherId, voucherLines, voucherIdGetter));
        voucherLineCollection.setTotalRecords(voucherLineCollection.getVoucherLines().size());
        JsonObject voucherLinesJson = JsonObject.mapFrom(voucherLineCollection);
        logger.info(voucherLinesJson.encodePrettily());
        addServerRqRsData(HttpMethod.GET, VOUCHER_LINES, voucherLinesJson);
        serverResponse(ctx, 200, APPLICATION_JSON, voucherLinesJson.encode());
    }
}
Also used : VoucherLine(org.folio.rest.acq.model.VoucherLine) Function(java.util.function.Function) VoucherLineCollection(org.folio.rest.acq.model.VoucherLineCollection) 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)

Example 3 with VoucherLineCollection

use of org.folio.rest.acq.model.VoucherLineCollection in project mod-invoice by folio-org.

the class VoucherLinesRetrieveServiceTest method positiveTest.

@Test
public void positiveTest() 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);
    CompletableFuture<List<VoucherLineCollection>> future = service.getVoucherLinesByChunks(vouchers);
    List<VoucherLineCollection> lineCollections = future.get();
    Assertions.assertEquals(3, lineCollections.get(0).getVoucherLines().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) VoucherLineCollection(org.folio.rest.acq.model.VoucherLineCollection) JsonObject(io.vertx.core.json.JsonObject) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Voucher(org.folio.rest.jaxrs.model.Voucher) Test(org.junit.jupiter.api.Test)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)3 VoucherLineCollection (org.folio.rest.acq.model.VoucherLineCollection)3 IOException (java.io.IOException)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 VoucherLine (org.folio.rest.acq.model.VoucherLine)2 Voucher (org.folio.rest.jaxrs.model.Voucher)2 Test (org.junit.jupiter.api.Test)2 Headers (io.restassured.http.Headers)1 Context (io.vertx.core.Context)1 Vertx (io.vertx.core.Vertx)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 ApiTestSuite.mockPort (org.folio.ApiTestSuite.mockPort)1 OKAPI_URL (org.folio.rest.RestConstants.OKAPI_URL)1