Search in sources :

Example 1 with DbRow

use of io.helidon.dbclient.DbRow in project helidon by oracle.

the class FlowControlIT method testSourceData.

/**
 * Source data verification.
 */
@Test
public void testSourceData() {
    Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.namedQuery("select-types"));
    assertThat(rows, notNullValue());
    List<DbRow> list = rows.collectList().await();
    assertThat(list, not(empty()));
    assertThat(list.size(), equalTo(18));
    for (DbRow row : list) {
        Integer id = row.column(1).as(Integer.class);
        String name = row.column(2).as(String.class);
        final Type type = new Type(id, name);
        assertThat(name, TYPES.get(id).getName().equals(name));
        LOGGER.info(() -> String.format("Type: %s", type.toString()));
    }
}
Also used : DbRow(io.helidon.dbclient.DbRow) Type(io.helidon.tests.integration.dbclient.common.AbstractIT.Type) Test(org.junit.jupiter.api.Test)

Example 2 with DbRow

use of io.helidon.dbclient.DbRow in project helidon by oracle.

the class ServerHealthCheckIT method testHttpHealth.

/**
 * Read and check DB Client health status from Helidon Web Server.
 *
 * @throws InterruptedException if the current thread was interrupted
 * @throws IOException if an I/O error occurs when sending or receiving HTTP request
 */
@Test
public void testHttpHealth() throws IOException, InterruptedException {
    // Call select-pokemons to warm up server
    Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.namedQuery("select-pokemons"));
    List<DbRow> pokemonList = rows.collectList().await();
    // Read and process health check response
    String response = get(URL + "/health");
    LOGGER.info("RESPONSE: " + response);
    JsonStructure jsonResponse = null;
    try (JsonReader jr = Json.createReader(new StringReader(response))) {
        jsonResponse = jr.read();
    } catch (JsonParsingException | IllegalStateException ex) {
        fail(String.format("Error parsing response: %s", ex.getMessage()));
    }
    JsonArray checks = jsonResponse.asJsonObject().getJsonArray("checks");
    assertThat(checks.size(), greaterThan(0));
    checks.stream().map((check) -> {
        String name = check.asJsonObject().getString("name");
        return check;
    }).forEachOrdered((check) -> {
        String state = check.asJsonObject().getString("state");
        String status = check.asJsonObject().getString("status");
        assertThat(state, equalTo("UP"));
        assertThat(status, equalTo("UP"));
    });
}
Also used : DbRow(io.helidon.dbclient.DbRow) JsonArray(jakarta.json.JsonArray) DbClientHealthCheck(io.helidon.dbclient.health.DbClientHealthCheck) Assertions.fail(org.junit.jupiter.api.Assertions.fail) JsonValue(jakarta.json.JsonValue) HttpRequest(java.net.http.HttpRequest) HealthSupport(io.helidon.health.HealthSupport) AfterAll(org.junit.jupiter.api.AfterAll) JsonStructure(jakarta.json.JsonStructure) DbRow(io.helidon.dbclient.DbRow) BeforeAll(org.junit.jupiter.api.BeforeAll) HttpClient(java.net.http.HttpClient) URI(java.net.URI) JsonReader(jakarta.json.JsonReader) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Multi(io.helidon.common.reactive.Multi) HealthCheck(org.eclipse.microprofile.health.HealthCheck) HttpResponse(java.net.http.HttpResponse) JsonParsingException(jakarta.json.stream.JsonParsingException) Config(io.helidon.config.Config) IOException(java.io.IOException) Logger(java.util.logging.Logger) DB_CLIENT(io.helidon.tests.integration.dbclient.common.AbstractIT.DB_CLIENT) CONFIG(io.helidon.tests.integration.dbclient.common.AbstractIT.CONFIG) Json(jakarta.json.Json) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) StringReader(java.io.StringReader) Matchers.equalTo(org.hamcrest.Matchers.equalTo) WebServer(io.helidon.webserver.WebServer) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Routing(io.helidon.webserver.Routing) JsonArray(jakarta.json.JsonArray) StringReader(java.io.StringReader) JsonReader(jakarta.json.JsonReader) JsonStructure(jakarta.json.JsonStructure) JsonParsingException(jakarta.json.stream.JsonParsingException) Test(org.junit.jupiter.api.Test)

Example 3 with DbRow

use of io.helidon.dbclient.DbRow in project helidon by oracle.

the class MapperIT method testGetWithMapping.

/**
 * Verify get of PoJo instance as a result using mapping.
 */
@Test
public void testGetWithMapping() {
    Optional<DbRow> maybeRow = DB_CLIENT.execute(exec -> exec.createNamedGet("select-pokemon-named-arg").addParam("name", POKEMONS.get(3).getName()).execute()).await();
    assertThat(maybeRow.isPresent(), equalTo(true));
    Pokemon pokemon = maybeRow.get().as(Pokemon.class);
    verifyPokemon(pokemon, POKEMONS.get(3));
}
Also used : DbRow(io.helidon.dbclient.DbRow) Utils.verifyDeletePokemon(io.helidon.tests.integration.dbclient.common.utils.Utils.verifyDeletePokemon) Utils.verifyUpdatePokemon(io.helidon.tests.integration.dbclient.common.utils.Utils.verifyUpdatePokemon) Utils.verifyPokemon(io.helidon.tests.integration.dbclient.common.utils.Utils.verifyPokemon) Logger(java.util.logging.Logger) Utils.verifyInsertPokemon(io.helidon.tests.integration.dbclient.common.utils.Utils.verifyInsertPokemon) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) DbRow(io.helidon.dbclient.DbRow) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AbstractIT(io.helidon.tests.integration.dbclient.common.AbstractIT) Multi(io.helidon.common.reactive.Multi) Utils.verifyDeletePokemon(io.helidon.tests.integration.dbclient.common.utils.Utils.verifyDeletePokemon) Utils.verifyUpdatePokemon(io.helidon.tests.integration.dbclient.common.utils.Utils.verifyUpdatePokemon) Utils.verifyPokemon(io.helidon.tests.integration.dbclient.common.utils.Utils.verifyPokemon) Utils.verifyInsertPokemon(io.helidon.tests.integration.dbclient.common.utils.Utils.verifyInsertPokemon) Test(org.junit.jupiter.api.Test)

Example 4 with DbRow

use of io.helidon.dbclient.DbRow in project helidon by oracle.

the class QueryStatementService method executeTest.

// Common test execution code
private JsonObject executeTest(final ServerRequest request, final ServerResponse response, final String testName, final TestFunction test) {
    LOGGER.fine(() -> String.format("Running SimpleQueryService.%s on server", testName));
    try {
        String fromIdStr = param(request, QUERY_FROM_ID_PARAM);
        int fromId = Integer.parseInt(fromIdStr);
        String toIdStr = param(request, QUERY_TO_ID_PARAM);
        int toId = Integer.parseInt(toIdStr);
        Multi<DbRow> future = test.apply(fromId, toId);
        final JsonArrayBuilder jab = Json.createArrayBuilder();
        future.forEach(dbRow -> jab.add(dbRow.as(JsonObject.class))).onComplete(() -> response.send(okStatus(jab.build()))).exceptionally(t -> {
            response.send(exceptionStatus(t));
            return null;
        });
    } catch (NumberFormatException | RemoteTestException ex) {
        LOGGER.fine(() -> String.format("Error in SimpleQueryService.%s on server", testName));
        response.send(exceptionStatus(ex));
    }
    return null;
}
Also used : DbRow(io.helidon.dbclient.DbRow) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException)

Example 5 with DbRow

use of io.helidon.dbclient.DbRow in project helidon by oracle.

the class GetStatementIT method testGetMappedNamedParam.

/**
 * Verify {@code namedParam(Object parameters)} mapped parameters setting method.
 *
 * @throws ExecutionException when database query failed
 * @throws InterruptedException if the current thread was interrupted
 */
@Test
public void testGetMappedNamedParam() throws ExecutionException, InterruptedException {
    RangePoJo range = new RangePoJo(0, 2);
    Optional<DbRow> maybeRow = DB_CLIENT.execute(exec -> exec.createNamedGet("select-pokemons-idrng-named-arg").namedParam(range).execute()).toCompletableFuture().get();
    verifyPokemonsIdRange(maybeRow, 0, 2);
}
Also used : DbRow(io.helidon.dbclient.DbRow) RangePoJo(io.helidon.tests.integration.dbclient.common.utils.RangePoJo) Test(org.junit.jupiter.api.Test)

Aggregations

DbRow (io.helidon.dbclient.DbRow)27 Test (org.junit.jupiter.api.Test)17 Multi (io.helidon.common.reactive.Multi)5 Pokemon (io.helidon.tests.integration.dbclient.common.AbstractIT.Pokemon)5 Logger (java.util.logging.Logger)5 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)5 Matchers.equalTo (org.hamcrest.Matchers.equalTo)5 AbstractIT (io.helidon.tests.integration.dbclient.common.AbstractIT)4 RangePoJo (io.helidon.tests.integration.dbclient.common.utils.RangePoJo)4 RemoteTestException (io.helidon.tests.integration.tools.service.RemoteTestException)4 JsonArrayBuilder (jakarta.json.JsonArrayBuilder)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 DB_CLIENT (io.helidon.tests.integration.dbclient.common.AbstractIT.DB_CLIENT)3 Map (java.util.Map)3 Matchers.notNullValue (org.hamcrest.Matchers.notNullValue)3 Config (io.helidon.config.Config)2 DbClient (io.helidon.dbclient.DbClient)2 CONFIG (io.helidon.tests.integration.dbclient.common.AbstractIT.CONFIG)2