Search in sources :

Example 16 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 maybeRow database query result to verify
 * @param pokemon pokemon to compare with
 */
public static void verifyPokemon(Optional<DbRow> maybeRow, AbstractIT.Pokemon pokemon) {
    assertThat(maybeRow.isPresent(), equalTo(true));
    DbRow row = maybeRow.get();
    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 17 with DbRow

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

the class Utils method verifyUpdatePokemon.

/**
 * Verify that provided pokemon was successfully updated in the database.
 *
 * @param result DML statement result
 * @param pokemon pokemon to compare with
 */
public static void verifyUpdatePokemon(Long result, AbstractIT.Pokemon pokemon) {
    assertThat(result, equalTo(1L));
    Optional<DbRow> maybeRow = DB_CLIENT.execute(exec -> exec.namedGet("select-pokemon-by-id", pokemon.getId())).await();
    assertThat(maybeRow.isPresent(), equalTo(true));
    DbRow row = maybeRow.get();
    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) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Pokemon(io.helidon.tests.integration.dbclient.common.AbstractIT.Pokemon) HashMap(java.util.HashMap) Logger(java.util.logging.Logger) DB_CLIENT(io.helidon.tests.integration.dbclient.common.AbstractIT.DB_CLIENT) List(java.util.List) DbRow(io.helidon.dbclient.DbRow) Map(java.util.Map) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) POKEMONS(io.helidon.tests.integration.dbclient.common.AbstractIT.POKEMONS) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AbstractIT(io.helidon.tests.integration.dbclient.common.AbstractIT) Multi(io.helidon.common.reactive.Multi)

Example 18 with DbRow

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

the class Utils method verifyInsertPokemon.

/**
 * Verify that provided pokemon was successfully inserted into the database.
 *
 * @param result DML statement result
 * @param pokemon pokemon to compare with
 */
public static void verifyInsertPokemon(Long result, AbstractIT.Pokemon pokemon) {
    assertThat(result, equalTo(1L));
    Optional<DbRow> maybeRow = DB_CLIENT.execute(exec -> exec.namedGet("select-pokemon-by-id", pokemon.getId())).await();
    assertThat(maybeRow.isPresent(), equalTo(true));
    DbRow row = maybeRow.get();
    Integer id = row.column("id").as(Integer.class);
    String name = row.column("name").as(String.class);
    assertThat(id, equalTo(pokemon.getId()));
    assertThat(name, pokemon.getName().equals(name));
}
Also used : DbRow(io.helidon.dbclient.DbRow) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Pokemon(io.helidon.tests.integration.dbclient.common.AbstractIT.Pokemon) HashMap(java.util.HashMap) Logger(java.util.logging.Logger) DB_CLIENT(io.helidon.tests.integration.dbclient.common.AbstractIT.DB_CLIENT) List(java.util.List) DbRow(io.helidon.dbclient.DbRow) Map(java.util.Map) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) POKEMONS(io.helidon.tests.integration.dbclient.common.AbstractIT.POKEMONS) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AbstractIT(io.helidon.tests.integration.dbclient.common.AbstractIT) Multi(io.helidon.common.reactive.Multi)

Example 19 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 single pokemon matching specified IDs range.
 * @param maybeRow database query result to verify
 * @param idMin beginning of ID range
 * @param idMax end of ID range
 */
public static void verifyPokemonsIdRange(Optional<DbRow> maybeRow, int idMin, int idMax) {
    assertThat(maybeRow.isPresent(), equalTo(true));
    DbRow row = maybeRow.get();
    // 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);
        }
    }
    Integer id = row.column(1).as(Integer.class);
    String name = row.column(2).as(String.class);
    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 20 with DbRow

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

the class InitIT method testListPokemonTypes.

/**
 * Verify that database contains properly initialized pokemon types relation.
 */
@Test
public void testListPokemonTypes() {
    Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.namedQuery("select-pokemons"));
    assertThat(rows, notNullValue());
    List<DbRow> rowsList = rows.collectList().await();
    assertThat(rowsList, not(empty()));
    for (DbRow row : rowsList) {
        Integer pokemonId = row.column(1).as(Integer.class);
        String pokemonName = row.column(2).as(String.class);
        Pokemon pokemon = POKEMONS.get(pokemonId);
        assertThat(pokemonName, POKEMONS.get(pokemonId).getName().equals(pokemonName));
        Multi<DbRow> typeRows = DB_CLIENT.execute(exec -> exec.namedQuery("select-poketypes", pokemonId));
        List<DbRow> typeRowsList = typeRows.collectList().await();
        assertThat(typeRowsList.size(), equalTo(pokemon.getTypes().size()));
        for (DbRow typeRow : typeRowsList) {
            Integer typeId = typeRow.column(2).as(Integer.class);
            assertThat(pokemon.getTypes(), hasItem(TYPES.get(typeId)));
        }
    }
}
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