Search in sources :

Example 1 with LOAD_SAMPLE_PARAMETER

use of org.folio.rest.impl.ModTenantAPI.LOAD_SAMPLE_PARAMETER in project mod-source-record-storage by folio-org.

the class AbstractRestVerticleTest method setUpClass.

@BeforeClass
public static void setUpClass(final TestContext context) throws Exception {
    Async async = context.async();
    vertx = Vertx.vertx();
    String[] hostAndPort = cluster.getBrokerList().split(":");
    System.setProperty(KAFKA_HOST, hostAndPort[0]);
    System.setProperty(KAFKA_PORT, hostAndPort[1]);
    System.setProperty(OKAPI_URL_ENV, OKAPI_URL);
    okapiPort = NetworkUtils.nextFreePort();
    String okapiUrl = "http://localhost:" + okapiPort;
    useExternalDatabase = System.getProperty("org.folio.source.storage.test.database", "embedded");
    RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory(new Jackson2ObjectMapperFactory() {

        @Override
        public ObjectMapper create(Type arg0, String arg1) {
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper;
        }
    }));
    switch(useExternalDatabase) {
        case "environment":
            System.out.println("Using environment settings");
            break;
        case "external":
            String postgresConfigPath = System.getProperty("org.folio.source.storage.test.config", "/postgres-conf-local.json");
            PostgresClientFactory.setConfigFilePath(postgresConfigPath);
            break;
        case "embedded":
            postgresSQLContainer = new PostgreSQLContainer<>(POSTGRES_IMAGE);
            postgresSQLContainer.start();
            Envs.setEnv(postgresSQLContainer.getHost(), postgresSQLContainer.getFirstMappedPort(), postgresSQLContainer.getUsername(), postgresSQLContainer.getPassword(), postgresSQLContainer.getDatabaseName());
            break;
        default:
            String message = "No understood database choice made." + "Please set org.folio.source.storage.test.database" + "to 'external', 'environment' or 'embedded'";
            throw new Exception(message);
    }
    TenantClient tenantClient = new TenantClient(okapiUrl, "diku", "dummy-token");
    DeploymentOptions restVerticleDeploymentOptions = new DeploymentOptions().setConfig(new JsonObject().put("http.port", okapiPort));
    vertx.deployVerticle(RestVerticle.class.getName(), restVerticleDeploymentOptions, res -> {
        try {
            TenantAttributes tenantAttributes = new TenantAttributes();
            tenantAttributes.setModuleTo(ModuleName.getModuleName());
            tenantAttributes.setParameters(Collections.singletonList(new Parameter().withKey(LOAD_SAMPLE_PARAMETER).withValue("true")));
            tenantClient.postTenant(tenantAttributes, res2 -> {
                if (res2.result().statusCode() == 204) {
                    return;
                }
                if (res2.result().statusCode() == 201) {
                    tenantClient.getTenantByOperationId(res2.result().bodyAsJson(TenantJob.class).getId(), 60000, context.asyncAssertSuccess(res3 -> {
                        context.assertTrue(res3.bodyAsJson(TenantJob.class).getComplete());
                        String error = res3.bodyAsJson(TenantJob.class).getError();
                        if (error != null) {
                            context.assertTrue(error.contains("EventDescriptor was not registered for eventType"));
                        }
                    }));
                } else {
                    context.assertEquals("Failed to make post tenant. Received status code 400", res2.result().bodyAsString());
                }
                async.complete();
            });
        } catch (Exception e) {
            e.printStackTrace();
            async.complete();
        }
    });
}
Also used : RestVerticle(org.folio.rest.RestVerticle) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) RestVerticle(org.folio.rest.RestVerticle) BeforeClass(org.junit.BeforeClass) EmbeddedKafkaCluster(net.mguenther.kafka.junit.EmbeddedKafkaCluster) WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) HttpStatus(org.apache.http.HttpStatus) PostgreSQLContainer(org.testcontainers.containers.PostgreSQLContainer) Jackson2ObjectMapperFactory(io.restassured.path.json.mapper.factory.Jackson2ObjectMapperFactory) OKAPI_URL_HEADER(org.folio.dataimport.util.RestUtil.OKAPI_URL_HEADER) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) Vertx(io.vertx.reactivex.core.Vertx) TenantClient(org.folio.rest.client.TenantClient) LOAD_SAMPLE_PARAMETER(org.folio.rest.impl.ModTenantAPI.LOAD_SAMPLE_PARAMETER) RequestSpecification(io.restassured.specification.RequestSpecification) ModuleName(org.folio.rest.tools.utils.ModuleName) JsonObject(io.vertx.core.json.JsonObject) ClassRule(org.junit.ClassRule) TenantJob(org.folio.rest.jaxrs.model.TenantJob) RestAssuredConfig(io.restassured.config.RestAssuredConfig) Before(org.junit.Before) ObjectMapperConfig(io.restassured.config.ObjectMapperConfig) EmbeddedKafkaClusterConfig.useDefaults(net.mguenther.kafka.junit.EmbeddedKafkaClusterConfig.useDefaults) AfterClass(org.junit.AfterClass) Envs(org.folio.rest.tools.utils.Envs) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ContentType(io.restassured.http.ContentType) EmbeddedKafkaCluster.provisionWith(net.mguenther.kafka.junit.EmbeddedKafkaCluster.provisionWith) UUID(java.util.UUID) PostgresClient(org.folio.rest.persist.PostgresClient) NetworkUtils(org.folio.rest.tools.utils.NetworkUtils) Rule(org.junit.Rule) DeploymentOptions(io.vertx.core.DeploymentOptions) Type(java.lang.reflect.Type) PostgresClientFactory(org.folio.dao.PostgresClientFactory) TenantAttributes(org.folio.rest.jaxrs.model.TenantAttributes) Slf4jNotifier(com.github.tomakehurst.wiremock.common.Slf4jNotifier) Parameter(org.folio.rest.jaxrs.model.Parameter) RestAssured(io.restassured.RestAssured) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Collections(java.util.Collections) Jackson2ObjectMapperFactory(io.restassured.path.json.mapper.factory.Jackson2ObjectMapperFactory) JsonObject(io.vertx.core.json.JsonObject) TenantJob(org.folio.rest.jaxrs.model.TenantJob) ObjectMapperConfig(io.restassured.config.ObjectMapperConfig) ContentType(io.restassured.http.ContentType) Type(java.lang.reflect.Type) DeploymentOptions(io.vertx.core.DeploymentOptions) TenantAttributes(org.folio.rest.jaxrs.model.TenantAttributes) Async(io.vertx.ext.unit.Async) TenantClient(org.folio.rest.client.TenantClient) Parameter(org.folio.rest.jaxrs.model.Parameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeClass(org.junit.BeforeClass)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Slf4jNotifier (com.github.tomakehurst.wiremock.common.Slf4jNotifier)1 WireMockConfiguration (com.github.tomakehurst.wiremock.core.WireMockConfiguration)1 WireMockRule (com.github.tomakehurst.wiremock.junit.WireMockRule)1 RestAssured (io.restassured.RestAssured)1 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)1 ObjectMapperConfig (io.restassured.config.ObjectMapperConfig)1 RestAssuredConfig (io.restassured.config.RestAssuredConfig)1 ContentType (io.restassured.http.ContentType)1 Jackson2ObjectMapperFactory (io.restassured.path.json.mapper.factory.Jackson2ObjectMapperFactory)1 RequestSpecification (io.restassured.specification.RequestSpecification)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 JsonObject (io.vertx.core.json.JsonObject)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 Vertx (io.vertx.reactivex.core.Vertx)1 Type (java.lang.reflect.Type)1 Collections (java.util.Collections)1 UUID (java.util.UUID)1 EmbeddedKafkaCluster (net.mguenther.kafka.junit.EmbeddedKafkaCluster)1