Search in sources :

Example 1 with RemoteTestException

use of io.helidon.tests.integration.tools.service.RemoteTestException 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 RemoteTestException

use of io.helidon.tests.integration.tools.service.RemoteTestException in project helidon by oracle.

the class HealthCheckService method testHealthCheckWithCustomDML.

// Verify health check implementation using custom DML statement.
private void testHealthCheckWithCustomDML(final ServerRequest request, final ServerResponse response) {
    LOGGER.fine(() -> "Running test HealthCheckService.testHealthCheckWithCustomDML on server");
    Config cfgStatement = dbConfig.get("statements.ping-dml");
    if (!cfgStatement.exists()) {
        response.send(exceptionStatus(new RemoteTestException("Missing statements.ping-dml configuration parameter.")));
        return;
    }
    Thread thread = new Thread(new HealthCheckThread(request, response, DbClientHealthCheck.builder(dbClient()).dml().statement(cfgStatement.as(String.class).get()).build()));
    thread.start();
}
Also used : Config(io.helidon.config.Config) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException)

Example 3 with RemoteTestException

use of io.helidon.tests.integration.tools.service.RemoteTestException in project helidon by oracle.

the class HealthCheckService method testHealthCheckWithCustomQuery.

// Verify health check implementation using custom query statement.
private void testHealthCheckWithCustomQuery(final ServerRequest request, final ServerResponse response) {
    LOGGER.fine(() -> "Running test HealthCheckService.testHealthCheckWithCustomQuery on server");
    Config cfgStatement = dbConfig.get("statements.ping-query");
    if (!cfgStatement.exists()) {
        response.send(exceptionStatus(new RemoteTestException("Missing statements.ping-query configuration parameter.")));
        return;
    }
    Thread thread = new Thread(new HealthCheckThread(request, response, DbClientHealthCheck.builder(dbClient()).query().statement(cfgStatement.as(String.class).get()).build()));
    thread.start();
}
Also used : Config(io.helidon.config.Config) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException)

Example 4 with RemoteTestException

use of io.helidon.tests.integration.tools.service.RemoteTestException in project helidon by oracle.

the class SimpleInsertService method executeTest.

// Common test execution code
private void executeTest(final ServerRequest request, final ServerResponse response, final String testName, final String pokemonName, final List<Type> pokemonTypes, final TestFunction test) {
    LOGGER.fine(() -> String.format("Running SimpleInsertService.%s on server", testName));
    try {
        String idStr = param(request, QUERY_ID_PARAM);
        int id = Integer.parseInt(idStr);
        Pokemon pokemon = new Pokemon(id, pokemonName, pokemonTypes);
        test.apply(pokemon).thenAccept(result -> response.send(AppResponse.okStatus(pokemon.toJsonObject()))).exceptionally(t -> {
            response.send(AppResponse.exceptionStatus(t));
            return null;
        });
    } catch (RemoteTestException | NumberFormatException ex) {
        LOGGER.fine(() -> String.format("Error in SimpleInsertService.%s on server", testName));
        response.send(AppResponse.exceptionStatus(ex));
    }
}
Also used : TYPES(io.helidon.tests.integration.dbclient.appl.model.Type.TYPES) AbstractService(io.helidon.tests.integration.dbclient.appl.AbstractService) Logger(java.util.logging.Logger) Function(java.util.function.Function) ServerRequest(io.helidon.webserver.ServerRequest) Type(io.helidon.tests.integration.dbclient.appl.model.Type) List(java.util.List) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) AppResponse(io.helidon.tests.integration.tools.service.AppResponse) Map(java.util.Map) 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 5 with RemoteTestException

use of io.helidon.tests.integration.tools.service.RemoteTestException 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;
}
Also used : DbRow(io.helidon.dbclient.DbRow) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException)

Aggregations

RemoteTestException (io.helidon.tests.integration.tools.service.RemoteTestException)18 DbClient (io.helidon.dbclient.DbClient)9 AppResponse (io.helidon.tests.integration.tools.service.AppResponse)9 Routing (io.helidon.webserver.Routing)9 ServerRequest (io.helidon.webserver.ServerRequest)9 ServerResponse (io.helidon.webserver.ServerResponse)9 Logger (java.util.logging.Logger)9 Single (io.helidon.common.reactive.Single)8 AbstractService (io.helidon.tests.integration.dbclient.appl.AbstractService)8 Pokemon (io.helidon.tests.integration.dbclient.appl.model.Pokemon)8 JsonArrayBuilder (jakarta.json.JsonArrayBuilder)8 JsonObject (jakarta.json.JsonObject)8 Map (java.util.Map)8 Function (java.util.function.Function)8 DbRow (io.helidon.dbclient.DbRow)7 AppResponse.exceptionStatus (io.helidon.tests.integration.tools.service.AppResponse.exceptionStatus)7 Json (jakarta.json.Json)7 Config (io.helidon.config.Config)6 List (java.util.List)6 Type (io.helidon.tests.integration.dbclient.appl.model.Type)5