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));
}
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));
}
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));
}
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()));
}
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)));
}
}
}
Aggregations