use of io.helidon.tests.integration.dbclient.appl.model.Pokemon in project helidon by oracle.
the class TransactionUpdateService 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 SimpleUpdateService.%s on server", testName));
try {
String name = param(request, QUERY_NAME_PARAM);
String idStr = param(request, QUERY_ID_PARAM);
int id = Integer.parseInt(idStr);
Pokemon srcPokemon = Pokemon.POKEMONS.get(id);
Pokemon updatedPokemon = new Pokemon(id, name, srcPokemon.getTypesArray());
test.apply(updatedPokemon).thenAccept(result -> response.send(AppResponse.okStatus(Json.createValue(result)))).exceptionally(t -> {
response.send(exceptionStatus(t));
return null;
});
} catch (RemoteTestException | NumberFormatException ex) {
LOGGER.fine(() -> String.format("Error in SimpleUpdateService.%s on server", testName));
response.send(exceptionStatus(ex));
}
return null;
}
use of io.helidon.tests.integration.dbclient.appl.model.Pokemon in project helidon by oracle.
the class InitService method testInitPokemonTypes.
// Initialize pokemon types relation
private void testInitPokemonTypes(final ServerRequest request, final ServerResponse response) {
LOGGER.fine(() -> "Running InitResource.testInitPokemonTypes on server");
sendDmlResponse(response, () -> dbClient.inTransaction(tx -> {
Single<Long> stage = null;
for (Map.Entry<Integer, Pokemon> entry : Pokemon.POKEMONS.entrySet()) {
Pokemon pokemon = entry.getValue();
for (Type type : pokemon.getTypes()) {
if (stage == null) {
stage = tx.namedDml("insert-poketype", pokemon.getId(), type.getId());
} else {
stage = stage.flatMapSingle(result -> tx.namedDml("insert-poketype", pokemon.getId(), type.getId()));
}
}
}
return stage;
}).toCompletableFuture());
}
use of io.helidon.tests.integration.dbclient.appl.model.Pokemon in project helidon by oracle.
the class DmlStatementIT method executeTest.
// Test executor method
private void executeTest(final String testName, final int id, final String newName) {
LOGGER.fine(() -> String.format("Running %s", testName));
try {
Pokemon pokemon = Pokemon.POKEMONS.get(id);
Pokemon updatedPokemon = new Pokemon(pokemon.getId(), newName, pokemon.getTypes());
JsonValue data = testClient.callServiceAndGetData(testName, QueryParams.builder().add(QueryParams.NAME, newName).add(QueryParams.ID, String.valueOf(id)).build());
Long count = JsonTools.getLong(data);
LOGGER.fine(() -> String.format("Rows modified: %d", count));
JsonObject pokemonData = VerifyData.getPokemon(testClient, pokemon.getId());
LogData.logJsonObject(Level.FINER, pokemonData);
assertThat(count, equalTo(1L));
VerifyData.verifyPokemon(pokemonData, updatedPokemon);
} catch (Exception e) {
LOGGER.log(Level.WARNING, e, () -> String.format("Exception in %s: %s", testName, e.getMessage()));
}
}
use of io.helidon.tests.integration.dbclient.appl.model.Pokemon in project helidon by oracle.
the class QueryStatementIT method executeTest.
// Test executor method
private void executeTest(final String testName, final int fromId, final int toId) {
LOGGER.fine(() -> String.format("Running %s", testName));
JsonArray data = testClient.callServiceAndGetData(testName, QueryParams.builder().add(QueryParams.FROM_ID, String.valueOf(fromId)).add(QueryParams.TO_ID, String.valueOf(toId)).build()).asJsonArray();
LogData.logJsonArray(Level.FINER, data);
assertThat(data.size(), equalTo(toId - fromId - 1));
data.getValuesAs(JsonObject.class).forEach(dataPokemon -> {
int id = dataPokemon.getInt("id");
final Pokemon pokemon = Pokemon.POKEMONS.get(id);
assertThat(id, greaterThan(fromId));
assertThat(id, lessThan(toId));
VerifyData.verifyPokemon(dataPokemon, pokemon);
});
}
use of io.helidon.tests.integration.dbclient.appl.model.Pokemon in project helidon by oracle.
the class MapperIT method testGetWithMapping.
/**
* Verify get of PoJo instance as a result using mapping.
*/
@Test
public void testGetWithMapping() {
LOGGER.fine(() -> "Running testGetWithMapping");
final Pokemon pokemon = Pokemon.POKEMONS.get(2);
JsonObject data = testClient.callServiceAndGetData("testGetWithMapping", QueryParams.single(QueryParams.NAME, pokemon.getName())).asJsonObject();
LogData.logJsonObject(Level.FINER, data);
VerifyData.verifyPokemon(data, pokemon);
}
Aggregations