Search in sources :

Example 21 with DbRow

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

the class InitIT method testListPokemons.

/**
 * Verify that database contains properly initialized pokemons.
 */
@Test
public void testListPokemons() {
    Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.namedQuery("select-pokemons"));
    assertThat(rows, notNullValue());
    List<DbRow> rowsList = rows.collectList().await();
    assertThat(rowsList, not(empty()));
    Set<Integer> ids = new HashSet<>(POKEMONS.keySet());
    for (DbRow row : rowsList) {
        Integer id = row.column(1).as(Integer.class);
        String name = row.column(2).as(String.class);
        assertThat(ids, hasItem(id));
        ids.remove(id);
        assertThat(name, POKEMONS.get(id).getName().equals(name));
    }
}
Also used : DbRow(io.helidon.dbclient.DbRow) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 22 with DbRow

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

the class InitIT method testListTypes.

/**
 * Verify that database contains properly initialized pokemon types.
 */
@Test
public void testListTypes() {
    Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.namedQuery("select-types"));
    assertThat(rows, notNullValue());
    List<DbRow> rowsList = rows.collectList().await(5, TimeUnit.SECONDS);
    assertThat(rowsList, not(empty()));
    Set<Integer> ids = new HashSet<>(TYPES.keySet());
    for (DbRow row : rowsList) {
        Integer id = row.column(1).as(Integer.class);
        String name = row.column(2).as(String.class);
        assertThat(ids, hasItem(id));
        ids.remove(id);
        assertThat(name, TYPES.get(id).getName().equals(name));
    }
}
Also used : DbRow(io.helidon.dbclient.DbRow) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 23 with DbRow

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

the class GetStatementIT method testGetMappedOrderParam.

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

Example 24 with DbRow

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

the class QueryStatementIT method testQueryMappedNamedParam.

/**
 * Verify {@code namedParam(Object parameters)} mapped parameters setting method.
 */
@Test
public void testQueryMappedNamedParam() {
    RangePoJo range = new RangePoJo(1, 7);
    Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.createNamedQuery("select-pokemons-idrng-named-arg").namedParam(range).execute());
    verifyPokemonsIdRange(rows, 1, 7);
}
Also used : DbRow(io.helidon.dbclient.DbRow) RangePoJo(io.helidon.tests.integration.dbclient.common.utils.RangePoJo) Test(org.junit.jupiter.api.Test)

Example 25 with DbRow

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

the class CheckIT method testDmlStatementExecution.

/**
 * Simple test to verify that DML query execution works.
 * Used before running database schema initialization.
 *
 * @throws ExecutionException when database query failed
 * @throws InterruptedException if the current thread was interrupted
 */
@Test
public void testDmlStatementExecution() throws ExecutionException, InterruptedException {
    Multi<DbRow> result = DB_CLIENT.execute(exec -> exec.namedQuery("ping-query"));
    List<DbRow> rowsList = result.collectList().await(5, TimeUnit.SECONDS);
    DbRow row = rowsList.get(0);
    Double ok = row.column("ok").as(Double.class);
    assertThat(ok, equalTo(1.0));
    LOGGER.info(() -> String.format("Command ping row: %s", row.toString()));
}
Also used : DbRow(io.helidon.dbclient.DbRow) 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