Search in sources :

Example 6 with DbRow

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

the class QueryStatementIT method testQueryMappedOrderParam.

/**
 * Verify {@code indexedParam(Object parameters)} mapped parameters setting method.
 */
@Test
public void testQueryMappedOrderParam() {
    RangePoJo range = new RangePoJo(1, 7);
    Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.createNamedQuery("select-pokemons-idrng-order-arg").indexedParam(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 7 with DbRow

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

the class Utils method verifyPokemonsIdRange.

/**
 * Verify that {@code Multi<DbRow> rows} argument contains pokemons matching specified IDs range.
 * @param rows database query result to verify
 * @param idMin beginning of ID range
 * @param idMax end of ID range
 */
public static void verifyPokemonsIdRange(Multi<DbRow> rows, int idMin, int idMax) {
    assertThat(rows, notNullValue());
    List<DbRow> rowsList = rows.collectList().await();
    // Build Map of valid pokemons
    Map<Integer, Pokemon> valid = new HashMap<>(POKEMONS.size());
    for (Map.Entry<Integer, Pokemon> entry : POKEMONS.entrySet()) {
        int id = entry.getKey();
        Pokemon pokemon = entry.getValue();
        if (id > idMin && id < idMax) {
            valid.put(id, pokemon);
        }
    }
    // assertThat(rowsList, hasSize(valid.size()));
    for (DbRow row : rowsList) {
        Integer id = row.column(1).as(Integer.class);
        String name = row.column(2).as(String.class);
        LOGGER.info(() -> String.format("Pokemon id=%d, name=%s", id, name));
        assertThat(valid.containsKey(id), equalTo(true));
        assertThat(name, equalTo(valid.get(id).getName()));
    }
}
Also used : DbRow(io.helidon.dbclient.DbRow) HashMap(java.util.HashMap) Pokemon(io.helidon.tests.integration.dbclient.common.AbstractIT.Pokemon) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with DbRow

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

the class Utils method verifyPokemon.

/**
 * Verify that {@code Multi<DbRow> rows} argument contains single record with provided pokemon.
 *
 * @param rows database query result to verify
 * @param pokemon pokemon to compare with
 */
public static void verifyPokemon(Multi<DbRow> rows, AbstractIT.Pokemon pokemon) {
    assertThat(rows, notNullValue());
    List<DbRow> rowsList = rows.collectList().await();
    assertThat(rowsList, hasSize(1));
    DbRow row = rowsList.get(0);
    Integer id = row.column(1).as(Integer.class);
    String name = row.column(2).as(String.class);
    assertThat(id, equalTo(pokemon.getId()));
    assertThat(name, pokemon.getName().equals(name));
}
Also used : DbRow(io.helidon.dbclient.DbRow)

Example 9 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 10 with DbRow

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

the class MapperIT method testQueryWithMapping.

/**
 * Verify query of PoJo instance as a result using mapping.
 */
@Test
public void testQueryWithMapping() {
    Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.createNamedQuery("select-pokemon-named-arg").addParam("name", POKEMONS.get(2).getName()).execute());
    Multi<Pokemon> pokemonRows = rows.map(it -> it.as(Pokemon.class));
    Pokemon pokemon = pokemonRows.collectList().await().get(0);
    verifyPokemon(pokemon, POKEMONS.get(2));
}
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) Utils.verifyInsertPokemon(io.helidon.tests.integration.dbclient.common.utils.Utils.verifyInsertPokemon) 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