Search in sources :

Example 26 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)

Example 27 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)

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