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