Search in sources :

Example 1 with ExportConfig

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

the class MockServer method handleGetBatchVoucherExportConfigById.

private void handleGetBatchVoucherExportConfigById(RoutingContext ctx) {
    logger.info("handleGetBatchVoucherExportConfigById got: GET " + ctx.request().path());
    String id = ctx.request().getParam(AbstractHelper.ID);
    logger.info("id: " + id);
    if (ID_FOR_INTERNAL_SERVER_ERROR.equals(id)) {
        serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else {
        JsonObject exportConfig = getMockEntry(BATCH_VOUCHER_EXPORT_CONFIGS, id).orElseGet(getJsonObjectFromFile(BATCH_VOUCHER_EXPORT_CONFIG_SAMPLE_PATH, id));
        if (exportConfig == null) {
            ctx.response().setStatusCode(404).end(id);
        } else {
            ExportConfig exportConfigSchema = exportConfig.mapTo(ExportConfig.class);
            exportConfigSchema.setId(id);
            exportConfigSchema.setUploadURI(ftpUri);
            // validate content against schema
            exportConfig = JsonObject.mapFrom(exportConfigSchema);
            addServerRqRsData(HttpMethod.GET, BATCH_VOUCHER_EXPORT_CONFIGS, exportConfig);
            serverResponse(ctx, 200, APPLICATION_JSON, exportConfig.encodePrettily());
        }
    }
}
Also used : ExportConfig(org.folio.rest.jaxrs.model.ExportConfig) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with ExportConfig

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

the class BatchVoucherExportConfigTest method testPostExportConfig.

@Test
public void testPostExportConfig() throws IOException {
    logger.info("=== Test create batch voucher export config ===");
    String body = getMockData(BATCH_VOUCHER_EXPORT_CONFIG_SAMPLE_PATH_WITH_ID);
    final ExportConfig exportConfig = verifyPostResponse(BATCH_VOUCHER_EXPORT_CONFIGS_ENDPOINT, body, prepareHeaders(X_OKAPI_TENANT), APPLICATION_JSON, 201).as(ExportConfig.class);
    String id = exportConfig.getId();
    assertThat(id, notNullValue());
    assertThat(MockServer.serverRqRs.get(BATCH_VOUCHER_EXPORT_CONFIGS, HttpMethod.POST), hasSize(1));
}
Also used : ExportConfig(org.folio.rest.jaxrs.model.ExportConfig) Test(org.junit.jupiter.api.Test)

Example 3 with ExportConfig

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

the class BatchVoucherExportConfigTest method testPutExportConfig.

@Test
public void testPutExportConfig() {
    logger.info("=== Test edit batch voucher export configuration - 204 expected ===");
    ExportConfig exportConfig = getMockAsJson(BATCH_VOUCHER_EXPORT_CONFIG_SAMPLE_PATH_WITH_ID).mapTo(ExportConfig.class);
    exportConfig.setFormat(Format.APPLICATION_JSON);
    verifyPut(BATCH_VOUCHER_EXPORT_CONFIG_ENDPOINT_WITH_ID, JsonObject.mapFrom(exportConfig), "", 204);
    assertThat(MockServer.serverRqRs.get(BATCH_VOUCHER_EXPORT_CONFIGS, HttpMethod.PUT), hasSize(1));
}
Also used : ExportConfig(org.folio.rest.jaxrs.model.ExportConfig) Test(org.junit.jupiter.api.Test)

Example 4 with ExportConfig

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

the class MockServer method handleGetBatchVoucherExportConfigs.

private void handleGetBatchVoucherExportConfigs(RoutingContext ctx) {
    logger.info("handleGetBatchVoucherExportConfigs got: {}?{}", ctx.request().path(), ctx.request().query());
    verifyIntegerParams(ctx, new String[] { LIMIT, OFFSET });
    String queryParam = StringUtils.trimToEmpty(ctx.request().getParam(QUERY));
    String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
    if (queryParam.contains(BAD_QUERY)) {
        serverResponse(ctx, 400, APPLICATION_JSON, Response.Status.BAD_REQUEST.getReasonPhrase());
    } else if (queryParam.contains(ID_FOR_INTERNAL_SERVER_ERROR) || ERROR_TENANT.equals(tenant)) {
        serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else {
        Supplier<List<ExportConfig>> getFromFile = () -> {
            try {
                return new JsonObject(getMockData(BATCH_VOUCHER_EXPORT_CONFIGS_SAMPLE_PATH)).mapTo(ExportConfigCollection.class).getExportConfigs();
            } catch (IOException e) {
                return Collections.emptyList();
            }
        };
        ExportConfigCollection exportConfigCollection = new ExportConfigCollection();
        List<ExportConfig> exportConfigs = getMockEntries(BATCH_VOUCHER_EXPORT_CONFIGS, ExportConfig.class).orElseGet(getFromFile);
        exportConfigCollection.setExportConfigs(exportConfigs);
        exportConfigCollection.setTotalRecords(exportConfigCollection.getExportConfigs().size());
        JsonObject exportConfigsJson = JsonObject.mapFrom(exportConfigCollection);
        logger.info(exportConfigsJson.encodePrettily());
        addServerRqRsData(HttpMethod.GET, BATCH_VOUCHER_EXPORT_CONFIGS, exportConfigsJson);
        serverResponse(ctx, 200, APPLICATION_JSON, exportConfigsJson.encode());
    }
}
Also used : ExportConfigCollection(org.folio.rest.jaxrs.model.ExportConfigCollection) ExportConfig(org.folio.rest.jaxrs.model.ExportConfig) 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 5 with ExportConfig

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

the class BatchVoucherExportConfigTest method testGetExportConfig.

@Test
public void testGetExportConfig() {
    logger.info("=== Test get batch voucher export configuration by id ===");
    final ExportConfig exportConfig = verifySuccessGet(BATCH_VOUCHER_EXPORT_CONFIG_ENDPOINT_WITH_ID, ExportConfig.class);
    assertThat(MockServer.serverRqRs.get(BATCH_VOUCHER_EXPORT_CONFIGS, HttpMethod.GET), hasSize(1));
    Assertions.assertEquals(EXPORT_CONFIG_ID, exportConfig.getId());
}
Also used : ExportConfig(org.folio.rest.jaxrs.model.ExportConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ExportConfig (org.folio.rest.jaxrs.model.ExportConfig)6 JsonObject (io.vertx.core.json.JsonObject)3 Test (org.junit.jupiter.api.Test)3 ExportConfigCollection (org.folio.rest.jaxrs.model.ExportConfigCollection)2 Context (io.vertx.core.Context)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 Supplier (java.util.function.Supplier)1 Collectors.toList (java.util.stream.Collectors.toList)1 FolioVertxCompletableFuture (org.folio.completablefuture.FolioVertxCompletableFuture)1 HelperUtils.getEndpointWithQuery (org.folio.invoices.utils.HelperUtils.getEndpointWithQuery)1 HelperUtils.getHttpClient (org.folio.invoices.utils.HelperUtils.getHttpClient)1 HelperUtils.handleDeleteRequest (org.folio.invoices.utils.HelperUtils.handleDeleteRequest)1 HelperUtils.handleGetRequest (org.folio.invoices.utils.HelperUtils.handleGetRequest)1 HelperUtils.handlePutRequest (org.folio.invoices.utils.HelperUtils.handlePutRequest)1