use of io.helidon.dbclient.DbRow in project helidon by oracle.
the class FlowControlIT method testSourceData.
/**
* Source data verification.
*/
@Test
public void testSourceData() {
Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.namedQuery("select-types"));
assertThat(rows, notNullValue());
List<DbRow> list = rows.collectList().await();
assertThat(list, not(empty()));
assertThat(list.size(), equalTo(18));
for (DbRow row : list) {
Integer id = row.column(1).as(Integer.class);
String name = row.column(2).as(String.class);
final Type type = new Type(id, name);
assertThat(name, TYPES.get(id).getName().equals(name));
LOGGER.info(() -> String.format("Type: %s", type.toString()));
}
}
use of io.helidon.dbclient.DbRow in project helidon by oracle.
the class ServerHealthCheckIT method testHttpHealth.
/**
* Read and check DB Client health status from Helidon Web Server.
*
* @throws InterruptedException if the current thread was interrupted
* @throws IOException if an I/O error occurs when sending or receiving HTTP request
*/
@Test
public void testHttpHealth() throws IOException, InterruptedException {
// Call select-pokemons to warm up server
Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.namedQuery("select-pokemons"));
List<DbRow> pokemonList = rows.collectList().await();
// Read and process health check response
String response = get(URL + "/health");
LOGGER.info("RESPONSE: " + response);
JsonStructure jsonResponse = null;
try (JsonReader jr = Json.createReader(new StringReader(response))) {
jsonResponse = jr.read();
} catch (JsonParsingException | IllegalStateException ex) {
fail(String.format("Error parsing response: %s", ex.getMessage()));
}
JsonArray checks = jsonResponse.asJsonObject().getJsonArray("checks");
assertThat(checks.size(), greaterThan(0));
checks.stream().map((check) -> {
String name = check.asJsonObject().getString("name");
return check;
}).forEachOrdered((check) -> {
String state = check.asJsonObject().getString("state");
String status = check.asJsonObject().getString("status");
assertThat(state, equalTo("UP"));
assertThat(status, equalTo("UP"));
});
}
use of io.helidon.dbclient.DbRow in project helidon by oracle.
the class MapperIT method testGetWithMapping.
/**
* Verify get of PoJo instance as a result using mapping.
*/
@Test
public void testGetWithMapping() {
Optional<DbRow> maybeRow = DB_CLIENT.execute(exec -> exec.createNamedGet("select-pokemon-named-arg").addParam("name", POKEMONS.get(3).getName()).execute()).await();
assertThat(maybeRow.isPresent(), equalTo(true));
Pokemon pokemon = maybeRow.get().as(Pokemon.class);
verifyPokemon(pokemon, POKEMONS.get(3));
}
use of io.helidon.dbclient.DbRow in project helidon by oracle.
the class QueryStatementService method executeTest.
// Common test execution code
private JsonObject executeTest(final ServerRequest request, final ServerResponse response, final String testName, final TestFunction test) {
LOGGER.fine(() -> String.format("Running SimpleQueryService.%s on server", testName));
try {
String fromIdStr = param(request, QUERY_FROM_ID_PARAM);
int fromId = Integer.parseInt(fromIdStr);
String toIdStr = param(request, QUERY_TO_ID_PARAM);
int toId = Integer.parseInt(toIdStr);
Multi<DbRow> future = test.apply(fromId, toId);
final JsonArrayBuilder jab = Json.createArrayBuilder();
future.forEach(dbRow -> jab.add(dbRow.as(JsonObject.class))).onComplete(() -> response.send(okStatus(jab.build()))).exceptionally(t -> {
response.send(exceptionStatus(t));
return null;
});
} catch (NumberFormatException | RemoteTestException ex) {
LOGGER.fine(() -> String.format("Error in SimpleQueryService.%s on server", testName));
response.send(exceptionStatus(ex));
}
return null;
}
use of io.helidon.dbclient.DbRow in project helidon by oracle.
the class GetStatementIT method testGetMappedNamedParam.
/**
* Verify {@code namedParam(Object parameters)} mapped parameters setting method.
*
* @throws ExecutionException when database query failed
* @throws InterruptedException if the current thread was interrupted
*/
@Test
public void testGetMappedNamedParam() throws ExecutionException, InterruptedException {
RangePoJo range = new RangePoJo(0, 2);
Optional<DbRow> maybeRow = DB_CLIENT.execute(exec -> exec.createNamedGet("select-pokemons-idrng-named-arg").namedParam(range).execute()).toCompletableFuture().get();
verifyPokemonsIdRange(maybeRow, 0, 2);
}
Aggregations