use of org.folio.rest.jaxrs.model.VoucherCollection in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupUpdateVoucher.
private void setupUpdateVoucher(Invoice invoice) throws IOException {
// GET Voucher
Voucher voucher = getMockAs(VOUCHER_SAMPLE_PATH, Voucher.class);
VoucherCollection voucherCollection = new VoucherCollection().withVouchers(singletonList(voucher)).withTotalRecords(1);
RequestEntry getRequestEntry = new RequestEntry(VOUCHER_ENDPOINT).withQuery(String.format("invoiceId==%s", invoice.getId())).withLimit(1).withOffset(0);
doReturn(completedFuture(voucherCollection)).when(restClient).get(argThat(re -> sameRequestEntry(getRequestEntry, re)), eq(requestContextMock), eq(VoucherCollection.class));
// PUT Voucher
RequestEntry putRequestEntry = new RequestEntry(VOUCHER_BY_ID_ENDPOINT).withId(voucher.getId());
doReturn(completedFuture(null)).when(restClient).put(argThat(re -> sameRequestEntry(putRequestEntry, re)), any(Voucher.class), eq(requestContextMock));
}
use of org.folio.rest.jaxrs.model.VoucherCollection in project mod-invoice by folio-org.
the class MockServer method handleGetVouchers.
private void handleGetVouchers(RoutingContext ctx) {
logger.info("handleGetVoucher got: {}?{}", ctx.request().path(), ctx.request().query());
String queryParam = StringUtils.trimToEmpty(ctx.request().getParam(QUERY));
String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
String invoiceId = EMPTY;
if (queryParam.contains(INVOICE_ID)) {
invoiceId = queryParam.split(INVOICE_ID + "==")[1];
}
if (EXCEPTION_CASE_BATCH_VOUCHER_EXPORT_GENERATION.equals(queryParam)) {
VoucherCollection voucherCollection = new VoucherCollection();
voucherCollection.withVouchers(new ArrayList<>());
JsonObject vouchersJson = JsonObject.mapFrom(voucherCollection);
addServerRqRsData(HttpMethod.GET, VOUCHERS_STORAGE, vouchersJson);
serverResponse(ctx, 200, APPLICATION_JSON, vouchersJson.encode());
return;
}
if (queryParam.contains("batchGroupId") && queryParam.contains("voucherDate")) {
invoiceId = "c0d08448-347b-418a-8c2f-5fb50248d67e";
}
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_VOUCHERS_ERROR_TENANT.equals(tenant)) {
serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
} else {
Supplier<List<Voucher>> getFromFile = () -> {
try {
return new JsonObject(getMockData(VOUCHERS_LIST_PATH)).mapTo(VoucherCollection.class).getVouchers();
} catch (IOException e) {
return Collections.emptyList();
}
};
VoucherCollection voucherCollection = new VoucherCollection();
List<Voucher> vouchers = getMockEntries(VOUCHERS_STORAGE, Voucher.class).orElseGet(getFromFile);
Function<Voucher, String> invoiceIdGetter = Voucher::getInvoiceId;
voucherCollection.setVouchers(filterEntriesByStringValue(invoiceId, vouchers, invoiceIdGetter));
voucherCollection.setTotalRecords(voucherCollection.getVouchers().size());
JsonObject vouchersJson = JsonObject.mapFrom(voucherCollection);
logger.info(vouchersJson.encodePrettily());
addServerRqRsData(HttpMethod.GET, VOUCHERS_STORAGE, vouchersJson);
serverResponse(ctx, 200, APPLICATION_JSON, vouchersJson.encode());
}
}
use of org.folio.rest.jaxrs.model.VoucherCollection in project mod-invoice by folio-org.
the class VouchersApiTest method testGetVoucherVouchers.
@Test
public void testGetVoucherVouchers() {
logger.info("=== Test Get Vouchers by without query - get 200 by successful retrieval of vouchers ===");
final VoucherCollection resp = verifySuccessGet(VOUCHER_PATH, VoucherCollection.class);
assertEquals(2, resp.getTotalRecords().intValue());
}
use of org.folio.rest.jaxrs.model.VoucherCollection in project mod-invoice by folio-org.
the class VouchersApiTest method testGetVoucherVouchersWithQueryParam.
@Test
public void testGetVoucherVouchersWithQueryParam() {
logger.info("=== Test Get Vouchers with query - get 200 by successful retrieval of vouchers by query ===");
String endpointQuery = String.format("%s?query=%s==%s", VOUCHER_PATH, INVOICE_ID, APPROVED_INVOICE_ID);
final VoucherCollection resp = verifySuccessGet(endpointQuery, VoucherCollection.class);
assertEquals(1, resp.getTotalRecords().intValue());
}
use of org.folio.rest.jaxrs.model.VoucherCollection 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());
}
Aggregations