Search in sources :

Example 1 with Pokemon

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;
}
Also used : AbstractService(io.helidon.tests.integration.dbclient.appl.AbstractService) Logger(java.util.logging.Logger) Function(java.util.function.Function) Json(jakarta.json.Json) ServerRequest(io.helidon.webserver.ServerRequest) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException) AppResponse.exceptionStatus(io.helidon.tests.integration.tools.service.AppResponse.exceptionStatus) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) AppResponse(io.helidon.tests.integration.tools.service.AppResponse) Map(java.util.Map) JsonObject(jakarta.json.JsonObject) ServerResponse(io.helidon.webserver.ServerResponse) Single(io.helidon.common.reactive.Single) DbClient(io.helidon.dbclient.DbClient) Routing(io.helidon.webserver.Routing) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException)

Example 2 with Pokemon

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());
}
Also used : DbClientHealthCheck(io.helidon.dbclient.health.DbClientHealthCheck) Config(io.helidon.config.Config) CompletableFuture(java.util.concurrent.CompletableFuture) Logger(java.util.logging.Logger) Supplier(java.util.function.Supplier) Json(jakarta.json.Json) ServerRequest(io.helidon.webserver.ServerRequest) Type(io.helidon.tests.integration.dbclient.appl.model.Type) JsonObjectBuilder(jakarta.json.JsonObjectBuilder) HealthCheckResponse(org.eclipse.microprofile.health.HealthCheckResponse) AppResponse.exceptionStatus(io.helidon.tests.integration.tools.service.AppResponse.exceptionStatus) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) Map(java.util.Map) ServerResponse(io.helidon.webserver.ServerResponse) Single(io.helidon.common.reactive.Single) AppResponse.okStatus(io.helidon.tests.integration.tools.service.AppResponse.okStatus) Service(io.helidon.webserver.Service) DbClient(io.helidon.dbclient.DbClient) Routing(io.helidon.webserver.Routing) HealthCheck(org.eclipse.microprofile.health.HealthCheck) Type(io.helidon.tests.integration.dbclient.appl.model.Type) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) Map(java.util.Map)

Example 3 with Pokemon

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()));
    }
}
Also used : JsonValue(jakarta.json.JsonValue) JsonObject(jakarta.json.JsonObject) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon)

Example 4 with Pokemon

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);
    });
}
Also used : JsonArray(jakarta.json.JsonArray) JsonObject(jakarta.json.JsonObject) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon)

Example 5 with 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);
}
Also used : JsonObject(jakarta.json.JsonObject) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) Test(org.junit.jupiter.api.Test)

Aggregations

Pokemon (io.helidon.tests.integration.dbclient.appl.model.Pokemon)17 JsonObject (jakarta.json.JsonObject)14 Single (io.helidon.common.reactive.Single)9 DbClient (io.helidon.dbclient.DbClient)9 Routing (io.helidon.webserver.Routing)9 ServerRequest (io.helidon.webserver.ServerRequest)9 ServerResponse (io.helidon.webserver.ServerResponse)9 Map (java.util.Map)9 Logger (java.util.logging.Logger)9 AbstractService (io.helidon.tests.integration.dbclient.appl.AbstractService)8 AppResponse (io.helidon.tests.integration.tools.service.AppResponse)8 RemoteTestException (io.helidon.tests.integration.tools.service.RemoteTestException)8 Function (java.util.function.Function)8 AppResponse.exceptionStatus (io.helidon.tests.integration.tools.service.AppResponse.exceptionStatus)7 Json (jakarta.json.Json)7 Type (io.helidon.tests.integration.dbclient.appl.model.Type)6 List (java.util.List)6 TYPES (io.helidon.tests.integration.dbclient.appl.model.Type.TYPES)5 JsonValue (jakarta.json.JsonValue)4 Multi (io.helidon.common.reactive.Multi)3