Search in sources :

Example 1 with PostgresClientFactory

use of org.folio.dao.PostgresClientFactory in project mod-source-record-storage by folio-org.

the class AbstractLBServiceTest method setUpClass.

@BeforeClass
public static void setUpClass(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(KAFKA_ENV, KAFKA_ENV_ID);
    System.setProperty(KAFKA_MAX_REQUEST_SIZE, String.valueOf(KAFKA_MAX_REQUEST_SIZE_VAL));
    System.setProperty(OKAPI_URL_ENV, OKAPI_URL);
    kafkaConfig = KafkaConfig.builder().kafkaHost(hostAndPort[0]).kafkaPort(hostAndPort[1]).envId(KAFKA_ENV_ID).maxRequestSize(KAFKA_MAX_REQUEST_SIZE_VAL).build();
    RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory(new Jackson2ObjectMapperFactory() {

        @Override
        public ObjectMapper create(Type arg0, String arg1) {
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper;
        }
    }));
    PostgresClient.setPostgresTester(new PostgresTesterContainer());
    JsonObject pgClientConfig = PostgresClient.getInstance(vertx).getConnectionConfig();
    Envs.setEnv(pgClientConfig.getString(PostgresClientFactory.HOST), pgClientConfig.getInteger(PostgresClientFactory.PORT), pgClientConfig.getString(PostgresClientFactory.USERNAME), pgClientConfig.getString(PostgresClientFactory.PASSWORD), pgClientConfig.getString(PostgresClientFactory.DATABASE));
    TenantClient tenantClient = new TenantClient(OKAPI_URL, TENANT_ID, TOKEN);
    DeploymentOptions restVerticleDeploymentOptions = new DeploymentOptions().setConfig(new JsonObject().put("http.port", PORT));
    vertx.deployVerticle(RestVerticle.class.getName(), restVerticleDeploymentOptions, deployResponse -> {
        try {
            tenantClient.postTenant(new TenantAttributes().withModuleTo("3.2.0"), res2 -> {
                postgresClientFactory = new PostgresClientFactory(vertx);
                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) RestVerticle(org.folio.rest.RestVerticle) BeforeClass(org.junit.BeforeClass) EmbeddedKafkaCluster(net.mguenther.kafka.junit.EmbeddedKafkaCluster) PostgresTesterContainer(org.folio.postgres.testing.PostgresTesterContainer) Jackson2ObjectMapperFactory(io.restassured.path.json.mapper.factory.Jackson2ObjectMapperFactory) TenantClient(org.folio.rest.client.TenantClient) JsonObject(io.vertx.core.json.JsonObject) Metadata(org.folio.rest.jaxrs.model.Metadata) ClassRule(org.junit.ClassRule) TenantJob(org.folio.rest.jaxrs.model.TenantJob) RestAssuredConfig(io.restassured.config.RestAssuredConfig) ObjectMapperConfig(io.restassured.config.ObjectMapperConfig) EmbeddedKafkaClusterConfig.useDefaults(net.mguenther.kafka.junit.EmbeddedKafkaClusterConfig.useDefaults) AfterClass(org.junit.AfterClass) Envs(org.folio.rest.tools.utils.Envs) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Vertx(io.vertx.core.Vertx) EmbeddedKafkaCluster.provisionWith(net.mguenther.kafka.junit.EmbeddedKafkaCluster.provisionWith) PostgresClient(org.folio.rest.persist.PostgresClient) NetworkUtils(org.folio.rest.tools.utils.NetworkUtils) DeploymentOptions(io.vertx.core.DeploymentOptions) Type(java.lang.reflect.Type) PostgresClientFactory(org.folio.dao.PostgresClientFactory) TenantAttributes(org.folio.rest.jaxrs.model.TenantAttributes) RestAssured(io.restassured.RestAssured) KafkaConfig(org.folio.kafka.KafkaConfig) 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) Type(java.lang.reflect.Type) DeploymentOptions(io.vertx.core.DeploymentOptions) TenantAttributes(org.folio.rest.jaxrs.model.TenantAttributes) PostgresClientFactory(org.folio.dao.PostgresClientFactory) Async(io.vertx.ext.unit.Async) TenantClient(org.folio.rest.client.TenantClient) PostgresTesterContainer(org.folio.postgres.testing.PostgresTesterContainer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeClass(org.junit.BeforeClass)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RestAssured (io.restassured.RestAssured)1 ObjectMapperConfig (io.restassured.config.ObjectMapperConfig)1 RestAssuredConfig (io.restassured.config.RestAssuredConfig)1 Jackson2ObjectMapperFactory (io.restassured.path.json.mapper.factory.Jackson2ObjectMapperFactory)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 Vertx (io.vertx.core.Vertx)1 JsonObject (io.vertx.core.json.JsonObject)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 Type (java.lang.reflect.Type)1 EmbeddedKafkaCluster (net.mguenther.kafka.junit.EmbeddedKafkaCluster)1 EmbeddedKafkaCluster.provisionWith (net.mguenther.kafka.junit.EmbeddedKafkaCluster.provisionWith)1 EmbeddedKafkaClusterConfig.useDefaults (net.mguenther.kafka.junit.EmbeddedKafkaClusterConfig.useDefaults)1 PostgresClientFactory (org.folio.dao.PostgresClientFactory)1 KafkaConfig (org.folio.kafka.KafkaConfig)1 PostgresTesterContainer (org.folio.postgres.testing.PostgresTesterContainer)1 RestVerticle (org.folio.rest.RestVerticle)1 TenantClient (org.folio.rest.client.TenantClient)1 Metadata (org.folio.rest.jaxrs.model.Metadata)1