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));
}
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());
}
}
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());
}
Aggregations