diff --git a/all/pom.xml b/all/pom.xml index 7bf40904ed8..8a423d9567e 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -595,6 +595,10 @@ io.helidon.integrations.db helidon-integrations-db-mysql + + io.helidon.integrations.db + helidon-integrations-db-pgsql + io.helidon.integrations.cdi helidon-integrations-cdi-configurable diff --git a/bom/pom.xml b/bom/pom.xml index adddfc941d6..b5532308d1a 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -793,6 +793,11 @@ helidon-integrations-db-mysql ${helidon.version} + + io.helidon.integrations.db + helidon-integrations-db-pgsql + ${helidon.version} + io.helidon.integrations.cdi helidon-integrations-cdi-configurable diff --git a/dependencies/pom.xml b/dependencies/pom.xml index 6694d157097..cc8c1d3e252 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -1304,6 +1304,11 @@ mysql ${version.lib.testcontainers} + + org.testcontainers + jdbc + ${version.lib.testcontainers} + org.testcontainers oracle-xe diff --git a/docs/pom.xml b/docs/pom.xml index feebb6ebea1..dbce12da1a4 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -52,6 +52,7 @@ mockito-core + org.apache.activemq activemq-client @@ -80,6 +81,11 @@ ${version.lib.jbatch.container} true + + org.postgresql + postgresql + true + diff --git a/etc/copyright-exclude.txt b/etc/copyright-exclude.txt index 3c4b0e2df76..cf1dcc364f8 100644 --- a/etc/copyright-exclude.txt +++ b/etc/copyright-exclude.txt @@ -67,3 +67,4 @@ src/test/resources/static/classpath/index.html ._java_ ._inject_ service.loader +.repo diff --git a/etc/pods/mysql.yaml b/etc/pods/mysql.yaml deleted file mode 100644 index 40f46b5aa62..00000000000 --- a/etc/pods/mysql.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# -# Copyright (c) 2018, 2020 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -apiVersion: v1 -kind: Pod -metadata: - name: mysql -spec: - containers: - - name: mysql - image: mysql:8 - ports: - - containerPort: 3306 - env: - - name: MYSQL_USER - value: "user" - - name: MYSQL_PASSWORD - value: "password" - - name: MYSQL_ROOT_PASSWORD - value: "root" - - name: MYSQL_DATABASE - value: "pokemon" diff --git a/etc/pods/vault.yaml b/etc/pods/vault.yaml deleted file mode 100644 index ad21996bc48..00000000000 --- a/etc/pods/vault.yaml +++ /dev/null @@ -1,44 +0,0 @@ -# -# Copyright (c) 2021 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -apiVersion: v1 -kind: Pod -metadata: - name: vault -spec: - containers: - - name: mysql - image: mysql:8 - imagePullPolicy: "IfNotPresent" - ports: - - containerPort: 3306 - env: - - name: MYSQL_USER - value: "user" - - name: MYSQL_PASSWORD - value: "password" - - name: MYSQL_ROOT_PASSWORD - value: "root" - - name: MYSQL_DATABASE - value: "pokemon" - - name: vault - image: vault:1.7.0 - imagePullPolicy: "IfNotPresent" - ports: - - containerPort: 8200 - env: - - name: VAULT_DEV_ROOT_TOKEN_ID - value: "myroot" \ No newline at end of file diff --git a/tests/integration/dbclient/app/pom.xml b/tests/integration/dbclient/app/pom.xml deleted file mode 100644 index 0b01742c984..00000000000 --- a/tests/integration/dbclient/app/pom.xml +++ /dev/null @@ -1,265 +0,0 @@ - - - - 4.0.0 - - io.helidon.applications - helidon-se - 4.1.0-SNAPSHOT - ../../../../applications/se/pom.xml - - io.helidon.tests.integration.dbclient - helidon-tests-integration-dbclient-app - 4.1.0-SNAPSHOT - Helidon Tests Integration Database Client Application - - - io.helidon.tests.integration.dbclient.app.Main - true - 1.9.3 - - - - - io.helidon.webserver - helidon-webserver - - - io.helidon.webserver.observe - helidon-webserver-observe-health - - - io.helidon.webserver.observe - helidon-webserver-observe-metrics - - - io.helidon.config - helidon-config - - - io.helidon.config - helidon-config-yaml - - - io.helidon.logging - helidon-logging-jul - - - io.helidon.dbclient - helidon-dbclient-jdbc - - - io.helidon.dbclient - helidon-dbclient-hikari - - - io.helidon.dbclient - helidon-dbclient-health - - - io.helidon.dbclient - helidon-dbclient-metrics - - - io.helidon.dbclient - helidon-dbclient-metrics-hikari - - - io.helidon.tests.integration.dbclient - helidon-tests-integration-dbclient-common - ${project.version} - - - io.helidon.tests.integration - helidon-tests-integration-harness - ${project.version} - - - org.eclipse.parsson - parsson - - - org.slf4j - slf4j-jdk14 - - - io.helidon.webclient - helidon-webclient - test - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.platform - junit-platform-suite-engine - ${version.lib.junit-suite} - test - - - org.hamcrest - hamcrest-all - test - - - - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-libs - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*IT - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - false - methods - 10 - - true - ${app.config} - ${db.user} - ${db.password} - ${db.url} - - - - - test - integration-test - - integration-test - verify - - - - **/*SuiteIT - - - - - - - - - - native-image - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - native - - - - - - - - h2 - - - !db - - - - h2.yaml - test - sa - - jdbc:h2:mem:${db.database};INIT=SET TRACE_LEVEL_FILE=2;DATABASE_TO_UPPER=FALSE - - - - io.helidon.integrations.db - h2 - - - com.h2database - h2 - - - - - mysql - - - db - mysql - - - - - io.helidon.integrations.db - helidon-integrations-db-mysql - ${project.version} - - - com.mysql - mysql-connector-j - - - - - pgsql - - - db - pgsql - - - - - io.helidon.integrations.db - helidon-integrations-db-pgsql - ${project.version} - - - org.postgresql - postgresql - - - - - diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/ErrorHandlerImpl.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/ErrorHandlerImpl.java deleted file mode 100644 index f62cb574ff7..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/ErrorHandlerImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app; - -import io.helidon.webserver.http.ErrorHandler; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; - -import static io.helidon.tests.integration.harness.AppResponse.exceptionStatus; - -/** - * Error handler. - */ -class ErrorHandlerImpl implements ErrorHandler { - - /** - * Singleton. - */ - static final ErrorHandler INSTANCE = new ErrorHandlerImpl(); - - private ErrorHandlerImpl() { - } - - @Override - public void handle(ServerRequest req, ServerResponse res, Throwable th) { - th.printStackTrace(); - res.send(exceptionStatus(th)); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/InitService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/InitService.java deleted file mode 100644 index 9255caf9b96..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/InitService.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app; - -import java.lang.System.Logger.Level; -import java.util.List; -import java.util.Map; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbClientException; -import io.helidon.dbclient.DbExecute; -import io.helidon.dbclient.DbTransaction; -import io.helidon.dbclient.health.DbClientHealthCheck; -import io.helidon.health.HealthCheck; -import io.helidon.health.HealthCheckResponse; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.HttpService; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.model.Type; - -import jakarta.json.Json; -import jakarta.json.JsonObjectBuilder; - -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Service for tests initialization services. - */ -public class InitService implements HttpService { - - private static final System.Logger LOGGER = System.getLogger(InitService.class.getName()); - - private final DbClient dbClient; - private final Config dbConfig; - - /** - * Creates an instance of web resource for tests initialization services. - * - * @param dbClient DbClient instance - * @param dbConfig testing application configuration - */ - InitService(DbClient dbClient, Config dbConfig) { - this.dbClient = dbClient; - this.dbConfig = dbConfig; - } - - @Override - public void routing(HttpRules rules) { - rules - .get("/testPing", this::testPing) - .get("/testHealthCheck", this::testHealthCheck) - .get("/testDropSchema", this::testDropSchema) - .get("/testInitSchema", this::testInitSchema) - .get("/testInitTypes", this::testInitTypes) - .get("/testInitPokemons", this::testInitPokemons) - .get("/testInitPokemonTypes", this::testInitPokemonTypes); - } - - private void testPing(ServerRequest request, ServerResponse response) { - boolean ping = dbConfig.get("test.ping-dml") - .map(c -> c.asBoolean().get()) - .orElse(false); - JsonObjectBuilder data = Json.createObjectBuilder(); - data.add("ping-dml", ping); - response.send(okStatus(data.build())); - } - - private void testHealthCheck(ServerRequest request, ServerResponse response) { - HealthCheck check = DbClientHealthCheck.create( - dbClient, - dbConfig.get("health-check")); - HealthCheckResponse checkResponse = check.call(); - HealthCheckResponse.Status checkState = checkResponse.status(); - JsonObjectBuilder data = Json.createObjectBuilder(); - data.add("state", checkState.name()); - response.send(okStatus(data.build())); - } - - private void testDropSchema(ServerRequest request, ServerResponse response) { - DbExecute exec = dbClient.execute(); - long count = 0; - for (String schema : List.of("poketypes", "pokemons", "types")) { - String statementName = "drop-" + schema; - try { - count += exec.namedDml(statementName); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format( - "Unable to execute statement: %s, %s", - statementName, - ex.getMessage())); - } - } - response.send(okStatus(Json.createValue(count))); - } - - private void testInitSchema(ServerRequest request, ServerResponse response) { - DbExecute exec = dbClient.execute(); - long count = 0; - for (String schema : List.of("types", "pokemons", "poketypes")) { - String statementName = "create-" + schema; - try { - count += exec.namedDml(statementName); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format( - "Unable to execute statement: %s, %s", - statementName, - ex.getMessage())); - } - } - response.send(okStatus(Json.createValue(count))); - } - - private void testInitTypes(ServerRequest request, ServerResponse response) { - DbTransaction tx = dbClient.transaction(); - long count = 0; - for (Map.Entry entry : Type.TYPES.entrySet()) { - count += tx.namedDml("insert-type", entry.getKey(), entry.getValue().name()); - } - tx.commit(); - response.send(okStatus(Json.createValue(count))); - } - - private void testInitPokemons(ServerRequest request, ServerResponse response) { - DbTransaction tx = dbClient.transaction(); - long count = 0; - for (Map.Entry entry : Pokemon.POKEMONS.entrySet()) { - count += tx.namedDml("insert-pokemon", entry.getKey(), entry.getValue().getName()); - } - tx.commit(); - response.send(okStatus(Json.createValue(count))); - } - - private void testInitPokemonTypes(ServerRequest request, ServerResponse response) { - DbTransaction tx = dbClient.transaction(); - long count = 0; - for (Map.Entry entry : Pokemon.POKEMONS.entrySet()) { - Pokemon pokemon = entry.getValue(); - for (Type type : pokemon.getTypes()) { - count += tx.namedDml("insert-poketype", pokemon.getId(), type.id()); - } - } - tx.commit(); - response.send(okStatus(Json.createValue(count))); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/Main.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/Main.java deleted file mode 100644 index 4f6cf0c0ce9..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/Main.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app; - -import java.lang.System.Logger.Level; -import java.util.Map; - -import io.helidon.config.Config; -import io.helidon.config.ConfigSources; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbClientException; -import io.helidon.dbclient.DbClientService; -import io.helidon.dbclient.DbStatementType; -import io.helidon.dbclient.health.DbClientHealthCheck; -import io.helidon.dbclient.metrics.DbClientMetrics; -import io.helidon.metrics.api.MetricsFactory; -import io.helidon.tests.integration.dbclient.app.tests.FlowControlService; -import io.helidon.tests.integration.dbclient.app.tests.HealthCheckService; -import io.helidon.tests.integration.dbclient.app.tests.InterceptorService; -import io.helidon.tests.integration.dbclient.app.tests.MapperService; -import io.helidon.tests.integration.dbclient.app.tests.SimpleDeleteService; -import io.helidon.tests.integration.dbclient.app.tests.SimpleGetService; -import io.helidon.tests.integration.dbclient.app.tests.SimpleInsertService; -import io.helidon.tests.integration.dbclient.app.tests.SimpleQueryService; -import io.helidon.tests.integration.dbclient.app.tests.SimpleUpdateService; -import io.helidon.tests.integration.dbclient.app.tests.StatementDmlService; -import io.helidon.tests.integration.dbclient.app.tests.StatementGetService; -import io.helidon.tests.integration.dbclient.app.tests.StatementQueryService; -import io.helidon.tests.integration.dbclient.app.tests.TransactionDeleteService; -import io.helidon.tests.integration.dbclient.app.tests.TransactionGetService; -import io.helidon.tests.integration.dbclient.app.tests.TransactionInsertService; -import io.helidon.tests.integration.dbclient.app.tests.TransactionQueryService; -import io.helidon.tests.integration.dbclient.app.tests.TransactionUpdateService; -import io.helidon.tests.integration.dbclient.app.tools.ExitService; -import io.helidon.tests.integration.harness.RemoteTestException; -import io.helidon.webserver.WebServer; -import io.helidon.webserver.observe.ObserveFeature; -import io.helidon.webserver.observe.health.HealthObserver; - -/** - * Main class. - * Testing application entry point. - */ -public class Main { - - private static final System.Logger LOGGER = System.getLogger(Main.class.getName()); - private static final String CONFIG_PROPERTY_NAME = "app.config"; - private static final String DEFAULT_CONFIG_FILE = "test.yaml"; - - /** - * Start the server. - * - * @param configFile config file - * @return server - */ - public static WebServer startServer(String configFile) { - - Config config = Config.create(ConfigSources.classpath("common.yaml"), - ConfigSources.classpath(configFile)); - Config.global(config); - - Config dbConfig = config.get("db"); - MetricsFactory.getInstance(config.get("metrics")); - - // Client services are added through a service loader - see mongoDB example for explicit services - DbClient dbClient = DbClient.builder(dbConfig) - .addService(DbClientMetrics.counter() - .statementNames( - "select-pokemon-named-arg", - "select-pokemon-order-arg", - "insert-pokemon")) - .addService(DbClientMetrics.timer().statementTypes(DbStatementType.GET)) - .build(); - - HealthObserver health = HealthObserver.builder() - .addCheck(DbClientHealthCheck.builder(dbClient) - .statementName("ping-query") - .build()) - .build(); - - Map statements = dbConfig.get("statements") - .detach() - .asMap() - .get(); - - ExitService exitResource = new ExitService(); - - DbClientService interceptorTestService = new InterceptorService.TestClientService(); - - // Prepare routing for the server - WebServer server = WebServer.builder() - .featuresDiscoverServices(false) - .addFeature(ObserveFeature.builder().addObserver(health).build()) - .routing(routing -> routing - .register("/Init", new InitService(dbClient, dbConfig)) - .register("/Exit", exitResource) - .register("/Verify", new VerifyService(dbClient, config)) - .register("/SimpleGet", new SimpleGetService(dbClient, statements)) - .register("/SimpleQuery", new SimpleQueryService(dbClient, statements)) - .register("/SimpleUpdate", new SimpleUpdateService(dbClient, statements)) - .register("/SimpleInsert", new SimpleInsertService(dbClient, statements)) - .register("/SimpleDelete", new SimpleDeleteService(dbClient, statements)) - .register("/TransactionGet", new TransactionGetService(dbClient, statements)) - .register("/TransactionQueries", new TransactionQueryService(dbClient, statements)) - .register("/TransactionUpdate", new TransactionUpdateService(dbClient, statements)) - .register("/TransactionInsert", new TransactionInsertService(dbClient, statements)) - .register("/TransactionDelete", new TransactionDeleteService(dbClient, statements)) - .register("/StatementDml", new StatementDmlService(dbClient, statements)) - .register("/StatementGet", new StatementGetService(dbClient, statements)) - .register("/StatementQuery", new StatementQueryService(dbClient, statements)) - .register("/FlowControl", new FlowControlService(dbClient, statements)) - .register("/Mapper", new MapperService(dbClient, statements)) - .register("/Interceptor", new InterceptorService( - DbClient.builder(dbConfig) - .addService(interceptorTestService).build(), - statements, - interceptorTestService)) - .register("/HealthCheck", new HealthCheckService(dbClient, dbConfig, statements)) - .error(DbClientException.class, ErrorHandlerImpl.INSTANCE) - .error(RemoteTestException.class, ErrorHandlerImpl.INSTANCE)) - .config(config.get("server")) - .build() - .start(); - - exitResource.setServer(server); - - // Start the server and print some info. - System.out.println("WEB server is up! http://localhost:" + server.port() + "/"); - - return server; - } - - /** - * Main method. - * - * @param args command line arguments - */ - public static void main(String[] args) { - String configFile; - if (args != null && args.length > 0) { - configFile = args[0]; - } else { - configFile = System.getProperty(CONFIG_PROPERTY_NAME, DEFAULT_CONFIG_FILE); - } - LOGGER.log(Level.INFO, () -> String.format("Configuration file: %s", configFile)); - startServer(configFile); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/VerifyService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/VerifyService.java deleted file mode 100644 index 20dfe368832..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/VerifyService.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbExecute; -import io.helidon.tests.integration.dbclient.app.tests.AbstractService; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.HttpService; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; - -import jakarta.json.Json; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; - -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Service for test data verification. - */ -public class VerifyService implements HttpService { - - private final DbClient dbClient; - private final Config config; - - VerifyService(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - @Override - public void routing(HttpRules rules) { - rules.get("/getPokemonById", this::getPokemonById) - .get("/getDatabaseType", this::getDatabaseType) - .get("/getConfigParam", this::getConfigParam); - } - - private void getPokemonById(ServerRequest request, ServerResponse response) { - DbExecute exec = dbClient.execute(); - String idStr = AbstractService.queryParam(request, QueryParams.ID); - int id = Integer.parseInt(idStr); - JsonObject jsonObject = exec - .namedGet("get-pokemon-by-id", id) - .map(row -> Json.createObjectBuilder() - .add("name", row.column("name").getString()) - .add("id", row.column("id").getInt()) - .add("types", exec.namedQuery("get-pokemon-types", id) - .map(typeRow -> typeRow.as(JsonObject.class)) - .collect( - Json::createArrayBuilder, - JsonArrayBuilder::add, - JsonArrayBuilder::add) - .build()) - .build()) - .orElse(JsonObject.EMPTY_JSON_OBJECT); - response.send(okStatus(jsonObject)); - } - - private void getDatabaseType(ServerRequest request, ServerResponse response) { - JsonObjectBuilder job = Json.createObjectBuilder(); - job.add("type", dbClient.dbType()); - response.send(okStatus(job.build())); - } - - private void getConfigParam(ServerRequest request, ServerResponse response) { - String name = AbstractService.queryParam(request, QueryParams.NAME); - Config node = config.get(name); - JsonObjectBuilder job = Json.createObjectBuilder(); - if (!node.exists()) { - response.send(okStatus(job.build())); - return; - } - job.add("config", node.as(String.class).get()); - response.send(okStatus(job.build())); - } - -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/dbmapper/DbClientMapperProvider.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/dbmapper/DbClientMapperProvider.java deleted file mode 100644 index 687a3e3d864..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/dbmapper/DbClientMapperProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.dbmapper; - -import java.util.Optional; - -import io.helidon.dbclient.DbMapper; -import io.helidon.dbclient.spi.DbMapperProvider; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.model.RangePoJo; - -import jakarta.json.JsonObject; - -/** - * Provides Database Client mappers. - */ -public class DbClientMapperProvider implements DbMapperProvider { - - @Override - public Optional> mapper(Class type) { - if (type.equals(JsonObject.class)) { - return Optional.of((DbMapper)DbRowToJsonObjectMapper.getInstance()); - } else if (type.equals(RangePoJo.class)) { - return Optional.of((DbMapper) RangePoJo.Mapper.INSTANCE); - } else if (type.equals(Pokemon.class)) { - return Optional.of((DbMapper) Pokemon.PokemonMapper.INSTANCE); - } else { - return Optional.empty(); - } - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/dbmapper/DbRowToJsonObjectMapper.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/dbmapper/DbRowToJsonObjectMapper.java deleted file mode 100644 index 4aa2702eae6..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/dbmapper/DbRowToJsonObjectMapper.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.dbmapper; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.BiConsumer; - -import io.helidon.dbclient.DbColumn; -import io.helidon.dbclient.DbMapper; -import io.helidon.dbclient.DbRow; - -import jakarta.json.Json; -import jakarta.json.JsonNumber; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; -import jakarta.json.JsonValue; - -// This implementation is limited only to conversions required by jUnit tests. -/** - * Mapper for DbRow to JsonObject conversion. - */ -public class DbRowToJsonObjectMapper implements DbMapper { - - private static final DbRowToJsonObjectMapper INSTANCE = new DbRowToJsonObjectMapper(); - - // Conversion is based on code used in EclipseLink: - // https://github.com/eclipse-ee4j/eclipselink/blob/master/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/helper/ConversionManager.java#L164 - // https://github.com/eclipse-ee4j/eclipselink/blob/master/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/databaseaccess/DatabaseAccessor.java#L1347 - private static final Map, BiConsumer> MAPPERS = new HashMap<>(); - - public static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd"); - public static final SimpleDateFormat TIME_FORMATTER = new SimpleDateFormat("HH:mm:ss"); - public static final SimpleDateFormat DATE_TIME_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - - static { - MAPPERS.put(Byte.class, (job, column) -> job.add(column.name(), column.get(Byte.class).intValue())); - MAPPERS.put(Short.class, (job, column) -> job.add(column.name(), column.get(Short.class).intValue())); - MAPPERS.put(Integer.class, (job, column) -> job.add(column.name(), column.get(Integer.class))); - MAPPERS.put(Long.class, (job, column) -> job.add(column.name(), column.get(Long.class))); - MAPPERS.put(Float.class, (job, column) -> job.add(column.name(), column.get(Float.class).doubleValue())); - MAPPERS.put(Double.class, (job, column) -> job.add(column.name(), column.get(Double.class))); - MAPPERS.put(BigInteger.class, (job, column) -> job.add(column.name(), column.get(BigInteger.class))); - MAPPERS.put(BigDecimal.class, (job, column) -> job.add(column.name(), column.get(BigDecimal.class))); - MAPPERS.put(String.class, (job, column) -> job.add(column.name(), column.get(String.class))); - MAPPERS.put(Character.class, (job, column) -> job.add(column.name(), column.get(Character.class).toString())); - MAPPERS.put(Boolean.class, (job, column) -> job.add(column.name(), column.get(Boolean.class))); - MAPPERS.put(java.sql.Date.class, (job, column) -> job.add(column.name(), DATE_FORMATTER.format(column.as(java.sql.Date.class)))); - MAPPERS.put(java.sql.Time.class, (job, column) -> job.add(column.name(), TIME_FORMATTER.format(column.as(java.sql.Time.class)))); - MAPPERS.put(java.sql.Timestamp.class, (job, column) -> job.add(column.name(), DATE_TIME_FORMATTER.format(column.as(java.sql.Timestamp.class)))); - MAPPERS.put(java.util.Date.class, (job, column) -> job.add(column.name(), DATE_TIME_FORMATTER.format(column.as(java.util.Date.class)))); - } - - static final DbRowToJsonObjectMapper getInstance() { - return INSTANCE; - } - - @Override - public JsonObject read(DbRow dbRow) { - JsonObjectBuilder job = Json.createObjectBuilder(); - dbRow.forEach((dbColumn) -> { - BiConsumer mapper = MAPPERS.get(dbColumn.javaType()); - if (mapper != null) { - mapper.accept(job, dbColumn); - } else { - job.add(dbColumn.name(), dbColumn.get().toString()); - } - }); - return job.build(); - } - - @Override - public Map toNamedParameters(JsonObject value) { - Map params = new HashMap<>(value.size()); - for (Map.Entry entry : value.entrySet()) { - switch(entry.getValue().getValueType()) { - case STRING: - params.put(entry.getKey(), entry.getValue().toString()); - break; - case NUMBER: - JsonNumber numberValue = (JsonNumber)entry.getValue(); - if (numberValue.isIntegral()) { - params.put(entry.getKey(), numberValue.bigIntegerValue()); - } else { - params.put(entry.getKey(), numberValue.bigDecimalValue()); - } - break; - case FALSE: - params.put(entry.getKey(), Boolean.FALSE); - break; - case TRUE: - params.put(entry.getKey(), Boolean.TRUE); - break; - case NULL: - params.put(entry.getKey(), null); - break; - } - } - return params; - } - - @Override - public List toIndexedParameters(JsonObject value) { - List params = new ArrayList<>(value.size()); - for (Map.Entry entry : value.entrySet()) { - switch(entry.getValue().getValueType()) { - case STRING: - params.add(entry.getValue().toString()); - break; - case NUMBER: - JsonNumber numberValue = (JsonNumber)entry.getValue(); - if (numberValue.isIntegral()) { - params.add(numberValue.bigIntegerValue()); - } else { - params.add(numberValue.bigDecimalValue()); - } - break; - case FALSE: - params.add(Boolean.FALSE); - break; - case TRUE: - params.add(Boolean.TRUE); - break; - case NULL: - params.add(null); - break; - } - } - return params; - } - -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractDeleteService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractDeleteService.java deleted file mode 100644 index c3293d7d758..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractDeleteService.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; -import java.util.Map; - -import io.helidon.http.NotFoundException; -import io.helidon.dbclient.DbClient; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; - -import jakarta.json.Json; - -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Base service to test delete statements. - */ -public abstract class AbstractDeleteService extends AbstractService { - - private static final System.Logger LOGGER = System.getLogger(AbstractDeleteService.class.getName()); - - /** - * Creates a new instance. - * - * @param dbClient DbClient instance - * @param statements statements from configuration file - */ - protected AbstractDeleteService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - public void routing(HttpRules rules) { - rules.get("/{testName}", this::executeTest); - } - - private void executeTest(ServerRequest request, ServerResponse response) { - String testName = pathParam(request, "testName"); - int id = Integer.parseInt(queryParam(request, QueryParams.ID)); - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on server", getClass().getSimpleName(), testName)); - long count = switch (testName) { - case "testCreateNamedDeleteStrStrOrderArgs" -> testCreateNamedDeleteStrStrOrderArgs(id); - case "testCreateDmlWithDeleteNamedArgs" -> testCreateDmlWithDeleteNamedArgs(id); - case "testCreateNamedDeleteStrNamedArgs" -> testCreateNamedDeleteStrNamedArgs(id); - case "testCreateNamedDeleteStrOrderArgs" -> testCreateNamedDeleteStrOrderArgs(id); - case "testCreateDeleteNamedArgs" -> testCreateDeleteNamedArgs(id); - case "testCreateDeleteOrderArgs" -> testCreateDeleteOrderArgs(id); - case "testNamedDeleteOrderArgs" -> testNamedDeleteOrderArgs(id); - case "testDeleteOrderArgs" -> testDeleteOrderArgs(id); - case "testCreateNamedDmlWithDeleteStrStrOrderArgs" -> testCreateNamedDmlWithDeleteStrStrOrderArgs(id); - case "testCreateNamedDmlWithDeleteStrNamedArgs" -> testCreateNamedDmlWithDeleteStrNamedArgs(id); - case "testCreateNamedDmlWithDeleteStrOrderArgs" -> testCreateNamedDmlWithDeleteStrOrderArgs(id); - case "testCreateDmlWithDeleteOrderArgs" -> testCreateDmlWithDeleteOrderArgs(id); - case "testNamedDmlWithDeleteOrderArgs" -> testNamedDmlWithDeleteOrderArgs(id); - case "testDmlWithDeleteOrderArgs" -> testDmlWithDeleteOrderArgs(id); - default -> throw new NotFoundException("test not found: " + testName); - }; - response.send(okStatus(Json.createValue(count))); - } - - /** - * Verify {@code createNamedDelete(String, String)} API method with ordered parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testCreateNamedDeleteStrStrOrderArgs(int id); - - /** - * Verify {@code createNamedDelete(String)} API method with named parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testCreateNamedDeleteStrNamedArgs(int id); - - /** - * Verify {@code createNamedDelete(String)} API method with ordered parameters - * - * @param id parameter - * @return count - */ - protected abstract long testCreateNamedDeleteStrOrderArgs(int id); - - /** - * Verify {@code createDelete(String)} API method with named parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testCreateDeleteNamedArgs(int id); - - /** - * Verify {@code createDelete(String)} API method with ordered parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testCreateDeleteOrderArgs(int id); - - /** - * Verify {@code namedDelete(String)} API method with ordered parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testNamedDeleteOrderArgs(int id); - - /** - * Verify {@code delete(String)} API method with ordered parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testDeleteOrderArgs(int id); - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with delete with ordered parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testCreateNamedDmlWithDeleteStrStrOrderArgs(int id); - - /** - * Verify {@code createNamedDmlStatement(String)} API method with delete with named parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testCreateNamedDmlWithDeleteStrNamedArgs(int id); - - /** - * Verify {@code createNamedDmlStatement(String)} API method with delete with ordered parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testCreateNamedDmlWithDeleteStrOrderArgs(int id); - - /** - * Verify {@code createDmlStatement(String)} API method with delete with named parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testCreateDmlWithDeleteNamedArgs(int id); - - /** - * Verify {@code createDmlStatement(String)} API method with delete with ordered parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testCreateDmlWithDeleteOrderArgs(int id); - - /** - * Verify {@code namedDml(String)} API method with delete with ordered parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testNamedDmlWithDeleteOrderArgs(int id); - - /** - * Verify {@code dml(String)} API method with delete with ordered parameters. - * - * @param id parameter - * @return count - */ - protected abstract long testDmlWithDeleteOrderArgs(int id); -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractGetService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractGetService.java deleted file mode 100644 index 6e0bd7266f4..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractGetService.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import io.helidon.http.NotFoundException; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; - -import jakarta.json.JsonObject; - -import java.lang.System.Logger.Level; -import java.util.Map; -import java.util.Optional; - -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Base service to test get statements. - */ -public abstract class AbstractGetService extends AbstractService { - - private static final System.Logger LOGGER = System.getLogger(AbstractGetService.class.getName()); - - /** - * Creates a new instance. - * - * @param dbClient DbClient instance - * @param statements statements from configuration file - */ - public AbstractGetService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - public void routing(HttpRules rules) { - rules.get("/{testName}", this::executeTest); - } - - private void executeTest(ServerRequest request, ServerResponse response) { - String testName = pathParam(request, "testName"); - String name = queryParam(request, QueryParams.NAME); - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on server", getClass().getSimpleName(), testName)); - Optional result = switch (testName) { - case "testCreateNamedGetStrStrNamedArgs" -> testCreateNamedGetStrStrNamedArgs(name); - case "testCreateNamedGetStrNamedArgs" -> testCreateNamedGetStrNamedArgs(name); - case "testCreateNamedGetStrOrderArgs" -> testCreateNamedGetStrOrderArgs(name); - case "testCreateGetNamedArgs" -> testCreateGetNamedArgs(name); - case "testCreateGetOrderArgs" -> testCreateGetOrderArgs(name); - case "testNamedGetStrOrderArgs" -> testNamedGetStrOrderArgs(name); - case "testGetStrOrderArgs" -> testGetStrOrderArgs(name); - default -> throw new NotFoundException("test not found: " + testName); - }; - response.send(okStatus(result.map(row -> row.as(JsonObject.class)) - .orElse(JsonObject.EMPTY_JSON_OBJECT))); - } - - /** - * Verify {@code createNamedGet(String, String)} API method with named parameters. - * - * @param name parameter - * @return row - */ - protected abstract Optional testCreateNamedGetStrStrNamedArgs(String name); - - /** - * Verify {@code createNamedGet(String)} API method with named parameters. - * - * @param name parameter - * @return row - */ - protected abstract Optional testCreateNamedGetStrNamedArgs(String name); - - /** - * Verify {@code createNamedGet(String)} API method with ordered parameters. - * - * @param name parameter - * @return row - */ - protected abstract Optional testCreateNamedGetStrOrderArgs(String name); - - /** - * Verify {@code createGet(String)} API method with named parameters. - * - * @param name parameter - * @return row - */ - protected abstract Optional testCreateGetNamedArgs(String name); - - /** - * Verify {@code createGet(String)} API method with ordered parameters. - * - * @param name parameter - * @return row - */ - protected abstract Optional testCreateGetOrderArgs(String name); - - /** - * Verify {@code namedGet(String)} API method with ordered parameters passed directly to the {@code query} method. - * - * @param name parameter - * @return row - */ - protected abstract Optional testNamedGetStrOrderArgs(String name); - - /** - * Verify {@code get(String)} API method with ordered parameters passed directly to the {@code query} method. - * - * @param name parameter - * @return row - */ - protected abstract Optional testGetStrOrderArgs(String name); - -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractInsertService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractInsertService.java deleted file mode 100644 index 2c1a854cb27..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractInsertService.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import io.helidon.http.NotFoundException; -import io.helidon.dbclient.DbClient; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.model.Type; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Base service to test insert statements. - */ -public abstract class AbstractInsertService extends AbstractService { - - private static final System.Logger LOGGER = System.getLogger(AbstractInsertService.class.getName()); - private static final Map POKEMON_NAMES = Collections.unmodifiableMap(initNames()); - private static final Map> POKEMON_TYPES = Collections.unmodifiableMap(initTypes()); - - @SuppressWarnings("SpellCheckingInspection") - private static Map initNames() { - Map names = new HashMap<>(); - names.put("testCreateNamedInsertStrStrNamedArgs", "Bulbasaur"); - names.put("testCreateNamedInsertStrNamedArgs", "Ivysaur"); - names.put("testCreateNamedInsertStrOrderArgs", "Venusaur"); - names.put("testCreateInsertNamedArgs", "Magby"); - names.put("testCreateInsertOrderArgs", "Magmar"); - names.put("testNamedInsertOrderArgs", "Rattata"); - names.put("testInsertOrderArgs", "Raticate"); - names.put("testCreateNamedDmlWithInsertStrStrNamedArgs", "Torchic"); - names.put("testCreateNamedDmlWithInsertStrNamedArgs", "Combusken"); - names.put("testCreateNamedDmlWithInsertStrOrderArgs", "Treecko"); - names.put("testCreateDmlWithInsertNamedArgs", "Grovyle"); - names.put("testCreateDmlWithInsertOrderArgs", "Sceptile"); - names.put("testNamedDmlWithInsertOrderArgs", "Snover"); - names.put("testDmlWithInsertOrderArgs", "Abomasnow"); - return names; - } - - @SuppressWarnings("SpellCheckingInspection") - private static Map> initTypes() { - Map> types = new HashMap<>(); - types.put("Bulbasaur", List.of(TYPES.get(4), TYPES.get(12))); - types.put("Ivysaur", List.of(TYPES.get(4), TYPES.get(12))); - types.put("Venusaur", List.of(TYPES.get(4), TYPES.get(12))); - types.put("Magby", List.of(TYPES.get(10))); - types.put("Magmar", List.of(TYPES.get(10))); - types.put("Rattata", List.of(TYPES.get(1))); - types.put("Raticate", List.of(TYPES.get(1))); - types.put("Torchic", List.of(TYPES.get(10))); - types.put("Combusken", List.of(TYPES.get(2), TYPES.get(10))); - types.put("Treecko", List.of(TYPES.get(12))); - types.put("Grovyle", List.of(TYPES.get(12))); - types.put("Sceptile", List.of(TYPES.get(12))); - types.put("Snover", List.of(TYPES.get(12), TYPES.get(15))); - types.put("Abomasnow", List.of(TYPES.get(12), TYPES.get(15))); - return types; - } - - /** - * Create a new instance. - * - * @param dbClient dbclient instance - * @param statements statements - */ - public AbstractInsertService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - public void routing(HttpRules rules) { - rules.get("/{testName}", this::executeTest); - } - - private void executeTest(ServerRequest request, ServerResponse response) { - String testName = pathParam(request, "testName"); - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on server", getClass().getSimpleName(), testName)); - int id = Integer.parseInt(queryParam(request, QueryParams.ID)); - String name = POKEMON_NAMES.get(testName); - long count = switch (testName) { - case "testCreateNamedInsertStrStrNamedArgs" -> testCreateNamedInsertStrStrNamedArgs(id, name); - case "testCreateNamedInsertStrNamedArgs" -> testCreateNamedInsertStrNamedArgs(id, name); - case "testCreateNamedInsertStrOrderArgs" -> testCreateNamedInsertStrOrderArgs(id, name); - case "testCreateInsertNamedArgs" -> testCreateInsertNamedArgs(id, name); - case "testCreateInsertOrderArgs" -> testCreateInsertOrderArgs(id, name); - case "testNamedInsertOrderArgs" -> testNamedInsertOrderArgs(id, name); - case "testInsertOrderArgs" -> testInsertOrderArgs(id, name); - case "testCreateNamedDmlWithInsertStrStrNamedArgs" -> testCreateNamedDmlWithInsertStrStrNamedArgs(id, name); - case "testCreateNamedDmlWithInsertStrNamedArgs" -> testCreateNamedDmlWithInsertStrNamedArgs(id, name); - case "testCreateNamedDmlWithInsertStrOrderArgs" -> testCreateNamedDmlWithInsertStrOrderArgs(id, name); - case "testCreateDmlWithInsertNamedArgs" -> testCreateDmlWithInsertNamedArgs(id, name); - case "testCreateDmlWithInsertOrderArgs" -> testCreateDmlWithInsertOrderArgs(id, name); - case "testNamedDmlWithInsertOrderArgs" -> testNamedDmlWithInsertOrderArgs(id, name); - case "testDmlWithInsertOrderArgs" -> testDmlWithInsertOrderArgs(id, name); - default -> throw new NotFoundException("test not found: " + testName); - }; - Pokemon pokemon = new Pokemon(id, name, POKEMON_TYPES.get(name)); - response.send(okStatus(pokemon.toJsonObject())); - } - - /** - * Verify {@code createNamedInsert(String, String)} API method with named parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedInsertStrStrNamedArgs(int id, String name); - - /** - * Verify {@code createNamedInsert(String)} API method with named parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedInsertStrNamedArgs(int id, String name); - - /** - * Verify {@code createNamedInsert(String)} API method with ordered parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedInsertStrOrderArgs(int id, String name); - - /** - * Verify {@code createInsert(String)} API method with named parameters. - * - * @param id parameter - * @param name parameter - */ - protected abstract long testCreateInsertNamedArgs(int id, String name); - - /** - * Verify {@code createInsert(String)} API method with ordered parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateInsertOrderArgs(int id, String name); - - /** - * Verify {@code namedInsert(String)} API method with ordered parameters passed directly to the {@code insert} method. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testNamedInsertOrderArgs(int id, String name); - - /** - * Verify {@code insert(String)} API method with ordered parameters passed directly to the {@code insert} method. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testInsertOrderArgs(int id, String name); - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with insert with named parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedDmlWithInsertStrStrNamedArgs(int id, String name); - - /** - * Verify {@code createNamedDmlStatement(String)} API method with insert with named parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedDmlWithInsertStrNamedArgs(int id, String name); - - /** - * Verify {@code createNamedDmlStatement(String)} API method with insert with ordered parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedDmlWithInsertStrOrderArgs(int id, String name); - - /** - * Verify {@code createDmlStatement(String)} API method with insert with named parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateDmlWithInsertNamedArgs(int id, String name); - - /** - * Verify {@code createDmlStatement(String)} API method with insert with ordered parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateDmlWithInsertOrderArgs(int id, String name); - - /** - * Verify {@code namedDml(String)} API method with insert with ordered parameters passed directly - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testNamedDmlWithInsertOrderArgs(int id, String name); - - /** - * Verify {@code dml(String)} API method with insert with ordered parameters passed directly - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testDmlWithInsertOrderArgs(int id, String name); -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractQueryService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractQueryService.java deleted file mode 100644 index 8b80426613a..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractQueryService.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; -import java.util.List; -import java.util.Map; - -import io.helidon.http.NotFoundException; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonObject; - -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Base service to test query statements. - */ -public abstract class AbstractQueryService extends AbstractService { - - private static final System.Logger LOGGER = System.getLogger(AbstractQueryService.class.getName()); - - /** - * Create a new instance. - * - * @param dbClient dbclient - * @param statements statements - */ - public AbstractQueryService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - public void routing(HttpRules rules) { - rules.get("/{testName}", this::executeTest); - } - - private void executeTest(ServerRequest request, ServerResponse response) { - String testName = pathParam(request, "testName"); - String name = queryParam(request, QueryParams.NAME); - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on server", - getClass().getSimpleName(), testName)); - List result = switch (testName) { - case "testCreateNamedQueryStrStrOrderArgs" -> testCreateNamedQueryStrStrOrderArgs(name); - case "testCreateNamedQueryStrNamedArgs" -> testCreateNamedQueryStrNamedArgs(name); - case "testCreateNamedQueryStrOrderArgs" -> testCreateNamedQueryStrOrderArgs(name); - case "testCreateQueryNamedArgs" -> testCreateQueryNamedArgs(name); - case "testCreateQueryOrderArgs" -> testCreateQueryOrderArgs(name); - case "testNamedQueryOrderArgs" -> testNamedQueryOrderArgs(name); - case "testQueryOrderArgs" -> testQueryOrderArgs(name); - default -> throw new NotFoundException("test not found: " + testName); - }; - JsonArray jsonArray = result.stream() - .map(row -> row.as(JsonObject.class)) - .collect(Json::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::add) - .build(); - response.send(okStatus(jsonArray)); - } - - /** - * Verify {@code createNamedQuery(String, String)} API method with ordered - * - * @param name parameter - * @return rows - */ - protected abstract List testCreateNamedQueryStrStrOrderArgs(String name); - - /** - * Verify {@code createNamedQuery(String)} API method with named parameters. - * - * @param name parameter - * @return rows - */ - protected abstract List testCreateNamedQueryStrNamedArgs(String name); - - /** - * Verify {@code createNamedQuery(String)} API method with ordered - * - * @param name parameter - * @return rows - */ - protected abstract List testCreateNamedQueryStrOrderArgs(String name); - - /** - * Verify {@code createQuery(String)} API method with named parameters. - * - * @param name parameter - * @return rows - */ - protected abstract List testCreateQueryNamedArgs(String name); - - /** - * Verify {@code createQuery(String)} API method with ordered parameters. - * - * @param name parameter - * @return rows - */ - protected abstract List testCreateQueryOrderArgs(String name); - - /** - * Verify {@code namedQuery(String)} API method with ordered parameters - * - * @param name parameter - * @return rows - */ - protected abstract List testNamedQueryOrderArgs(String name); - - /** - * Verify {@code query(String)} API method with ordered parameters passed - * - * @param name parameter - * @return rows - */ - protected abstract List testQueryOrderArgs(String name); -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractService.java deleted file mode 100644 index df36d53ad6f..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractService.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; - -import io.helidon.dbclient.DbClient; -import io.helidon.webserver.http.HttpService; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.tests.integration.harness.RemoteTestException; - -/** - * Common web service code for testing application. - */ -public abstract class AbstractService implements HttpService { - - private final DbClient dbClient; - private final Map statements; - - /** - * Creates an instance of common web service code for testing application. - * - * @param dbClient DbClient instance - * @param statements statements from configuration file - */ - public AbstractService(DbClient dbClient, Map statements) { - this.dbClient = dbClient; - this.statements = statements; - } - - /** - * Returns stored DbClient instance. - * - * @return DbClient instance - */ - public DbClient dbClient() { - return dbClient; - } - - /** - * Returns stored statement from configuration file. - * - * @param name statement configuration property name - * @return statement from configuration file - */ - public String statement(String name) { - return statements.get(name); - } - - /** - * Retrieve HTTP query parameter value from request. - * - * @param request HTTP request context - * @param name query parameter name - * @return query parameter value - * @throws RemoteTestException when no parameter with given name exists in request - */ - public static String queryParam(ServerRequest request, String name) { - return request.query().first(name) - .orElseThrow(() -> new RemoteTestException("Query parameter %s is missing.", name)); - } - - /** - * Retrieve HTTP path parameter value from request. - * - * @param request HTTP request context - * @param name path parameter name - * @return path parameter value - * @throws RemoteTestException when no parameter with given name exists in request - */ - public static String pathParam(ServerRequest request, String name) { - return request.path().pathParameters().first(name) - .orElseThrow(() -> new RemoteTestException("Path parameter %s is missing.", name)); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractUpdateService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractUpdateService.java deleted file mode 100644 index 5bdef190979..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractUpdateService.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; -import java.util.Map; - -import io.helidon.http.NotFoundException; -import io.helidon.dbclient.DbClient; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; - -import jakarta.json.Json; - -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Base service to test update statements. - */ -public abstract class AbstractUpdateService extends AbstractService { - - private static final System.Logger LOGGER = System.getLogger(AbstractUpdateService.class.getName()); - - /** - * Create a new instance. - * - * @param dbClient dbclient - * @param statements statements - */ - public AbstractUpdateService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - public void routing(HttpRules rules) { - rules.get("/{testName}", this::executeTest); - } - - private void executeTest(ServerRequest request, ServerResponse response) { - String testName = pathParam(request, "testName"); - int id = Integer.parseInt(queryParam(request, QueryParams.ID)); - String name = queryParam(request, QueryParams.NAME); - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on server", getClass().getSimpleName(), testName)); - long count = switch (testName) { - case "testCreateNamedUpdateStrStrNamedArgs" -> testCreateNamedUpdateStrStrNamedArgs(id, name); - case "testCreateNamedUpdateStrNamedArgs" -> testCreateNamedUpdateStrNamedArgs(id, name); - case "testCreateNamedUpdateStrOrderArgs" -> testCreateNamedUpdateStrOrderArgs(id, name); - case "testCreateUpdateNamedArgs" -> testCreateUpdateNamedArgs(id, name); - case "testCreateUpdateOrderArgs" -> testCreateUpdateOrderArgs(id, name); - case "testNamedUpdateNamedArgs" -> testNamedUpdateNamedArgs(id, name); - case "testUpdateOrderArgs" -> testUpdateOrderArgs(id, name); - case "testCreateNamedDmlWithUpdateStrStrNamedArgs" -> testCreateNamedDmlWithUpdateStrStrNamedArgs(id, name); - case "testCreateNamedDmlWithUpdateStrNamedArgs" -> testCreateNamedDmlWithUpdateStrNamedArgs(id, name); - case "testCreateNamedDmlWithUpdateStrOrderArgs" -> testCreateNamedDmlWithUpdateStrOrderArgs(id, name); - case "testCreateDmlWithUpdateNamedArgs" -> testCreateDmlWithUpdateNamedArgs(id, name); - case "testCreateDmlWithUpdateOrderArgs" -> testCreateDmlWithUpdateOrderArgs(id, name); - case "testNamedDmlWithUpdateOrderArgs" -> testNamedDmlWithUpdateOrderArgs(id, name); - case "testDmlWithUpdateOrderArgs" -> testDmlWithUpdateOrderArgs(id, name); - default -> throw new NotFoundException("test not found: " + testName); - }; - response.send(okStatus(Json.createValue(count))); - } - - /** - * Verify {@code createNamedUpdate(String, String)} API method with ordered parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedUpdateStrStrNamedArgs(int id, String name); - - /** - * Verify {@code createNamedUpdate(String)} API method with named parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedUpdateStrNamedArgs(int id, String name); - - /** - * Verify {@code createNamedUpdate(String)} API method with ordered parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedUpdateStrOrderArgs(int id, String name); - - /** - * Verify {@code createUpdate(String)} API method with named parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateUpdateNamedArgs(int id, String name); - - /** - * Verify {@code createUpdate(String)} API method with ordered parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateUpdateOrderArgs(int id, String name); - - /** - * Verify {@code namedUpdate(String)} API method with ordered parameters passed directly to the - * {@code namedQuery} method. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testNamedUpdateNamedArgs(int id, String name); - - /** - * Verify {@code update(String)} API method with ordered parameters passed directly to the {@code query} method. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testUpdateOrderArgs(int id, String name); - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with update with named parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedDmlWithUpdateStrStrNamedArgs(int id, String name); - - /** - * Verify {@code createNamedDmlStatement(String)} API method with update with named parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedDmlWithUpdateStrNamedArgs(int id, String name); - - /** - * Verify {@code createNamedDmlStatement(String)} API method with update with ordered parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateNamedDmlWithUpdateStrOrderArgs(int id, String name); - - /** - * Verify {@code createDmlStatement(String)} API method with update with named parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateDmlWithUpdateNamedArgs(int id, String name); - - /** - * Verify {@code createDmlStatement(String)} API method with update with ordered parameters. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testCreateDmlWithUpdateOrderArgs(int id, String name); - - /** - * Verify {@code namedDml(String)} API method with update with ordered parameters passed directly. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testNamedDmlWithUpdateOrderArgs(int id, String name); - - /** - * Verify {@code dml(String)} API method with update with ordered parameters passed directly. - * - * @param id parameter - * @param name parameter - * @return count - */ - protected abstract long testDmlWithUpdateOrderArgs(int id, String name); - -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/FlowControlService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/FlowControlService.java deleted file mode 100644 index c98f6724d3b..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/FlowControlService.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.model.Type; -import io.helidon.tests.integration.harness.RemoteTestException; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; - -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Service to test proper flow control handling in query processing. - */ -public class FlowControlService extends AbstractService { - - /** - * Local logger instance. - */ - private static final System.Logger LOGGER = System.getLogger(FlowControlService.class.getName()); - - /** - * Creates an instance of web resource to test proper flow control handling in query processing. - * - * @param dbClient DbClient instance - * @param statements statements from configuration file - */ - public FlowControlService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - public void routing(HttpRules rules) { - rules.get("/testSourceData", this::testSourceData) - .get("/testFlowControl", this::testFlowControl); - } - - // Source data verification test. - // Testing code is blocking, so it's running in a separate thread. - private void testSourceData(ServerRequest request, ServerResponse response) { - LOGGER.log(Level.DEBUG, "Running FlowControlService.testSourceData on server"); - Stream rows = dbClient().execute().namedQuery("select-types"); - if (rows == null) { - throw new RemoteTestException("Rows value is null."); - } - List list = rows.toList(); - if (list.isEmpty()) { - throw new RemoteTestException("Rows list is empty."); - } - if (list.size() != 18) { - throw new RemoteTestException("Rows list size shall be 18."); - } - for (DbRow row : list) { - Integer id = row.column(1).get(Integer.class); - String name = row.column(2).get(String.class); - Type type = new Type(id, name); - if (!Type.TYPES.get(id).name().equals(name)) { - throw new RemoteTestException("Expected type name \"%s\", but got \"%s\".", - Type.TYPES.get(id).name(), - name); - } - LOGGER.log(Level.DEBUG, type::toString); - } - response.send(okStatus(JsonObject.EMPTY_JSON_OBJECT)); - } - - // Flow control test. - // Testing code is blocking, so it's running in a separate thread. - private void testFlowControl(ServerRequest request, ServerResponse response) { - LOGGER.log(Level.DEBUG, "Running FlowControlService.testFlowControl on server"); - long count = dbClient().execute().namedQuery("select-types").count(); - LOGGER.log(Level.DEBUG, "Sending OK response."); - JsonObjectBuilder job = Json.createObjectBuilder(); - job.add("total", count); - response.send(okStatus(job.build())); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/HealthCheckService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/HealthCheckService.java deleted file mode 100644 index a8e08d3ca6d..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/HealthCheckService.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; -import java.util.Map; - -import io.helidon.config.Config; -import io.helidon.health.HealthCheck; -import io.helidon.health.HealthCheckResponse; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.health.DbClientHealthCheck; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.AppResponse; -import io.helidon.tests.integration.harness.RemoteTestException; - -import jakarta.json.Json; -import jakarta.json.JsonObjectBuilder; - -/** - * Service to verify that health check works. - */ -public class HealthCheckService extends AbstractService { - - private static final System.Logger LOGGER = System.getLogger(HealthCheckService.class.getName()); - - private final Config dbConfig; - - /** - * Creates an instance of web resource to verify that health check works. - * - * @param dbClient DbClient instance - * @param dbConfig testing application configuration - * @param statements statements from configuration file - */ - public HealthCheckService(DbClient dbClient, Config dbConfig, Map statements) { - super(dbClient, statements); - this.dbConfig = dbConfig; - } - - @Override - public void routing(HttpRules rules) { - rules - .get("/testHealthCheck", this::testHealthCheck) - .get("/testHealthCheckWithName", this::testHealthCheckWithName) - .get("/testHealthCheckWithCustomNamedDML", this::testHealthCheckWithCustomNamedDML) - .get("/testHealthCheckWithCustomDML", this::testHealthCheckWithCustomDML) - .get("/testHealthCheckWithCustomNamedQuery", this::testHealthCheckWithCustomNamedQuery) - .get("/testHealthCheckWithCustomQuery", this::testHealthCheckWithCustomQuery); - } - - private void executeTest(ServerResponse response, String testName, HealthCheck check) { - LOGGER.log(Level.DEBUG, () -> String.format("Running HealthCheckService.%s on server", testName)); - JsonObjectBuilder job = Json.createObjectBuilder(); - HealthCheckResponse hcResponse = check.call(); - HealthCheckResponse.Status state = hcResponse.status(); - job.add("name", check.name()); - job.add("status", state.name()); - response.send(AppResponse.okStatus(job.build())); - } - - // Verify health check implementation with default settings. - private void testHealthCheck(ServerRequest request, ServerResponse response) { - executeTest(response, "testHealthCheck", - DbClientHealthCheck.create( - dbClient(), - dbConfig.get("health-check"))); - } - - // Verify health check implementation with builder and custom name. - private void testHealthCheckWithName(ServerRequest request, ServerResponse response) { - String name = queryParam(request, QueryParams.NAME); - executeTest(response, "testHealthCheckWithName", - DbClientHealthCheck.builder(dbClient()) - .config(dbConfig.get("health-check")) - .name(name) - .build()); - } - - // Verify health check implementation using custom DML named statement. - private void testHealthCheckWithCustomNamedDML(ServerRequest request, ServerResponse response) { - Config cfgStatement = dbConfig.get("statements.ping-dml"); - if (!cfgStatement.exists()) { - throw new RemoteTestException("Missing statements.ping-dml configuration parameter."); - } - executeTest(response, "testHealthCheckWithCustomNamedDML", - DbClientHealthCheck.builder(dbClient()) - .dml() - .statementName("ping-dml") - .build()); - } - - // Verify health check implementation using custom DML statement. - private void testHealthCheckWithCustomDML(ServerRequest request, ServerResponse response) { - Config cfgStatement = dbConfig.get("statements.ping-dml"); - if (!cfgStatement.exists()) { - throw new RemoteTestException("Missing statements.ping-dml configuration parameter."); - } - executeTest(response, "testHealthCheckWithCustomDML", - DbClientHealthCheck.builder(dbClient()) - .dml() - .statement(cfgStatement.as(String.class).get()) - .build()); - } - - // Verify health check implementation using custom query named statement. - private void testHealthCheckWithCustomNamedQuery(ServerRequest request, ServerResponse response) { - Config cfgStatement = dbConfig.get("statements.ping-query"); - if (!cfgStatement.exists()) { - throw new RemoteTestException("Missing statements.ping-query configuration parameter."); - } - executeTest(response, "testHealthCheckWithCustomNamedQuery", - DbClientHealthCheck.builder(dbClient()) - .query() - .statementName("ping-query") - .build()); - } - - // Verify health check implementation using custom query statement. - private void testHealthCheckWithCustomQuery(ServerRequest request, ServerResponse response) { - Config cfgStatement = dbConfig.get("statements.ping-query"); - if (!cfgStatement.exists()) { - throw new RemoteTestException("Missing statements.ping-query configuration parameter."); - } - executeTest(response, "testHealthCheckWithCustomQuery", - DbClientHealthCheck.builder(dbClient()) - .query() - .statement(cfgStatement.as(String.class).get()) - .build()); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/InterceptorService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/InterceptorService.java deleted file mode 100644 index 68fe774d516..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/InterceptorService.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbClientService; -import io.helidon.dbclient.DbClientServiceContext; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.harness.AppResponse; -import io.helidon.tests.integration.harness.RemoteTestException; - -import jakarta.json.Json; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonObject; - -/** - * Service to verify services handling. - */ -public class InterceptorService extends AbstractService { - - private final DbClientService interceptor; - - /** - * Creates an instance of web resource to verify services handling. - * - * @param dbClient DbClient instance - * @param statements statements from configuration file - * @param interceptor DbClientService interceptor instance used in test - */ - public InterceptorService(DbClient dbClient, Map statements, DbClientService interceptor) { - super(dbClient, statements); - this.interceptor = interceptor; - } - - /** - * Test db service. - */ - public static final class TestClientService implements DbClientService { - - private boolean called; - - /** - * Create a new instance. - */ - public TestClientService() { - this.called = false; - } - - @Override - public DbClientServiceContext statement(DbClientServiceContext context) { - this.called = true; - return context; - } - } - - @Override - public void routing(HttpRules rules) { - rules.get("/testStatementInterceptor", this::testStatementInterceptor); - } - - // Check that statement interceptor was called before statement execution. - private void testStatementInterceptor(ServerRequest request, ServerResponse response) { - JsonArrayBuilder jab = dbClient().execute().createNamedQuery("select-pokemon-named-arg") - .addParam("name", Pokemon.POKEMONS.get(6).getName()) - .execute() - .map(row -> row.as(JsonObject.class)) - .collect(Json::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::addAll); - if (((TestClientService) interceptor).called) { - response.send(AppResponse.okStatus(jab.build())); - } else { - throw new RemoteTestException("Interceptor service was not called"); - } - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/MapperService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/MapperService.java deleted file mode 100644 index f6ca23e109a..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/MapperService.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Stream; - -import io.helidon.http.NotFoundException; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonObject; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Service to test mapping interface. - */ -public class MapperService extends AbstractService { - - private static final System.Logger LOGGER = System.getLogger(MapperService.class.getName()); - - /** - * Create a new instance. - * - * @param dbClient dbclient - * @param statements statements - */ - public MapperService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - public void routing(HttpRules rules) { - rules.get("/{testName}", this::executeTest); - } - - private void executeTest(ServerRequest req, ServerResponse res) { - String testName = pathParam(req, "testName"); - LOGGER.log(System.Logger.Level.DEBUG, () -> String.format("Running %s.%s on server", getClass().getSimpleName(), testName)); - switch (testName) { - case "testInsertWithOrderMapping" -> execInsert(req, res, this::testInsertWithOrderMapping); - case "testInsertWithNamedMapping" -> execInsert(req, res, this::testInsertWithNamedMapping); - case "testUpdateWithOrderMapping" -> execUpdate(req, res, this::testUpdateWithOrderMapping); - case "testUpdateWithNamedMapping" -> execUpdate(req, res, this::testUpdateWithNamedMapping); - case "testDeleteWithOrderMapping" -> execDelete(req, res, this::testDeleteWithOrderMapping); - case "testDeleteWithNamedMapping" -> execDelete(req, res, this::testDeleteWithNamedMapping); - case "testQueryWithMapping" -> execQueryMapping(req, res, this::testQueryWithMapping); - case "testGetWithMapping" -> execGetMapping(req, res, this::testGetWithMapping); - default -> throw new NotFoundException("test not found: " + testName); - } - } - - private void execInsert(ServerRequest req, ServerResponse res, Function test) { - int id = Integer.parseInt(queryParam(req, QueryParams.ID)); - Pokemon pokemon = test.apply(id); - res.send(okStatus(pokemon.toJsonObject())); - } - - private void execUpdate(ServerRequest req, ServerResponse res, Function test) { - String name = queryParam(req, QueryParams.NAME); - int id = Integer.parseInt(queryParam(req, QueryParams.ID)); - Pokemon srcPokemon = Pokemon.POKEMONS.get(id); - Pokemon updatedPokemon = new Pokemon(id, name, srcPokemon.getTypesArray()); - long count = test.apply(updatedPokemon); - res.send(okStatus(Json.createValue(count))); - } - - private void execDelete(ServerRequest req, ServerResponse res, Function test) { - int id = Integer.parseInt(queryParam(req, QueryParams.ID)); - Pokemon pokemon = Pokemon.POKEMONS.get(id); - long count = test.apply(pokemon); - res.send(okStatus(Json.createValue(count))); - } - - private void execGetMapping(ServerRequest req, ServerResponse res, Function> test) { - String name = queryParam(req, QueryParams.NAME); - JsonObject jsonObject = test.apply(name) - .map(row -> row.as(Pokemon.class).toJsonObject()) - .orElse(JsonObject.EMPTY_JSON_OBJECT); - res.send(okStatus(jsonObject)); - } - - private void execQueryMapping(ServerRequest req, ServerResponse res, Function> test) { - String name = queryParam(req, QueryParams.NAME); - JsonArray jsonArray = test.apply(name) - .map(row -> row.as(Pokemon.class).toJsonObject()) - .collect(Json::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::add) - .build(); - res.send(okStatus(jsonArray)); - } - - /** - * Verify insertion using indexed mapping. - * - * @param id parameter - * @return pokemon - */ - private Pokemon testInsertWithOrderMapping(int id) { - Pokemon pokemon = new Pokemon(id, "Articuno", Pokemon.typesList(TYPES.get(3), TYPES.get(15))); - dbClient().execute() - .createNamedInsert("insert-pokemon-order-arg-rev") - .indexedParam(pokemon) - .execute(); - return pokemon; - } - - /** - * Verify insertion using named mapping. - * - * @param id parameter - * @return pokemon - */ - private Pokemon testInsertWithNamedMapping(int id) { - Pokemon pokemon = new Pokemon(id, "Zapdos", Pokemon.typesList(TYPES.get(3), TYPES.get(13))); - dbClient().execute() - .createNamedInsert("insert-pokemon-named-arg") - .namedParam(pokemon) - .execute(); - return pokemon; - } - - /** - * Verify update using indexed mapping. - * - * @param pokemon pokemon - * @return count - */ - private long testUpdateWithOrderMapping(Pokemon pokemon) { - return dbClient().execute() - .createNamedUpdate("update-pokemon-order-arg") - .indexedParam(pokemon) - .execute(); - } - - /** - * Verify update using named mapping. - * - * @param pokemon pokemon - * @return count - */ - private long testUpdateWithNamedMapping(Pokemon pokemon) { - return dbClient().execute() - .createNamedUpdate("update-pokemon-named-arg") - .namedParam(pokemon) - .execute(); - } - - /** - * Verify delete using indexed mapping. - * - * @param pokemon pokemon - * @return count - */ - private long testDeleteWithOrderMapping(Pokemon pokemon) { - return dbClient().execute() - .createNamedDelete("delete-pokemon-full-order-arg") - .indexedParam(pokemon) - .execute(); - } - - /** - * Verify delete using named mapping. - * - * @param pokemon pokemon - * @return count - */ - private long testDeleteWithNamedMapping(Pokemon pokemon) { - return dbClient().execute() - .createNamedDelete("delete-pokemon-full-named-arg") - .namedParam(pokemon) - .execute(); - } - - /** - * Verify query as a result using mapping. - * - * @param name parameter - * @return rows - */ - private Stream testQueryWithMapping(String name) { - return dbClient().execute() - .createNamedQuery("select-pokemon-named-arg") - .addParam("name", name) - .execute(); - } - - /** - * Verify get as a result using mapping. - * - * @param name parameter - * @return row - */ - private Optional testGetWithMapping(String name) { - return dbClient().execute().createNamedGet("select-pokemon-named-arg") - .addParam("name", name) - .execute(); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleDeleteService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleDeleteService.java deleted file mode 100644 index 8e309069dd8..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleDeleteService.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; - -import io.helidon.dbclient.DbClient; - -/** - * Service to test delete statements. - */ -public class SimpleDeleteService extends AbstractDeleteService { - - /** - * Create a new instance - * - * @param dbClient DbClient instance - * @param statements statements from configuration file - */ - public SimpleDeleteService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - protected long testCreateNamedDeleteStrStrOrderArgs(int id) { - return dbClient().execute() - .createNamedDelete("delete-rayquaza", statement("delete-pokemon-order-arg")) - .addParam(id) - .execute(); - } - - @Override - protected long testCreateNamedDeleteStrNamedArgs(int id) { - return dbClient().execute() - .createNamedDelete("delete-pokemon-named-arg") - .addParam("id", id) - .execute(); - } - - @Override - protected long testCreateNamedDeleteStrOrderArgs(int id) { - return dbClient().execute() - .createNamedDelete("delete-pokemon-order-arg") - .addParam(id) - .execute(); - } - - @Override - protected long testCreateDeleteNamedArgs(int id) { - return dbClient().execute() - .createDelete(statement("delete-pokemon-named-arg")) - .addParam("id", id) - .execute(); - } - - @Override - protected long testCreateDeleteOrderArgs(int id) { - return dbClient().execute() - .createDelete(statement("delete-pokemon-order-arg")) - .addParam(id) - .execute(); - } - - @Override - protected long testNamedDeleteOrderArgs(int id) { - return dbClient().execute() - .namedDelete("delete-pokemon-order-arg", id); - } - - @Override - protected long testDeleteOrderArgs(int id) { - return dbClient().execute() - .delete(statement("delete-pokemon-order-arg"), id); - } - - @Override - protected long testCreateNamedDmlWithDeleteStrStrOrderArgs(int id) { - return dbClient().execute() - .createNamedDmlStatement("delete-mudkip", statement("delete-pokemon-order-arg")) - .addParam(id) - .execute(); - } - - @Override - protected long testCreateNamedDmlWithDeleteStrNamedArgs(int id) { - return dbClient().execute() - .createNamedDmlStatement("delete-pokemon-named-arg") - .addParam("id", id) - .execute(); - } - - @Override - protected long testCreateNamedDmlWithDeleteStrOrderArgs(int id) { - return dbClient().execute() - .createNamedDmlStatement("delete-pokemon-order-arg") - .addParam(id) - .execute(); - } - - @Override - protected long testCreateDmlWithDeleteNamedArgs(int id) { - return dbClient().execute() - .createDmlStatement(statement("delete-pokemon-named-arg")) - .addParam("id", id) - .execute(); - } - - @Override - protected long testCreateDmlWithDeleteOrderArgs(int id) { - return dbClient().execute() - .createDmlStatement(statement("delete-pokemon-order-arg")) - .addParam(id) - .execute(); - } - - @Override - protected long testNamedDmlWithDeleteOrderArgs(int id) { - return dbClient().execute() - .namedDml("delete-pokemon-order-arg", id); - } - - @Override - protected long testDmlWithDeleteOrderArgs(int id) { - return dbClient().execute() - .dml(statement("delete-pokemon-order-arg"), id); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleGetService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleGetService.java deleted file mode 100644 index e3199ab969c..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleGetService.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2020, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; -import java.util.Optional; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; - -/** - * Service to test simple get statements. - */ -public class SimpleGetService extends AbstractGetService { - - /** - * Creates an instance of web resource to test set of basic DbClient gets. - * - * @param dbClient DbClient instance - * @param statements statements from configuration file - */ - public SimpleGetService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - protected Optional testCreateNamedGetStrStrNamedArgs(String name) { - return dbClient().execute() - .createNamedGet("select-pikachu", statement("select-pokemon-named-arg")) - .addParam("name", name) - .execute(); - } - - @Override - protected Optional testCreateNamedGetStrNamedArgs(String name) { - return dbClient().execute() - .createNamedGet("select-pokemon-named-arg") - .addParam("name", name) - .execute(); - } - - @Override - protected Optional testCreateNamedGetStrOrderArgs(String name) { - return dbClient().execute() - .createNamedGet("select-pokemon-order-arg") - .addParam(name) - .execute(); - } - - @Override - protected Optional testCreateGetNamedArgs(String name) { - return dbClient().execute() - .createGet(statement("select-pokemon-named-arg")) - .addParam("name", name) - .execute(); - } - - @Override - protected Optional testCreateGetOrderArgs(String name) { - return dbClient().execute() - .createGet(statement("select-pokemon-order-arg")) - .addParam(name) - .execute(); - } - - @Override - protected Optional testNamedGetStrOrderArgs(String name) { - return dbClient().execute() - .namedGet("select-pokemon-order-arg", name); - } - - @Override - protected Optional testGetStrOrderArgs(String name) { - return dbClient().execute() - .get(statement("select-pokemon-order-arg"), name); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleInsertService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleInsertService.java deleted file mode 100644 index 806daa550cb..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleInsertService.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; - -import io.helidon.dbclient.DbClient; - -/** - * Service to test simple insert statements. - */ -public class SimpleInsertService extends AbstractInsertService { - - /** - * Creates an instance of web resource to test set of basic DbClient inserts. - * - * @param dbClient DbClient instance - * @param statements statements from configuration file - */ - public SimpleInsertService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - protected long testCreateNamedInsertStrStrNamedArgs(int id, String name) { - return dbClient().execute() - .createNamedInsert("insert-bulbasaur", statement("insert-pokemon-named-arg")) - .addParam("id", id) - .addParam("name", name) - .execute(); - } - - @Override - protected long testCreateNamedInsertStrNamedArgs(int id, String name) { - return dbClient().execute() - .createNamedInsert("insert-pokemon-named-arg") - .addParam("id", id) - .addParam("name", name) - .execute(); - } - - @Override - protected long testCreateNamedInsertStrOrderArgs(int id, String name) { - return dbClient().execute() - .createNamedInsert("insert-pokemon-order-arg") - .addParam(id) - .addParam(name) - .execute(); - } - - @Override - protected long testCreateInsertNamedArgs(int id, String name) { - return dbClient().execute() - .createInsert(statement("insert-pokemon-named-arg")) - .addParam("id", id) - .addParam("name", name) - .execute(); - } - - @Override - protected long testCreateInsertOrderArgs(int id, String name) { - return dbClient().execute() - .createInsert(statement("insert-pokemon-order-arg")) - .addParam(id) - .addParam(name) - .execute(); - } - - @Override - protected long testNamedInsertOrderArgs(int id, String name) { - return dbClient().execute() - .namedInsert("insert-pokemon-order-arg", id, name); - } - - @Override - protected long testInsertOrderArgs(int id, String name) { - return dbClient().execute() - .insert(statement("insert-pokemon-order-arg"), id, name); - } - - @Override - protected long testCreateNamedDmlWithInsertStrStrNamedArgs(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("insert-torchic", statement("insert-pokemon-named-arg")) - .addParam("id", id) - .addParam("name", name) - .execute(); - } - - @Override - protected long testCreateNamedDmlWithInsertStrNamedArgs(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("insert-pokemon-named-arg") - .addParam("id", id) - .addParam("name", name) - .execute(); - } - - @Override - protected long testCreateNamedDmlWithInsertStrOrderArgs(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("insert-pokemon-order-arg") - .addParam(id) - .addParam(name) - .execute(); - } - - @Override - protected long testCreateDmlWithInsertNamedArgs(int id, String name) { - return dbClient().execute() - .createDmlStatement(statement("insert-pokemon-named-arg")) - .addParam("id", id) - .addParam("name", name) - .execute(); - } - - @Override - protected long testCreateDmlWithInsertOrderArgs(int id, String name) { - return dbClient().execute() - .createDmlStatement(statement("insert-pokemon-order-arg")) - .addParam(id) - .addParam(name) - .execute(); - } - - @Override - protected long testNamedDmlWithInsertOrderArgs(int id, String name) { - return dbClient().execute() - .namedDml("insert-pokemon-order-arg", id, name); - } - - @Override - protected long testDmlWithInsertOrderArgs(int id, String name) { - return dbClient().execute() - .dml(statement("insert-pokemon-order-arg"), id, name); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleQueryService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleQueryService.java deleted file mode 100644 index 6ae42bd8b5d..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleQueryService.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.List; -import java.util.Map; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; - -/** - * Service to test simple query statements. - */ -public class SimpleQueryService extends AbstractQueryService { - - /** - * Create a new instance. - * - * @param dbClient dbclient - * @param statements statements - */ - public SimpleQueryService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - protected List testCreateNamedQueryStrStrOrderArgs(String name) { - return dbClient().execute() - .createNamedQuery("select-pikachu", statement("select-pokemon-order-arg")) - .addParam(name) - .execute() - .toList(); - } - - @Override - protected List testCreateNamedQueryStrNamedArgs(String name) { - return dbClient().execute() - .createNamedQuery("select-pokemon-named-arg") - .addParam("name", name) - .execute() - .toList(); - } - - @Override - protected List testCreateNamedQueryStrOrderArgs(String name) { - return dbClient().execute() - .createNamedQuery("select-pokemon-order-arg") - .addParam(name) - .execute() - .toList(); - } - - @Override - protected List testCreateQueryNamedArgs(String name) { - return dbClient().execute() - .createQuery(statement("select-pokemon-named-arg")) - .addParam("name", name) - .execute() - .toList(); - } - - @Override - protected List testCreateQueryOrderArgs(String name) { - return dbClient().execute() - .createQuery(statement("select-pokemon-order-arg")) - .addParam(name) - .execute() - .toList(); - } - - @Override - protected List testNamedQueryOrderArgs(String name) { - return dbClient().execute() - .namedQuery("select-pokemon-order-arg", name) - .toList(); - } - - @Override - protected List testQueryOrderArgs(String name) { - return dbClient().execute() - .query(statement("select-pokemon-order-arg"), name) - .toList(); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleUpdateService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleUpdateService.java deleted file mode 100644 index c0f0ebaee46..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleUpdateService.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; - -import io.helidon.dbclient.DbClient; - -/** - * Service to test simple update statements. - */ -public class SimpleUpdateService extends AbstractUpdateService { - - /** - * Create a new instance. - * - * @param dbClient dbclient - * @param statements statements - */ - public SimpleUpdateService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - protected long testCreateNamedUpdateStrStrNamedArgs(int id, String name) { - return dbClient().execute() - .createNamedUpdate("update-spearow", statement("update-pokemon-named-arg")) - .addParam("name", name) - .addParam("id", id) - .execute(); - } - - @Override - protected long testCreateNamedUpdateStrNamedArgs(int id, String name) { - return dbClient().execute() - .createNamedUpdate("update-pokemon-named-arg") - .addParam("name", name) - .addParam("id", id) - .execute(); - } - - @Override - protected long testCreateNamedUpdateStrOrderArgs(int id, String name) { - return dbClient().execute() - .createNamedUpdate("update-pokemon-order-arg") - .addParam(name) - .addParam(id) - .execute(); - } - - @Override - protected long testCreateUpdateNamedArgs(int id, String name) { - return dbClient().execute() - .createUpdate(statement("update-pokemon-named-arg")) - .addParam("name", name) - .addParam("id", id) - .execute(); - } - - @Override - protected long testCreateUpdateOrderArgs(int id, String name) { - return dbClient().execute() - .createUpdate(statement("update-pokemon-order-arg")) - .addParam(name) - .addParam(id) - .execute(); - } - - @Override - protected long testNamedUpdateNamedArgs(int id, String name) { - return dbClient().execute() - .namedUpdate("update-pokemon-order-arg", name, id); - } - - @Override - protected long testUpdateOrderArgs(int id, String name) { - return dbClient().execute() - .update(statement("update-pokemon-order-arg"), name, id); - } - - @Override - protected long testCreateNamedDmlWithUpdateStrStrNamedArgs(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("update-piplup", statement("update-pokemon-named-arg")) - .addParam("name", name) - .addParam("id", id) - .execute(); - } - - @Override - protected long testCreateNamedDmlWithUpdateStrNamedArgs(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("update-pokemon-named-arg") - .addParam("name", name) - .addParam("id", id) - .execute(); - } - - @Override - protected long testCreateNamedDmlWithUpdateStrOrderArgs(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("update-pokemon-order-arg") - .addParam(name) - .addParam(id) - .execute(); - } - - @Override - protected long testCreateDmlWithUpdateNamedArgs(int id, String name) { - return dbClient().execute() - .createDmlStatement(statement("update-pokemon-named-arg")) - .addParam("name", name) - .addParam("id", id) - .execute(); - } - - @Override - protected long testCreateDmlWithUpdateOrderArgs(int id, String name) { - return dbClient().execute() - .createDmlStatement(statement("update-pokemon-order-arg")) - .addParam(name) - .addParam(id) - .execute(); - } - - @Override - protected long testNamedDmlWithUpdateOrderArgs(int id, String name) { - return dbClient().execute() - .namedDml("update-pokemon-order-arg", name, id); - } - - @Override - protected long testDmlWithUpdateOrderArgs(int id, String name) { - return dbClient().execute() - .dml(statement("update-pokemon-order-arg"), name, id); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementDmlService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementDmlService.java deleted file mode 100644 index 137bce519d5..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementDmlService.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; -import java.util.List; -import java.util.Map; - -import io.helidon.http.NotFoundException; -import io.helidon.dbclient.DbClient; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; - -import jakarta.json.Json; - -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Service to test DbStatementDml methods. - */ -public class StatementDmlService extends AbstractService { - - private static final System.Logger LOGGER = System.getLogger(StatementDmlService.class.getName()); - - public StatementDmlService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - public void routing(HttpRules rules) { - rules.get("/{testName}", this::executeTest); - } - - private void executeTest(ServerRequest request, ServerResponse response) { - String testName = pathParam(request, "testName"); - String name = queryParam(request, QueryParams.NAME); - int id = Integer.parseInt(queryParam(request, QueryParams.ID)); - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on server", getClass().getSimpleName(), testName)); - long count = switch (testName) { - case "testDmlArrayParams" -> testDmlArrayParams(id, name); - case "testDmlListParams" -> testDmlListParams(id, name); - case "testDmlMapParams" -> testDmlMapParams(id, name); - case "testDmlOrderParam" -> testDmlOrderParam(id, name); - case "testDmlNamedParam" -> testDmlNamedParam(id, name); - case "testDmlMappedNamedParam" -> testDmlMappedNamedParam(id, name); - case "testDmlMappedOrderParam" -> testDmlMappedOrderParam(id, name); - default -> throw new NotFoundException("test not found: " + testName); - }; - response.send(okStatus(Json.createValue(count))); - } - - /** - * Verify {@code params(Object... parameters)} parameters setting method. - * - * @param id parameter - * @param name parameter - * @return count - */ - private long testDmlArrayParams(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("update-pokemon-order-arg") - .params(name, id) - .execute(); - } - - /** - * Verify {@code params(List)} parameters setting method. - * - * @param id parameter - * @param name parameter - * @return count - */ - private long testDmlListParams(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("update-pokemon-order-arg") - .params(List.of(name, id)) - .execute(); - } - - /** - * Verify {@code params(Map)} parameters setting method. - * - * @param id parameter - * @param name parameter - * @return count - */ - private long testDmlMapParams(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("update-pokemon-named-arg") - .params(Map.of("name", name, "id", id)) - .execute(); - } - - /** - * Verify {@code addParam(Object parameter)} parameters setting method. - * - * @param id parameter - * @param name parameter - * @return count - */ - private long testDmlOrderParam(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("update-pokemon-order-arg") - .addParam(name) - .addParam(id) - .execute(); - } - - /** - * Verify {@code addParam(String name, Object parameter)} parameters setting method. - * - * @param id parameter - * @param name parameter - * @return count - */ - private long testDmlNamedParam(int id, String name) { - return dbClient().execute() - .createNamedDmlStatement("update-pokemon-named-arg") - .addParam("name", name) - .addParam("id", id) - .execute(); - } - - /** - * Verify {@code namedParam(Object parameters)} mapped parameters setting method. - * - * @param id parameter - * @param name parameter - * @return count - */ - private long testDmlMappedNamedParam(int id, String name) { - Pokemon pokemon = new Pokemon(id, name, Pokemon.POKEMONS.get(id).getTypesArray()); - return dbClient().execute() - .createNamedDmlStatement("update-pokemon-named-arg") - .namedParam(pokemon) - .execute(); - } - - /** - * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. - * - * @param id parameter - * @param name parameter - * @return count - */ - private long testDmlMappedOrderParam(int id, String name) { - Pokemon pokemon = new Pokemon(id, name, Pokemon.POKEMONS.get(id).getTypesArray()); - return dbClient().execute() - .createNamedDmlStatement("update-pokemon-order-arg") - .indexedParam(pokemon) - .execute(); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementGetService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementGetService.java deleted file mode 100644 index de08450d2de..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementGetService.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import io.helidon.http.NotFoundException; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.common.model.RangePoJo; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; - -import jakarta.json.JsonObject; - -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Service to test get statements. - */ -public class StatementGetService extends AbstractService { - - private static final System.Logger LOGGER = System.getLogger(StatementGetService.class.getName()); - - /** - * Create a new instance - * - * @param dbClient dbclient - * @param statements statements - */ - public StatementGetService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - public void routing(HttpRules rules) { - rules.get("/{testName}", this::executeTest); - } - - private void executeTest(ServerRequest request, ServerResponse response) { - String testName = pathParam(request, "testName"); - int fromId = Integer.parseInt(queryParam(request, QueryParams.FROM_ID)); - int toId = Integer.parseInt(queryParam(request, QueryParams.TO_ID)); - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on server", getClass().getSimpleName(), testName)); - Optional result = switch (testName) { - case "testGetArrayParams" -> testGetArrayParams(fromId, toId); - case "testGetListParams" -> testGetListParams(fromId, toId); - case "testGetMapParams" -> testGetMapParams(fromId, toId); - case "testGetOrderParam" -> testGetOrderParam(fromId, toId); - case "testGetNamedParam" -> testGetNamedParam(fromId, toId); - case "testGetMappedNamedParam" -> testGetMappedNamedParam(fromId, toId); - case "testGetMappedOrderParam" -> testGetMappedOrderParam(fromId, toId); - default -> throw new NotFoundException("test not found: " + testName); - }; - JsonObject jsonObject = result - .map(row -> row.as(JsonObject.class)) - .orElse(JsonObject.EMPTY_JSON_OBJECT); - response.send(okStatus(jsonObject)); - } - - /** - * Verify {@code params(Object... parameters)} parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return row - */ - private Optional testGetArrayParams(int fromId, int toId) { - return dbClient().execute() - .createNamedGet("select-pokemons-idrng-order-arg") - .params(fromId, toId) - .execute(); - } - - /** - * Verify {@code params(List)} parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return row - */ - private Optional testGetListParams(int fromId, int toId) { - return dbClient().execute() - .createNamedGet("select-pokemons-idrng-order-arg") - .params(List.of(fromId, toId)) - .execute(); - } - - /** - * Verify {@code params(Map)} parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return row - */ - private Optional testGetMapParams(int fromId, int toId) { - return dbClient().execute() - .createNamedGet("select-pokemons-idrng-named-arg") - .params(Map.of("idmin", fromId, "idmax", toId)) - .execute(); - } - - /** - * Verify {@code addParam(Object parameter)} parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return row - */ - private Optional testGetOrderParam(int fromId, int toId) { - return dbClient().execute() - .createNamedGet("select-pokemons-idrng-order-arg") - .addParam(fromId) - .addParam(toId) - .execute(); - } - - /** - * Verify {@code addParam(String name, Object parameter)} parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return row - */ - private Optional testGetNamedParam(int fromId, int toId) { - return dbClient().execute() - .createNamedGet("select-pokemons-idrng-named-arg") - .addParam("idmin", fromId) - .addParam("idmax", toId) - .execute(); - } - - /** - * Verify {@code namedParam(Object parameters)} mapped parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return row - */ - private Optional testGetMappedNamedParam(int fromId, int toId) { - RangePoJo range = new RangePoJo(fromId, toId); - return dbClient().execute() - .createNamedGet("select-pokemons-idrng-named-arg") - .namedParam(range) - .execute(); - } - - /** - * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return row - */ - private Optional testGetMappedOrderParam(int fromId, int toId) { - RangePoJo range = new RangePoJo(fromId, toId); - return dbClient().execute() - .createNamedGet("select-pokemons-idrng-order-arg") - .indexedParam(range) - .execute(); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementQueryService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementQueryService.java deleted file mode 100644 index a1eabc1563a..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementQueryService.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; - -import io.helidon.http.NotFoundException; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; -import io.helidon.tests.integration.dbclient.common.model.RangePoJo; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonObject; - -import static io.helidon.tests.integration.harness.AppResponse.okStatus; - -/** - * Service to test query statements. - */ -public class StatementQueryService extends AbstractService { - - private static final System.Logger LOGGER = System.getLogger(StatementGetService.class.getName()); - - /** - * Create a new instance. - * - * @param dbClient dbclient - * @param statements statements - */ - public StatementQueryService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - public void routing(HttpRules rules) { - rules.get("/{testName}", this::executeTest); - } - - private void executeTest(ServerRequest request, ServerResponse response) { - String testName = pathParam(request, "testName"); - int fromId = Integer.parseInt(queryParam(request, QueryParams.FROM_ID)); - int toId = Integer.parseInt(queryParam(request, QueryParams.TO_ID)); - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on server", getClass().getSimpleName(), testName)); - Stream result = switch (testName) { - case "testQueryArrayParams" -> testQueryArrayParams(fromId, toId); - case "testQueryListParams" -> testQueryListParams(fromId, toId); - case "testQueryMapParams" -> testQueryMapParams(fromId, toId); - case "testQueryOrderParam" -> testQueryOrderParam(fromId, toId); - case "testQueryNamedParam" -> testQueryNamedParam(fromId, toId); - case "testQueryMappedNamedParam" -> testQueryMappedNamedParam(fromId, toId); - case "testQueryMappedOrderParam" -> testQueryMappedOrderParam(fromId, toId); - default -> throw new NotFoundException("test not found: " + testName); - }; - JsonArray jsonArray = result - .map(row -> row.as(JsonObject.class)) - .collect(Json::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::add) - .build(); - response.send(okStatus(jsonArray)); - } - - /** - * Verify {@code params(Object... parameters)} parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return rows - */ - private Stream testQueryArrayParams(int fromId, int toId) { - return dbClient().execute() - .createNamedQuery("select-pokemons-idrng-order-arg") - .params(fromId, toId) - .execute(); - } - - /** - * Verify {@code params(List)} parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return rows - */ - private Stream testQueryListParams(int fromId, int toId) { - return dbClient().execute() - .createNamedQuery("select-pokemons-idrng-order-arg") - .params(List.of(fromId, toId)) - .execute(); - } - - /** - * Verify {@code params(Map)} parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return rows - */ - private Stream testQueryMapParams(int fromId, int toId) { - return dbClient().execute() - .createNamedQuery("select-pokemons-idrng-named-arg") - .params(Map.of("idmin", fromId, "idmax", toId)) - .execute(); - } - - /** - * Verify {@code addParam(Object parameter)} parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return rows - */ - private Stream testQueryOrderParam(int fromId, int toId) { - return dbClient().execute() - .createNamedQuery("select-pokemons-idrng-order-arg") - .addParam(fromId) - .addParam(toId) - .execute(); - } - - /** - * Verify {@code addParam(String name, Object parameter)} parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return rows - */ - private Stream testQueryNamedParam(int fromId, int toId) { - return dbClient().execute() - .createNamedQuery("select-pokemons-idrng-named-arg") - .addParam("idmin", fromId) - .addParam("idmax", toId) - .execute(); - } - - /** - * Verify {@code namedParam(Object parameters)} mapped parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return rows - */ - private Stream testQueryMappedNamedParam(int fromId, int toId) { - RangePoJo range = new RangePoJo(fromId, toId); - return dbClient().execute().createNamedQuery("select-pokemons-idrng-named-arg") - .namedParam(range) - .execute(); - } - - /** - * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. - * - * @param fromId parameter - * @param toId parameter - * @return rows - */ - private Stream testQueryMappedOrderParam(int fromId, int toId) { - RangePoJo range = new RangePoJo(fromId, toId); - return dbClient().execute().createNamedQuery("select-pokemons-idrng-order-arg") - .indexedParam(range) - .execute(); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionDeleteService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionDeleteService.java deleted file mode 100644 index 0dfb7953424..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionDeleteService.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbTransaction; - -/** - * Service to test delete statements in transaction. - */ -public class TransactionDeleteService extends AbstractDeleteService { - - public TransactionDeleteService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - protected long testCreateNamedDeleteStrStrOrderArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDelete("delete-rayquaza", statement("delete-pokemon-order-arg")) - .addParam(id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDeleteStrNamedArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDelete("delete-pokemon-named-arg") - .addParam("id", id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDeleteStrOrderArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDelete("delete-pokemon-order-arg") - .addParam(id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateDeleteNamedArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createDelete(statement("delete-pokemon-named-arg")) - .addParam("id", id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateDeleteOrderArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createDelete(statement("delete-pokemon-order-arg")) - .addParam(id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testNamedDeleteOrderArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.namedDelete("delete-pokemon-order-arg", id); - tx.commit(); - return count; - } - - @Override - protected long testDeleteOrderArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.delete(statement("delete-pokemon-order-arg"), id); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDmlWithDeleteStrStrOrderArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDmlStatement("delete-mudkip", statement("delete-pokemon-order-arg")) - .addParam(id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDmlWithDeleteStrNamedArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDmlStatement("delete-pokemon-named-arg") - .addParam("id", id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDmlWithDeleteStrOrderArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDmlStatement("delete-pokemon-order-arg") - .addParam(id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateDmlWithDeleteNamedArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createDmlStatement(statement("delete-pokemon-named-arg")) - .addParam("id", id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateDmlWithDeleteOrderArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx - .createDmlStatement(statement("delete-pokemon-order-arg")) - .addParam(id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testNamedDmlWithDeleteOrderArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.namedDml("delete-pokemon-order-arg", id); - tx.commit(); - return count; - } - - @Override - protected long testDmlWithDeleteOrderArgs(int id) { - DbTransaction tx = dbClient().transaction(); - long count = tx.dml(statement("delete-pokemon-order-arg"), id); - tx.commit(); - return count; - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionGetService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionGetService.java deleted file mode 100644 index 917a21dbdb5..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionGetService.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; -import java.util.Optional; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.dbclient.DbTransaction; - -/** - * Service to test set of get statements calls in transaction. - */ -public class TransactionGetService extends AbstractGetService { - - public TransactionGetService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - protected Optional testCreateNamedGetStrStrNamedArgs(String name) { - DbTransaction tx = dbClient().transaction(); - Optional result = tx - .createNamedGet("select-pikachu", statement("select-pokemon-named-arg")) - .addParam("name", name) - .execute(); - tx.commit(); - return result; - } - - @Override - protected Optional testCreateNamedGetStrNamedArgs(String name) { - DbTransaction tx = dbClient().transaction(); - Optional result = tx - .createNamedGet("select-pokemon-named-arg") - .addParam("name", name) - .execute(); - tx.commit(); - return result; - } - - @Override - protected Optional testCreateNamedGetStrOrderArgs(String name) { - DbTransaction tx = dbClient().transaction(); - Optional result = tx - .createNamedGet("select-pokemon-order-arg") - .addParam(name) - .execute(); - tx.commit(); - return result; - } - - @Override - protected Optional testCreateGetNamedArgs(String name) { - DbTransaction tx = dbClient().transaction(); - Optional result = tx - .createGet(statement("select-pokemon-named-arg")) - .addParam("name", name) - .execute(); - tx.commit(); - return result; - } - - @Override - protected Optional testCreateGetOrderArgs(String name) { - DbTransaction tx = dbClient().transaction(); - Optional result = tx - .createGet(statement("select-pokemon-order-arg")) - .addParam(name) - .execute(); - tx.commit(); - return result; - } - - @Override - protected Optional testNamedGetStrOrderArgs(String name) { - DbTransaction tx = dbClient().transaction(); - Optional result = tx.namedGet("select-pokemon-order-arg", name); - tx.commit(); - return result; - } - - @Override - protected Optional testGetStrOrderArgs(String name) { - DbTransaction tx = dbClient().transaction(); - Optional result = tx.get(statement("select-pokemon-order-arg"), name); - tx.commit(); - return result; - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionInsertService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionInsertService.java deleted file mode 100644 index aabcdb27c84..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionInsertService.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbTransaction; - -/** - * Service to test simple insert statements in transaction. - */ -public class TransactionInsertService extends AbstractInsertService { - - /** - * Create a new instance. - * - * @param dbClient dbclient - * @param statements statements - */ - public TransactionInsertService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - protected long testCreateNamedInsertStrStrNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx - .createNamedInsert("insert-bulbasaur", statement("insert-pokemon-named-arg")) - .addParam("id", id) - .addParam("name", name) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedInsertStrNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedInsert("insert-pokemon-named-arg") - .addParam("id", id) - .addParam("name", name) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedInsertStrOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedInsert("insert-pokemon-order-arg") - .addParam(id) - .addParam(name) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateInsertNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createInsert(statement("insert-pokemon-named-arg")) - .addParam("id", id) - .addParam("name", name) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateInsertOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createInsert(statement("insert-pokemon-order-arg")) - .addParam(id) - .addParam(name) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testNamedInsertOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.namedInsert("insert-pokemon-order-arg", id, name); - tx.commit(); - return count; - } - - @Override - protected long testInsertOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.insert(statement("insert-pokemon-order-arg"), id, name); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDmlWithInsertStrStrNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDmlStatement("insert-torchic", statement("insert-pokemon-named-arg")) - .addParam("id", id) - .addParam("name", name) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDmlWithInsertStrNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDmlStatement("insert-pokemon-named-arg") - .addParam("id", id) - .addParam("name", name) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDmlWithInsertStrOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDmlStatement("insert-pokemon-order-arg") - .addParam(id) - .addParam(name) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateDmlWithInsertNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createDmlStatement(statement("insert-pokemon-named-arg")) - .addParam("id", id) - .addParam("name", name) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateDmlWithInsertOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createDmlStatement(statement("insert-pokemon-order-arg")) - .addParam(id) - .addParam(name) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testNamedDmlWithInsertOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.namedDml("insert-pokemon-order-arg", id, name); - tx.commit(); - return count; - } - - @Override - protected long testDmlWithInsertOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.dml(statement("insert-pokemon-order-arg"), id, name); - tx.commit(); - return count; - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionQueryService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionQueryService.java deleted file mode 100644 index 2d3d04bc33b..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionQueryService.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.List; -import java.util.Map; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.dbclient.DbTransaction; - -/** - * Service to test simple query statements in transaction. - */ -public class TransactionQueryService extends AbstractQueryService { - - /** - * Create a new instance. - * - * @param dbClient dbclient - * @param statements statements - */ - public TransactionQueryService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - protected List testCreateNamedQueryStrStrOrderArgs(String name) { - DbTransaction tx = dbClient().transaction(); - List rows = tx.createNamedQuery("select-pikachu", statement("select-pokemon-order-arg")) - .addParam(name) - .execute() - .toList(); - tx.commit(); - return rows; - } - - @Override - protected List testCreateNamedQueryStrNamedArgs(String name) { - DbTransaction tx = dbClient().transaction(); - List rows = tx - .createNamedQuery("select-pokemon-named-arg") - .addParam("name", name) - .execute() - .toList(); - tx.commit(); - return rows; - } - - @Override - protected List testCreateNamedQueryStrOrderArgs(String name) { - DbTransaction tx = dbClient().transaction(); - List rows = tx - .createNamedQuery("select-pokemon-order-arg") - .addParam(name) - .execute() - .toList(); - tx.commit(); - return rows; - } - - @Override - protected List testCreateQueryNamedArgs(String name) { - DbTransaction tx = dbClient().transaction(); - List rows = tx - .createQuery(statement("select-pokemon-named-arg")) - .addParam("name", name) - .execute() - .toList(); - tx.commit(); - return rows; - } - - @Override - protected List testCreateQueryOrderArgs(String name) { - DbTransaction tx = dbClient().transaction(); - List rows = tx - .createQuery(statement("select-pokemon-order-arg")) - .addParam(name) - .execute() - .toList(); - tx.commit(); - return rows; - } - - @Override - protected List testNamedQueryOrderArgs(String name) { - DbTransaction tx = dbClient().transaction(); - List rows = tx - .namedQuery("select-pokemon-order-arg", name) - .toList(); - tx.commit(); - return rows; - } - - @Override - protected List testQueryOrderArgs(String name) { - DbTransaction tx = dbClient().transaction(); - List rows = tx - .query(statement("select-pokemon-order-arg"), name) - .toList(); - tx.commit(); - return rows; - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionUpdateService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionUpdateService.java deleted file mode 100644 index 2d9fc38ed2d..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionUpdateService.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.util.Map; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbTransaction; - -/** - * Service to test simple update statements in transaction. - */ -public class TransactionUpdateService extends AbstractUpdateService { - - /** - * Create a new instance. - * - * @param dbClient dbclient - * @param statements statements - */ - public TransactionUpdateService(DbClient dbClient, Map statements) { - super(dbClient, statements); - } - - @Override - protected long testCreateNamedUpdateStrStrNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedUpdate("update-spearow", statement("update-pokemon-named-arg")) - .addParam("name", name) - .addParam("id", id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedUpdateStrNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx - .createNamedUpdate("update-pokemon-named-arg") - .addParam("name", name) - .addParam("id", id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedUpdateStrOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedUpdate("update-pokemon-order-arg") - .addParam(name) - .addParam(id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateUpdateNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createUpdate(statement("update-pokemon-named-arg")) - .addParam("name", name) - .addParam("id", id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateUpdateOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createUpdate(statement("update-pokemon-order-arg")) - .addParam(name) - .addParam(id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testNamedUpdateNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.namedUpdate("update-pokemon-order-arg", name, id); - tx.commit(); - return count; - } - - @Override - protected long testUpdateOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.update(statement("update-pokemon-order-arg"), name, id); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDmlWithUpdateStrStrNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDmlStatement("update-piplup", statement("update-pokemon-named-arg")) - .addParam("name", name) - .addParam("id", id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDmlWithUpdateStrNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDmlStatement("update-pokemon-named-arg") - .addParam("name", name) - .addParam("id", id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateNamedDmlWithUpdateStrOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createNamedDmlStatement("update-pokemon-order-arg") - .addParam(name) - .addParam(id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateDmlWithUpdateNamedArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createDmlStatement(statement("update-pokemon-named-arg")) - .addParam("name", name) - .addParam("id", id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testCreateDmlWithUpdateOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.createDmlStatement(statement("update-pokemon-order-arg")) - .addParam(name) - .addParam(id) - .execute(); - tx.commit(); - return count; - } - - @Override - protected long testNamedDmlWithUpdateOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.namedDml("update-pokemon-order-arg", name, id); - tx.commit(); - return count; - } - - @Override - protected long testDmlWithUpdateOrderArgs(int id, String name) { - DbTransaction tx = dbClient().transaction(); - long count = tx.dml(statement("update-pokemon-order-arg"), name, id); - tx.commit(); - return count; - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tools/ExitService.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tools/ExitService.java deleted file mode 100644 index 01171894c25..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tools/ExitService.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tools; - -import io.helidon.common.media.type.MediaTypes; -import io.helidon.webserver.WebServer; -import io.helidon.webserver.http.HttpRules; -import io.helidon.webserver.http.HttpService; -import io.helidon.webserver.http.ServerRequest; -import io.helidon.webserver.http.ServerResponse; - -/** - * Service to terminate web server. - */ -public class ExitService implements HttpService { - - private WebServer server; - - @Override - public void routing(HttpRules rules) { - rules.get("/", this::exit); - } - - /** - * Set the server instance. - * - * @param server server - */ - public void setServer(WebServer server) { - this.server = server; - } - - private void exit(ServerRequest request, ServerResponse response) { - response.headers().contentType(MediaTypes.TEXT_PLAIN); - response.send("Testing web application shutting down."); - server.stop(); - } -} diff --git a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tools/QueryParams.java b/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tools/QueryParams.java deleted file mode 100644 index 368b54adf82..00000000000 --- a/tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tools/QueryParams.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tools; - -import java.util.HashMap; - -/** - * Query parameters map with builder. - */ -public class QueryParams extends HashMap { - - /** - * Query parameter {@code name}. - */ - public static final String NAME = "name"; - /** - * Query parameter {@code id} - */ - public static final String ID = "id"; - /** - * Query parameter {@code fromid}. - */ - public static final String FROM_ID = "fromid"; - /** - * Query parameter {@code toid}. - */ - public static final String TO_ID = "toid"; - - /** - * Shortcut for single parameter in a query. - * - * @param name name of parameter - * @param value value of parameter - * @return query parameters {@code Map} with provided single value - */ - public static QueryParams single(String name, String value) { - return QueryParams.builder().add(name, value).build(); - } - - /** - * Create query parameters builder. - * - * @return new query parameters builder instance - */ - public static Builder builder() { - return new Builder(); - } - - /** - * Query parameter builder. - */ - public static final class Builder { - - private final QueryParams params; - - private Builder() { - params = new QueryParams(); - } - - /** - * Add query parameter. - * - * @param name name of parameter - * @param value value of parameter - * @return updated query parameter builder - */ - public Builder add(String name, String value) { - params.put(name, value); - return this; - } - - /** - * Build query parameters with parameters currently stored in builder. - * - * @return query parameters {@code Map}. - */ - public QueryParams build() { - return params; - } - } -} diff --git a/tests/integration/dbclient/app/src/main/resources/h2.yaml b/tests/integration/dbclient/app/src/main/resources/h2.yaml deleted file mode 100644 index 9961aa9db56..00000000000 --- a/tests/integration/dbclient/app/src/main/resources/h2.yaml +++ /dev/null @@ -1,61 +0,0 @@ -# -# Copyright (c) 2022, 2023 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -db: - source: jdbc - connection: - url: ${db.url} - username: ${db.user} - password: ${db.password} - health-check: - type: query - statement: "SELECT 0" - statements: - ping-query: "SELECT 0" - create-types: "CREATE TABLE Types (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(64) NOT NULL)" - create-pokemons: "CREATE TABLE Pokemons (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(64) NOT NULL)" - create-poketypes: "CREATE TABLE PokemonTypes (id_pokemon INTEGER NOT NULL, id_type INTEGER NOT NULL REFERENCES Types(id))" - drop-types: "DROP TABLE Types" - drop-pokemons: "DROP TABLE Pokemons" - drop-poketypes: "DROP TABLE PokemonTypes" - insert-type: "INSERT INTO Types(id, name) VALUES(?, ?)" - insert-pokemon: "INSERT INTO Pokemons(id, name) VALUES(?, ?)" - insert-poketype: "INSERT INTO PokemonTypes(id_pokemon, id_type) VALUES(?, ?)" - select-types: "SELECT id, name FROM Types" - select-pokemons: "SELECT id, name FROM Pokemons" - select-poketypes: "SELECT id_pokemon, id_type FROM PokemonTypes p WHERE id_pokemon = ?" - get-pokemon-by-id: "SELECT id, name FROM Pokemons WHERE id = ?" - get-pokemon-types: "SELECT t.id AS id, t.name AS name FROM Types t INNER JOIN PokemonTypes pt ON pt.id_type = t.id WHERE pt.id_pokemon = ?" - select-poketypes-all: "SELECT id_pokemon, id_type FROM PokemonTypes" - select-max-id: "SELECT MAX(id) FROM Pokemons" - select-pokemon-named-arg: "SELECT id, name FROM Pokemons WHERE name=:name" - select-pokemon-order-arg: "SELECT id, name FROM Pokemons WHERE name=?" - insert-pokemon-named-arg: "INSERT INTO Pokemons(id, name) VALUES(:id, :name)" - insert-pokemon-order-arg: "INSERT INTO Pokemons(id, name) VALUES(?, ?)" - insert-pokemon-order-arg-rev: "INSERT INTO Pokemons(name, id) VALUES(?, ?)" - select-pokemon-by-id: "SELECT id, name FROM Pokemons WHERE id=?" - update-pokemon-named-arg: "UPDATE Pokemons SET name=:name WHERE id=:id" - update-pokemon-order-arg: "UPDATE Pokemons SET name=? WHERE id=?" - delete-pokemon-named-arg: "DELETE FROM Pokemons WHERE id=:id" - delete-pokemon-order-arg: "DELETE FROM Pokemons WHERE id=?" - delete-pokemon-full-named-arg: "DELETE FROM Pokemons WHERE name=:name AND id=:id" - delete-pokemon-full-order-arg: "DELETE FROM Pokemons WHERE name=? AND id=?" - select-pokemons-idrng-named-arg: "SELECT id, name FROM Pokemons WHERE id > :idmin AND id < :idmax" - select-pokemons-idrng-order-arg: "SELECT id, name FROM Pokemons WHERE id > ? AND id < ?" - select-pokemons-error-arg: "SELECT id, name FROM Pokemons WHERE id > :id AND name = ?" - -test: - ping-dml: false diff --git a/tests/integration/dbclient/app/src/main/resources/logging.properties b/tests/integration/dbclient/app/src/main/resources/logging.properties deleted file mode 100644 index e1b27ef2055..00000000000 --- a/tests/integration/dbclient/app/src/main/resources/logging.properties +++ /dev/null @@ -1,25 +0,0 @@ -# -# Copyright (c) 2020, 2023 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -handlers=io.helidon.logging.jul.HelidonConsoleHandler -# HelidonConsoleHandler uses a SimpleFormatter subclass that replaces "!thread!" with the current thread -java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$s %3$s !thread!: %5$s%6$s%n -# Global logging level. Can be overridden by specific loggers -.level=WARNING -io.helidon.level=INFO -io.helidon.config.level=INFO -io.helidon.webserver.http.level=WARNING -io.helidon.tests.integration.dbclient.app.level=INFO diff --git a/tests/integration/dbclient/app/src/main/resources/mysql.yaml b/tests/integration/dbclient/app/src/main/resources/mysql.yaml deleted file mode 100644 index a1ab39bfd79..00000000000 --- a/tests/integration/dbclient/app/src/main/resources/mysql.yaml +++ /dev/null @@ -1,59 +0,0 @@ -# -# Copyright (c) 2019, 2023 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -db: - source: jdbc - connection: - url: ${db.url} - username: ${db.user} - password: ${db.password} - health-check: - type: dml - statement: "DO 0" - statements: - ping-dml: "DO 0" - ping-query: "SELECT 0" - create-types: "CREATE TABLE Types (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(64) NOT NULL)" - create-pokemons: "CREATE TABLE Pokemons (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(64) NOT NULL)" - create-poketypes: "CREATE TABLE PokemonTypes (id_pokemon INTEGER NOT NULL, id_type INTEGER NOT NULL REFERENCES Types(id))" - drop-types: "DROP TABLE Types" - drop-pokemons: "DROP TABLE Pokemons" - drop-poketypes: "DROP TABLE PokemonTypes" - insert-type: "INSERT INTO Types(id, name) VALUES(?, ?)" - insert-pokemon: "INSERT INTO Pokemons(id, name) VALUES(?, ?)" - insert-poketype: "INSERT INTO PokemonTypes(id_pokemon, id_type) VALUES(?, ?)" - select-types: "SELECT id, name FROM Types" - select-pokemons: "SELECT id, name FROM Pokemons" - select-poketypes: "SELECT id_pokemon, id_type FROM PokemonTypes p WHERE id_pokemon = ?" - get-pokemon-by-id: "SELECT id, name FROM Pokemons WHERE id = ?" - get-pokemon-types: "SELECT t.id AS id, t.name AS name FROM Types t INNER JOIN PokemonTypes pt ON pt.id_type = t.id WHERE pt.id_pokemon = ?" - select-poketypes-all: "SELECT id_pokemon, id_type FROM PokemonTypes" - select-max-id: "SELECT MAX(id) FROM Pokemons" - select-pokemon-named-arg: "SELECT id, name FROM Pokemons WHERE name=:name" - select-pokemon-order-arg: "SELECT id, name FROM Pokemons WHERE name=?" - insert-pokemon-named-arg: "INSERT INTO Pokemons(id, name) VALUES(:id, :name)" - insert-pokemon-order-arg: "INSERT INTO Pokemons(id, name) VALUES(?, ?)" - insert-pokemon-order-arg-rev: "INSERT INTO Pokemons(name, id) VALUES(?, ?)" - select-pokemon-by-id: "SELECT id, name FROM Pokemons WHERE id=?" - update-pokemon-named-arg: "UPDATE Pokemons SET name=:name WHERE id=:id" - update-pokemon-order-arg: "UPDATE Pokemons SET name=? WHERE id=?" - delete-pokemon-named-arg: "DELETE FROM Pokemons WHERE id=:id" - delete-pokemon-order-arg: "DELETE FROM Pokemons WHERE id=?" - delete-pokemon-full-named-arg: "DELETE FROM Pokemons WHERE name=:name AND id=:id" - delete-pokemon-full-order-arg: "DELETE FROM Pokemons WHERE name=? AND id=?" - select-pokemons-idrng-named-arg: "SELECT id, name FROM Pokemons WHERE id > :idmin AND id < :idmax" - select-pokemons-idrng-order-arg: "SELECT id, name FROM Pokemons WHERE id > ? AND id < ?" - select-pokemons-error-arg: "SELECT id, name FROM Pokemons WHERE id > :id AND name = ?" diff --git a/tests/integration/dbclient/app/src/main/resources/pgsql.yaml b/tests/integration/dbclient/app/src/main/resources/pgsql.yaml deleted file mode 100644 index 7f66eceac99..00000000000 --- a/tests/integration/dbclient/app/src/main/resources/pgsql.yaml +++ /dev/null @@ -1,61 +0,0 @@ -# -# Copyright (c) 2021, 2023 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -db: - source: jdbc - connection: - url: ${db.url} - username: ${db.user} - password: ${db.password} - health-check: - type: query - statement: "SELECT 0" - statements: - ping-query: "SELECT 0" - create-types: "CREATE TABLE Types (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(64) NOT NULL)" - create-pokemons: "CREATE TABLE Pokemons (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(64) NOT NULL)" - create-poketypes: "CREATE TABLE PokemonTypes (id_pokemon INTEGER NOT NULL, id_type INTEGER NOT NULL REFERENCES Types(id))" - drop-types: "DROP TABLE Types" - drop-pokemons: "DROP TABLE Pokemons" - drop-poketypes: "DROP TABLE PokemonTypes" - insert-type: "INSERT INTO Types(id, name) VALUES(?, ?)" - insert-pokemon: "INSERT INTO Pokemons(id, name) VALUES(?, ?)" - insert-poketype: "INSERT INTO PokemonTypes(id_pokemon, id_type) VALUES(?, ?)" - select-types: "SELECT id, name FROM Types" - select-pokemons: "SELECT id, name FROM Pokemons" - select-poketypes: "SELECT id_pokemon, id_type FROM PokemonTypes p WHERE id_pokemon = ?" - get-pokemon-by-id: "SELECT id, name FROM Pokemons WHERE id = ?" - get-pokemon-types: "SELECT t.id AS id, t.name AS name FROM Types t INNER JOIN PokemonTypes pt ON pt.id_type = t.id WHERE pt.id_pokemon = ?" - select-poketypes-all: "SELECT id_pokemon, id_type FROM PokemonTypes" - select-max-id: "SELECT MAX(id) FROM Pokemons" - select-pokemon-named-arg: "SELECT id, name FROM Pokemons WHERE name=:name" - select-pokemon-order-arg: "SELECT id, name FROM Pokemons WHERE name=?" - insert-pokemon-named-arg: "INSERT INTO Pokemons(id, name) VALUES(:id, :name)" - insert-pokemon-order-arg: "INSERT INTO Pokemons(id, name) VALUES(?, ?)" - insert-pokemon-order-arg-rev: "INSERT INTO Pokemons(name, id) VALUES(?, ?)" - select-pokemon-by-id: "SELECT id, name FROM Pokemons WHERE id=?" - update-pokemon-named-arg: "UPDATE Pokemons SET name=:name WHERE id=:id" - update-pokemon-order-arg: "UPDATE Pokemons SET name=? WHERE id=?" - delete-pokemon-named-arg: "DELETE FROM Pokemons WHERE id=:id" - delete-pokemon-order-arg: "DELETE FROM Pokemons WHERE id=?" - delete-pokemon-full-named-arg: "DELETE FROM Pokemons WHERE name=:name AND id=:id" - delete-pokemon-full-order-arg: "DELETE FROM Pokemons WHERE name=? AND id=?" - select-pokemons-idrng-named-arg: "SELECT id, name FROM Pokemons WHERE id > :idmin AND id < :idmax" - select-pokemons-idrng-order-arg: "SELECT id, name FROM Pokemons WHERE id > ? AND id < ?" - select-pokemons-error-arg: "SELECT id, name FROM Pokemons WHERE id > :id AND name = ?" - -test: - ping-dml: false diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/DbInit.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/DbInit.java deleted file mode 100644 index e2d757ff393..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/DbInit.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.harness.HelidonTestException; -import io.helidon.tests.integration.harness.JsonValues; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; - -/** - * Database initializer. - */ -class DbInit { - - private static final System.Logger LOGGER = System.getLogger(DbInit.class.getName()); - - private final TestServiceClient testClient; - - /** - * Create a new instance - * - * @param port port - */ - DbInit(int port) { - this.testClient = TestClient.builder() - .port(port) - .service("Init") - .build(); - } - - /** - * Invoke {@code /Init/testPing}. - */ - public void testPing() { - executeTest("testPing"); - } - - /** - * Invoke {@code /Init/testDropSchema}. - */ - public void dropSchema() { - try { - executeInit("testDropSchema"); - } catch (HelidonTestException ex) { - LOGGER.log(Level.INFO, "Remote database tables did not exist."); - } - } - - /** - * Invoke {@code /Init/testHealthCheck}. - */ - public void testHealthCheck() { - executeTest("testHealthCheck"); - } - - /** - * Invoke {@code /Init/testInitSchema}. - */ - public void initSchema() { - executeInit("testInitSchema"); - } - - /** - * Invoke {@code /Init/testInitTypes}. - */ - public void initTypes() { - executeInit("testInitTypes"); - } - - /** - * Invoke {@code /Init/testInitPokemons}. - */ - public void initPokemons() { - executeInit("testInitPokemons"); - } - - /** - * Invoke {@code /Init/testInitPokemonTypes}. - */ - public void initPokemonTypes() { - executeInit("testInitPokemonTypes"); - } - - private void executeTest(String testName) { - JsonObject data = testClient - .callServiceAndGetData(testName) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - } - - private void executeInit(String testName) { - JsonValue data = testClient - .callServiceAndGetData(testName); - Long count = JsonValues.asLong(data); - LOGGER.log(Level.DEBUG, () -> String.format("Rows modified: %d", count)); - } -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/LogData.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/LogData.java deleted file mode 100644 index b33bd2bef4a..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/LogData.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app; - -import java.lang.System.Logger.Level; - -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; - -/** - * JSON Data Log Helper. - */ -public class LogData { - - private static final System.Logger LOGGER = System.getLogger(LogData.class.getName()); - - /** - * Log JSON object in human-readable form. - * - * @param level logging level - * @param data data to log - */ - public static void logJsonObject(Level level, JsonObject data) { - LOGGER.log(level, () -> "JSON object:"); - if (data == null) { - LOGGER.log(level, " is null"); - return; - } - if (data.isEmpty()) { - LOGGER.log(level, " is empty"); - return; - } - data.forEach((key, value) - -> LOGGER.log(level, () -> String.format(" - %s: %s", key, value.toString()))); - } - - /** - * Log JSON array in human-readable form. - * - * @param level logging level - * @param data data to log - */ - public static void logJsonArray(Level level, JsonArray data) { - LOGGER.log(level, () -> String.format("JSON array: %s", data.toString())); - data.forEach(row -> { - switch (row.getValueType()) { - case OBJECT: - LOGGER.log(level, () -> " - Row:"); - row.asJsonObject().forEach((key, value) - -> LOGGER.log(level, () -> String.format(" - %s: %s", key, value.toString()))); - default: - LOGGER.log(level, () -> String.format(" - %s", row.toString())); - } - }); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/SuiteIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/SuiteIT.java deleted file mode 100644 index bffd7cbd1be..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/SuiteIT.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Map; - -import io.helidon.logging.common.LogConfig; -import io.helidon.webclient.http1.Http1Client; -import io.helidon.webclient.http1.Http1ClientResponse; -import io.helidon.webserver.WebServer; -import io.helidon.tests.integration.harness.AfterSuite; -import io.helidon.tests.integration.harness.BeforeSuite; -import io.helidon.tests.integration.harness.HelidonProcessRunner; -import io.helidon.tests.integration.harness.HelidonProcessRunner.ExecType; - -import org.junit.platform.suite.api.IncludeClassNamePatterns; -import org.junit.platform.suite.api.SelectPackages; -import org.junit.platform.suite.api.Suite; - -@Suite -@SelectPackages("io.helidon.tests.integration.dbclient.app.tests") -@IncludeClassNamePatterns(".*IT") -class SuiteIT { - - private static final System.Logger LOGGER = System.getLogger(SuiteIT.class.getName()); - private static final int SLEEP_MILLIS = 250; - private static final int TIMEOUT = 60; - - @BeforeSuite - static Map setup() { - LogConfig.configureRuntime(); - LOGGER.log(System.Logger.Level.DEBUG, "Running test suite setup"); - - String appConfigProperty = System.getProperty("app.config"); - ExecType execType = ExecType.of(System.getProperty("app.execType", "classpath")); - WebServer[] server = new WebServer[1]; - HelidonProcessRunner processRunner = HelidonProcessRunner.builder() - .execType(execType) - .moduleName("io.helidon.tests.integration.dbclient.app") - .mainClass(Main.class.getName()) - .finalName("helidon-tests-integration-dbclient-app") - .args(new String[]{appConfigProperty}) - .inMemoryStartCommand(() -> server[0] = Main.startServer(appConfigProperty)) - .inMemoryStopCommand(() -> server[0].stop()) - .build() - .startApplication(); - - int serverPort = processRunner.port(); - - waitForDatabase(); - - // Call schema initialization services - if ("h2.yaml".equals(appConfigProperty)) { - DbInit dbInit = new DbInit(serverPort); - dbInit.dropSchema(); - dbInit.initSchema(); - dbInit.initTypes(); - dbInit.initPokemons(); - dbInit.initPokemonTypes(); - } - - return Map.of("processRunner", processRunner, "serverPort", serverPort); - } - - @AfterSuite - static void tearDown(int serverPort) { - LOGGER.log(System.Logger.Level.DEBUG, "Running test application close()"); - Http1Client testClient = Http1Client.builder() - .baseUri(String.format("http://localhost:%d", serverPort)) - .build(); - try (Http1ClientResponse response = testClient.get() - .path("/Exit") - .request()) { - LOGGER.log(System.Logger.Level.INFO, () -> String.format( - "Status: %s", - response.status())); - LOGGER.log(System.Logger.Level.INFO, () -> String.format( - "Response: %s", - response.entity().as(String.class))); - } - } - - @SuppressWarnings({"SleepWhileInLoop", "BusyWait"}) - private static void waitForDatabase() { - String user = System.getProperty("db.user"); - String password = System.getProperty("db.password"); - String url = System.getProperty("db.url"); - if (user == null) { - throw new IllegalStateException("Database user name was not set!"); - } - if (password == null) { - throw new IllegalStateException("Database user password was not set!"); - } - if (url == null) { - throw new IllegalStateException("Database URL was not set!"); - } - long endTm = 1000 * TIMEOUT + System.currentTimeMillis(); - while (true) { - try { - LOGGER.log(System.Logger.Level.DEBUG, () -> String.format( - "Connection check: user=%s password=%s url=%s", - user, password, url)); - Connection conn = DriverManager.getConnection(url, user, password); - closeConnection(conn); - return; - } catch (SQLException ex) { - LOGGER.log(System.Logger.Level.DEBUG, () -> String.format( - "Connection check: %s", ex.getMessage())); - if (System.currentTimeMillis() > endTm) { - throw new IllegalStateException(String.format( - "Database is not ready within %d seconds", TIMEOUT)); - } - try { - Thread.sleep(SLEEP_MILLIS); - } catch (InterruptedException ie) { - LOGGER.log(System.Logger.Level.WARNING, () -> String.format( - "Thread was interrupted: %s", ie.getMessage()), ie); - } - } - } - } - - private static void closeConnection(Connection connection) { - try { - connection.close(); - } catch (SQLException ex) { - LOGGER.log(System.Logger.Level.WARNING, () -> String.format( - "Could not close database connection: %s", ex.getMessage())); - } - } -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/VerifyData.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/VerifyData.java deleted file mode 100644 index 0cd875961ca..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/VerifyData.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app; - -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; - -import jakarta.json.JsonObject; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; - -/** - * Test data verification helper methods. - */ -public class VerifyData { - - private static final String POKEMON_ID_KEY = "id"; - private static final String POKEMON_NAME_KEY = "name"; - - /** - * Verify that returned data contain single record with expected data. - * - * @param actual database query result to verify - * @param expected data to compare with - */ - public static void verifyPokemon(JsonObject actual, Pokemon expected) { - assertThat(actual, notNullValue()); - assertThat(actual.isEmpty(), is(false)); - Integer id = actual.getInt(POKEMON_ID_KEY); - String name = actual.getString(POKEMON_NAME_KEY); - assertThat(id, equalTo(expected.getId())); - assertThat(name, expected.getName().equals(name)); - } - - /** - * Verify that returned data contain single record with expected data. - * - * @param actual database query result to verify - * @param expected data to compare with - */ - public static void verifyPokemon(JsonObject actual, JsonObject expected) { - assertThat(actual, notNullValue()); - assertThat(expected, notNullValue()); - Integer id = actual.getInt(POKEMON_ID_KEY); - String name = actual.getString(POKEMON_NAME_KEY); - assertThat(id, equalTo(expected.getInt(POKEMON_ID_KEY))); - assertThat(name, equalTo(expected.getString(POKEMON_NAME_KEY))); - } - - /** - * Retrieve record as JSON object from remote web resource. - * - * @param testClient webclient used to access remote web resource - * @param id ID of record to retrieve - * @return JSON object - */ - public static JsonObject getPokemon(TestClient testClient, int id) { - return testClient.callServiceAndGetData( - "Verify", - "getPokemonById", - QueryParams.single(QueryParams.ID, String.valueOf(id))) - .asJsonObject(); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/FlowControlIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/FlowControlIT.java deleted file mode 100644 index 9db515d4c2b..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/FlowControlIT.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import org.junit.jupiter.api.MethodOrderer; -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; - -/** - * Verify proper flow control handling in query processing. - */ -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) -class FlowControlIT { - - private static final System.Logger LOGGER = System.getLogger(FlowControlIT.class.getName()); - - private final TestServiceClient testClient; - - FlowControlIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("FlowControl") - .build(); - } - - private void executeTest(String testName) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonObject data = testClient - .callServiceAndGetData(testName) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - } - - /** - * Source data verification test. - */ - @Test - @Order(1) - void testSourceData() { - executeTest("testSourceData"); - } - - /** - * Flow control test. - */ - @Test - @Order(2) - void testFlowControl() { - executeTest("testFlowControl"); - } -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/HealthCheckIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/HealthCheckIT.java deleted file mode 100644 index f85571945f2..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/HealthCheckIT.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.health.HealthCheckResponse; -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Test {@link io.helidon.dbclient.health.DbClientHealthCheck}. - */ -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -class HealthCheckIT { - - private static final System.Logger LOGGER = System.getLogger(HealthCheckIT.class.getName()); - - private final TestServiceClient testClient; - private String dbType = null; - private boolean pingDml = true; - - HealthCheckIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("HealthCheck") - .build(); - } - - @BeforeAll - void setup() { - JsonObject dbTypeValue = testClient - .callServiceAndGetData("Verify", "getDatabaseType", null) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, dbTypeValue); - dbType = dbTypeValue.getString("type"); - JsonObject pingDmlValue = testClient - .callServiceAndGetData( - "Verify", "getConfigParam", - QueryParams.single(QueryParams.NAME, "test.ping-dml")) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, pingDmlValue); - if (pingDmlValue.containsKey("config")) { - pingDml = Boolean.parseBoolean(pingDmlValue.getString("config")); - } - } - - /** - * Verify health check implementation with default settings. - */ - @Test - void testHealthCheck() { - JsonObject data = testClient - .callServiceAndGetData("testHealthCheck") - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - assertThat(data.getString("status"), equalTo(HealthCheckResponse.Status.UP.name())); - } - - /** - * Verify health check implementation with builder and custom name. - */ - @Test - void testHealthCheckWithName() { - String hcName = "TestHC"; - JsonObject data = testClient - .callServiceAndGetData( - "testHealthCheckWithName", - QueryParams.single(QueryParams.NAME, hcName)) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - assertThat(data.getString("status"), equalTo(HealthCheckResponse.Status.UP.name())); - assertThat(data.getString("name"), equalTo(hcName)); - } - - /** - * Verify health check implementation using custom DML named statement. - */ - @Test - void testHealthCheckWithCustomNamedDML() { - if (!pingDml) { - LOGGER.log(Level.INFO, () -> String.format("Database %s does not support DML ping, skipping this test", dbType)); - return; - } - JsonObject data = testClient - .callServiceAndGetData("testHealthCheckWithCustomNamedDML") - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - assertThat(data.getString("status"), equalTo(HealthCheckResponse.Status.UP.name())); - } - - /** - * Verify health check implementation using custom DML statement. - */ - @Test - void testHealthCheckWithCustomDML() { - if (!pingDml) { - LOGGER.log(Level.DEBUG, () -> String.format("Database %s does not support DML ping, skipping this test", dbType)); - return; - } - JsonObject data = testClient - .callServiceAndGetData("testHealthCheckWithCustomDML") - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - assertThat(data.getString("status"), equalTo(HealthCheckResponse.Status.UP.name())); - } - - /** - * Verify health check implementation using custom query named statement. - */ - @Test - void testHealthCheckWithCustomNamedQuery() { - JsonObject data = testClient - .callServiceAndGetData("testHealthCheckWithCustomNamedQuery") - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - assertThat(data.getString("status"), equalTo(HealthCheckResponse.Status.UP.name())); - } - - /** - * Verify health check implementation using custom query statement. - */ - @Test - void testHealthCheckWithCustomQuery() { - JsonObject data = testClient - .callServiceAndGetData("testHealthCheckWithCustomQuery") - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - assertThat(data.getString("status"), equalTo(HealthCheckResponse.Status.UP.name())); - } -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/InterceptorIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/InterceptorIT.java deleted file mode 100644 index 872988740c5..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/InterceptorIT.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import org.junit.jupiter.api.Test; - -/** - * Test {@link io.helidon.dbclient.DbClientService}. - */ -class InterceptorIT { - - private static final System.Logger LOGGER = System.getLogger(InterceptorIT.class.getName()); - - private final TestServiceClient testClient; - - InterceptorIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("Interceptor") - .build(); - } - - /** - * Check that statement interceptor was called before statement execution. - */ - @Test - void testStatementInterceptor() { - LOGGER.log(System.Logger.Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), "testStatementInterceptor")); - testClient.callServiceAndGetData("testStatementInterceptor"); - } -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/MapperIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/MapperIT.java deleted file mode 100644 index b981f9a05b8..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/MapperIT.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.JsonValues; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Verify mapping interface. - */ -class MapperIT { - - private static final System.Logger LOGGER = System.getLogger(MapperIT.class.getName()); - - private final TestServiceClient testClient; - - MapperIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("Mapper") - .build(); - } - - /** - * Verify insertion using indexed mapping. - */ - @Test - void testInsertWithOrderMapping() { - executeInsertTest("testInsertWithOrderMapping", 103); - } - - /** - * Verify insertion using named mapping. - */ - @Test - void testInsertWithNamedMapping() { - executeInsertTest("testInsertWithNamedMapping", 104); - } - - /** - * Verify update using indexed mapping. - */ - @Test - void testUpdateWithOrderMapping() { - executeUpdateTest("testUpdateWithOrderMapping", 99, "Masquerain"); - } - - /** - * Verify update using named mapping. - */ - @Test - void testUpdateWithNamedMapping() { - executeUpdateTest("testUpdateWithNamedMapping", 100, "Moltres"); - } - - /** - * Verify delete using indexed mapping. - */ - @Test - void testDeleteWithOrderMapping() { - executeDeleteTest("testDeleteWithOrderMapping", 101); - } - - /** - * Verify delete using named mapping. - */ - @Test - void testDeleteWithNamedMapping() { - executeDeleteTest("testDeleteWithNamedMapping", 102); - } - - // Query and Get calls are here just once so no common executor code is needed. - - /** - * Verify query as a result using mapping. - */ - @Test - void testQueryWithMapping() { - Pokemon pokemon = Pokemon.POKEMONS.get(1); - JsonArray data = testClient - .callServiceAndGetData( - "testQueryWithMapping", - QueryParams.single(QueryParams.NAME, pokemon.getName())) - .asJsonArray(); - LogData.logJsonArray(Level.DEBUG, data); - assertThat(data.size(), equalTo(1)); - VerifyData.verifyPokemon(data.getJsonObject(0), pokemon); - } - - /** - * Verify get as a result using mapping. - */ - @Test - void testGetWithMapping() { - Pokemon pokemon = Pokemon.POKEMONS.get(2); - JsonObject data = testClient - .callServiceAndGetData( - "testGetWithMapping", - QueryParams.single(QueryParams.NAME, pokemon.getName())) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - VerifyData.verifyPokemon(data, pokemon); - } - - private void executeInsertTest(String testName, int id) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonObject data = testClient - .callServiceAndGetData( - testName, - QueryParams.single(QueryParams.ID, String.valueOf(id))) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - JsonObject pokemonData = VerifyData.getPokemon(testClient, id); - LogData.logJsonObject(Level.DEBUG, pokemonData); - VerifyData.verifyPokemon(pokemonData, data); - } - - private void executeUpdateTest(String testName, int id, String newName) { - LOGGER.log(Level.DEBUG, () -> String.format("Running MapperIT.%s on client", testName)); - 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 = JsonValues.asLong(data); - LOGGER.log(Level.DEBUG, () -> String.format("Rows updated: %d", count)); - JsonObject pokemonData = VerifyData.getPokemon(testClient, pokemon.getId()); - LogData.logJsonObject(Level.DEBUG, pokemonData); - assertThat(count, equalTo(1L)); - VerifyData.verifyPokemon(pokemonData, updatedPokemon); - } - - private void executeDeleteTest(String testName, int id) { - LOGGER.log(Level.DEBUG, () -> String.format("Running MapperIT.%s on client", testName)); - JsonValue data = testClient - .callServiceAndGetData( - testName, - QueryParams.single(QueryParams.ID, String.valueOf(id))); - Long count = JsonValues.asLong(data); - LOGGER.log(Level.DEBUG, () -> String.format("Rows deleted: %d", count)); - JsonObject pokemonData = VerifyData.getPokemon(testClient, id); - LogData.logJsonObject(Level.DEBUG, pokemonData); - assertThat(count, equalTo(1L)); - assertThat(pokemonData.isEmpty(), equalTo(true)); - } -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/ServerMetricsCheckIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/ServerMetricsCheckIT.java deleted file mode 100644 index 3b1c05d4c16..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/ServerMetricsCheckIT.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; - -import io.helidon.tests.integration.harness.TestServiceClient; -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.notNullValue; - -/** - * Test JDBC metrics. - */ -class ServerMetricsCheckIT { - - private static final System.Logger LOGGER = System.getLogger(ServerMetricsCheckIT.class.getName()); - - private final TestClient testClient; - - ServerMetricsCheckIT(int serverPort) { - this.testClient = TestServiceClient.builder() - .port(serverPort) - .build(); - } - - /** - * Read and check Database Client metrics from Helidon Web Server. - * - */ - @Test - void testHttpMetrics() { - LOGGER.log(System.Logger.Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), "testHttpMetrics")); - - // Call select-pokemon-named-arg query to initialize counter - testClient.callServiceAndGetData( - "SimpleGet", - "testCreateNamedGetStrNamedArgs", - QueryParams.single(QueryParams.NAME, Pokemon.POKEMONS.get(1).getName())); - // Call select-pokemon-order-arg query to initialize counter - testClient.callServiceAndGetData( - "SimpleGet", - "testCreateNamedGetStrOrderArgs", - QueryParams.single(QueryParams.NAME, Pokemon.POKEMONS.get(2).getName())); - - JsonObject application; - application = testClient.callServiceAndGetRawData("observe/metrics", "application"); - assertThat(application, notNullValue()); - assertThat(application.getValueType(), equalTo(JsonValue.ValueType.OBJECT)); - assertThat(application.size(), greaterThan(0)); - assertThat(application.containsKey("db.counter.select-pokemon-named-arg"), equalTo(true)); - assertThat(application.containsKey("db.counter.select-pokemon-order-arg"), equalTo(true)); - assertThat(application.containsKey("db.counter.insert-pokemon"), equalTo(true)); - int selectPokemons = application.getInt("db.counter.select-pokemon-named-arg"); - int insertPokemons = application.getInt("db.counter.insert-pokemon"); - assertThat(selectPokemons, greaterThan(0)); - assertThat(insertPokemons, greaterThan(0)); - assertThat(application.containsKey("db.timer.select-pokemon-named-arg"), equalTo(true)); - assertThat(application.containsKey("db.timer.select-pokemon-named-arg"), equalTo(true)); - JsonObject insertTimer = application.getJsonObject("db.timer.select-pokemon-named-arg"); - assertThat(insertTimer.containsKey("count"), equalTo(true)); - assertThat(insertTimer.containsKey("max"), equalTo(true)); - int timerCount = insertTimer.getInt("count"); - assertThat(timerCount, greaterThan(0)); - } -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleDeleteIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleDeleteIT.java deleted file mode 100644 index c1722a72537..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleDeleteIT.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.JsonValues; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Test simple delete statements. - */ -class SimpleDeleteIT { - - private static final System.Logger LOGGER = System.getLogger(SimpleDeleteIT.class.getName()); - - private final TestServiceClient testClient; - - SimpleDeleteIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("SimpleDelete") - .build(); - } - - private void executeTest(String testName, int id) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonValue data = testClient - .callServiceAndGetData( - testName, - QueryParams.single(QueryParams.ID, String.valueOf(id))); - Long count = JsonValues.asLong(data); - LOGGER.log(Level.DEBUG, () -> String.format("Rows deleted: %d", count)); - JsonObject pokemonData = VerifyData.getPokemon(testClient, id); - LogData.logJsonObject(Level.DEBUG, pokemonData); - assertThat(count, equalTo(1L)); - assertThat(pokemonData.isEmpty(), equalTo(true)); - } - - /** - * Verify {@code createNamedDelete(String, String)} API method with ordered parameters. - */ - @Test - void testCreateNamedDeleteStrStrOrderArgs() { - executeTest("testCreateNamedDeleteStrStrOrderArgs", 15); - } - - /** - * Verify {@code createNamedDelete(String)} API method with named parameters. - */ - @Test - void testCreateNamedDeleteStrNamedArgs() { - executeTest("testCreateNamedDeleteStrNamedArgs", 16); - } - - /** - * Verify {@code createNamedDelete(String)} API method with ordered parameters. - */ - @Test - void testCreateNamedDeleteStrOrderArgs() { - executeTest("testCreateNamedDeleteStrOrderArgs", 17); - } - - /** - * Verify {@code createDelete(String)} API method with named parameters. - */ - @Test - void testCreateDeleteNamedArgs() { - executeTest("testCreateDeleteNamedArgs", 18); - } - - /** - * Verify {@code createDelete(String)} API method with ordered parameters. - */ - @Test - void testCreateDeleteOrderArgs() { - executeTest("testCreateDeleteOrderArgs", 19); - } - - /** - * Verify {@code namedDelete(String)} API method with ordered parameters. - */ - @Test - void testNamedDeleteOrderArgs() { - executeTest("testNamedDeleteOrderArgs", 20); - } - - /** - * Verify {@code delete(String)} API method with ordered parameters. - */ - @Test - void testDeleteOrderArgs() { - executeTest("testDeleteOrderArgs", 21); - } - - // DML delete - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with delete with ordered parameters. - */ - @Test - void testCreateNamedDmlWithDeleteStrStrOrderArgs() { - executeTest("testCreateNamedDmlWithDeleteStrStrOrderArgs", 36); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with delete with named parameters. - */ - @Test - void testCreateNamedDmlWithDeleteStrNamedArgs() { - executeTest("testCreateNamedDmlWithDeleteStrNamedArgs", 37); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with delete with ordered parameters. - */ - @Test - void testCreateNamedDmlWithDeleteStrOrderArgs() { - executeTest("testCreateNamedDmlWithDeleteStrOrderArgs", 38); - } - - /** - * Verify {@code createDmlStatement(String)} API method with delete with named parameters. - */ - @Test - void testCreateDmlWithDeleteNamedArgs() { - executeTest("testCreateDmlWithDeleteNamedArgs", 39); - } - - /** - * Verify {@code createDmlStatement(String)} API method with delete with ordered parameters. - */ - @Test - void testCreateDmlWithDeleteOrderArgs() { - executeTest("testCreateDmlWithDeleteOrderArgs", 40); - } - - /** - * Verify {@code namedDml(String)} API method with delete with ordered parameters. - */ - @Test - void testNamedDmlWithDeleteOrderArgs() { - executeTest("testNamedDmlWithDeleteOrderArgs", 41); - } - - /** - * Verify {@code dml(String)} API method with delete with ordered parameters. - */ - @Test - void testDmlWithDeleteOrderArgs() { - executeTest("testDmlWithDeleteOrderArgs", 42); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleGetIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleGetIT.java deleted file mode 100644 index 0fb26a5199f..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleGetIT.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import org.junit.jupiter.api.Test; - -/** - * Test simple get statements. - */ -class SimpleGetIT { - - private static final System.Logger LOGGER = System.getLogger(SimpleGetIT.class.getName()); - - private final TestServiceClient testClient; - - SimpleGetIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("SimpleGet") - .build(); - } - - void executeTest(String testName, Pokemon pokemon) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonObject data = testClient - .callServiceAndGetData( - testName, - QueryParams.single(QueryParams.NAME, pokemon.getName())) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - VerifyData.verifyPokemon(data, pokemon); - } - - /** - * Verify {@code createNamedGet(String, String)} API method with named - * parameters. - */ - @Test - void testCreateNamedGetStrStrNamedArgs() { - executeTest("testCreateNamedGetStrStrNamedArgs", Pokemon.POKEMONS.get(1)); - } - - /** - * Verify {@code createNamedGet(String)} API method with named parameters. - */ - @Test - void testCreateNamedGetStrNamedArgs() { - executeTest("testCreateNamedGetStrNamedArgs", Pokemon.POKEMONS.get(2)); - } - - /** - * Verify {@code createNamedGet(String)} API method with ordered parameters. - */ - @Test - void testCreateNamedGetStrOrderArgs() { - executeTest("testCreateNamedGetStrOrderArgs", Pokemon.POKEMONS.get(3)); - } - - /** - * Verify {@code createGet(String)} API method with named parameters. - */ - @Test - void testCreateGetNamedArgs() { - executeTest("testCreateGetNamedArgs", Pokemon.POKEMONS.get(4)); - } - - /** - * Verify {@code createGet(String)} API method with ordered parameters. - */ - @Test - void testCreateGetOrderArgs() { - executeTest("testCreateGetOrderArgs", Pokemon.POKEMONS.get(5)); - } - - /** - * Verify {@code namedGet(String)} API method with ordered parameters passed - * directly to the {@code query} method. - */ - @Test - void testNamedGetStrOrderArgs() { - executeTest("testNamedGetStrOrderArgs", Pokemon.POKEMONS.get(6)); - } - - /** - * Verify {@code get(String)} API method with ordered parameters passed - * directly to the {@code query} method. - */ - @Test - void testGetStrOrderArgs() { - executeTest("testGetStrOrderArgs", Pokemon.POKEMONS.get(7)); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleInsertIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleInsertIT.java deleted file mode 100644 index 097cbf8ad50..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleInsertIT.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import org.junit.jupiter.api.Test; - -/** - * Test simple insert statements. - */ -class SimpleInsertIT { - - private static final System.Logger LOGGER = System.getLogger(SimpleInsertIT.class.getName()); - - private final TestServiceClient testClient; - - SimpleInsertIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("SimpleInsert") - .build(); - } - - private void executeTest(String testName, int id) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonObject data = testClient.callServiceAndGetData( - testName, - QueryParams.single(QueryParams.ID, String.valueOf(id))) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - JsonObject pokemonData = VerifyData.getPokemon(testClient, id); - LogData.logJsonObject(Level.DEBUG, pokemonData); - VerifyData.verifyPokemon(pokemonData, data); - } - - /** - * Verify {@code createNamedInsert(String, String)} API method with named parameters. - */ - @Test - void testCreateNamedInsertStrStrNamedArgs() { - executeTest("testCreateNamedInsertStrStrNamedArgs", 22); - } - - /** - * Verify {@code createNamedInsert(String)} API method with named parameters. - */ - @Test - void testCreateNamedInsertStrNamedArgs() { - executeTest("testCreateNamedInsertStrNamedArgs", 23); - } - - /** - * Verify {@code createNamedInsert(String)} API method with ordered parameters. - */ - @Test - void testCreateNamedInsertStrOrderArgs() { - executeTest("testCreateNamedInsertStrOrderArgs", 24); - } - - /** - * Verify {@code createInsert(String)} API method with named parameters. - */ - @Test - void testCreateInsertNamedArgs() { - executeTest("testCreateInsertNamedArgs", 25); - } - - /** - * Verify {@code createInsert(String)} API method with ordered parameters. - */ - @Test - void testCreateInsertOrderArgs() { - executeTest("testCreateInsertOrderArgs", 26); - } - - /** - * Verify {@code namedInsert(String)} API method with ordered parameters passed directly to the {@code insert} method. - */ - @Test - void testNamedInsertOrderArgs() { - executeTest("testNamedInsertOrderArgs", 27); - } - - /** - * Verify {@code insert(String)} API method with ordered parameters passed directly to the {@code insert} method. - */ - @Test - void testInsertOrderArgs() { - executeTest("testInsertOrderArgs", 28); - } - - // DML insert - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with insert with named parameters. - */ - @Test - void testCreateNamedDmlWithInsertStrStrNamedArgs() { - executeTest("testCreateNamedDmlWithInsertStrStrNamedArgs", 43); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with insert with named parameters. - */ - @Test - void testCreateNamedDmlWithInsertStrNamedArgs() { - executeTest("testCreateNamedDmlWithInsertStrNamedArgs", 44); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with insert with ordered parameters. - */ - @Test - void testCreateNamedDmlWithInsertStrOrderArgs() { - executeTest("testCreateNamedDmlWithInsertStrOrderArgs", 45); - } - - /** - * Verify {@code createDmlStatement(String)} API method with insert with named parameters. - */ - @Test - void testCreateDmlWithInsertNamedArgs() { - executeTest("testCreateDmlWithInsertNamedArgs", 46); - } - - /** - * Verify {@code createDmlStatement(String)} API method with insert with ordered parameters. - */ - @Test - void testCreateDmlWithInsertOrderArgs() { - executeTest("testCreateDmlWithInsertOrderArgs", 47); - } - - /** - * Verify {@code namedDml(String)} API method with insert with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - void testNamedDmlWithInsertOrderArgs() { - executeTest("testNamedDmlWithInsertOrderArgs", 48); - } - - /** - * Verify {@code dml(String)} API method with insert with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - void testDmlWithInsertOrderArgs() { - executeTest("testDmlWithInsertOrderArgs", 49); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleQueriesIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleQueriesIT.java deleted file mode 100644 index b696716fcf9..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleQueriesIT.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonArray; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; - -/** - * Test simple query statements. - */ -class SimpleQueriesIT { - - private static final System.Logger LOGGER = System.getLogger(SimpleQueriesIT.class.getName()); - - private final TestServiceClient testClient; - - SimpleQueriesIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("SimpleQuery") - .build(); - } - - private void executeTest(String testName, Pokemon pokemon) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonArray data = testClient - .callServiceAndGetData( - testName, - QueryParams.single(QueryParams.NAME, pokemon.getName())) - .asJsonArray(); - LogData.logJsonArray(Level.DEBUG, data); - assertThat(data.size(), Matchers.equalTo(1)); - VerifyData.verifyPokemon(data.getJsonObject(0), pokemon); - } - - /** - * Verify {@code createNamedQuery(String, String)} API method with ordered parameters. - */ - @Test - void testCreateNamedQueryStrStrOrderArgs() { - executeTest("testCreateNamedQueryStrStrOrderArgs", Pokemon.POKEMONS.get(1)); - } - - /** - * Verify {@code createNamedQuery(String)} API method with named parameters. - */ - @Test - void testCreateNamedQueryStrNamedArgs() { - executeTest("testCreateNamedQueryStrNamedArgs", Pokemon.POKEMONS.get(2)); - } - - /** - * Verify {@code createNamedQuery(String)} API method with ordered parameters. - */ - @Test - void testCreateNamedQueryStrOrderArgs() { - executeTest("testCreateNamedQueryStrOrderArgs", Pokemon.POKEMONS.get(3)); - } - - /** - * Verify {@code createQuery(String)} API method with named parameters. - */ - @Test - void testCreateQueryNamedArgs() { - executeTest("testCreateQueryNamedArgs", Pokemon.POKEMONS.get(4)); - } - - /** - * Verify {@code createQuery(String)} API method with ordered parameters. - */ - @Test - void testCreateQueryOrderArgs() { - executeTest("testCreateQueryOrderArgs", Pokemon.POKEMONS.get(5)); - } - - /** - * Verify {@code namedQuery(String)} API method with ordered parameters passed directly to the {@code namedQuery} method. - */ - @Test - void testNamedQueryOrderArgs() { - executeTest("testNamedQueryOrderArgs", Pokemon.POKEMONS.get(6)); - } - - /** - * Verify {@code query(String)} API method with ordered parameters passed directly to the {@code query} method. - */ - @Test - void testQueryOrderArgs() { - executeTest("testQueryOrderArgs", Pokemon.POKEMONS.get(7)); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleUpdateIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleUpdateIT.java deleted file mode 100644 index 6bf64bd5373..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleUpdateIT.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.JsonValues; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Test simple update statements. - */ -class SimpleUpdateIT { - - private static final System.Logger LOGGER = System.getLogger(SimpleUpdateIT.class.getName()); - - private final TestServiceClient testClient; - - SimpleUpdateIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("SimpleUpdate") - .build(); - } - - private void executeTest(String testName, int id, String newName) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - 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 = JsonValues.asLong(data); - LOGGER.log(Level.DEBUG, () -> String.format("Rows updated: %d", count)); - JsonObject pokemonData = VerifyData.getPokemon(testClient, pokemon.getId()); - LogData.logJsonObject(Level.DEBUG, pokemonData); - assertThat(count, equalTo(1L)); - VerifyData.verifyPokemon(pokemonData, updatedPokemon); - } - - /** - * Verify {@code createNamedUpdate(String, String)} API method with ordered parameters. - */ - @Test - void testCreateNamedUpdateStrStrNamedArgs() { - executeTest("testCreateNamedUpdateStrStrNamedArgs", 8, "Fearow"); - } - - /** - * Verify {@code createNamedUpdate(String)} API method with named parameters. - */ - @Test - void testCreateNamedUpdateStrNamedArgs() { - executeTest("testCreateNamedUpdateStrNamedArgs", 9, "Spearow"); - } - - /** - * Verify {@code createNamedUpdate(String, String)} API method with ordered parameters. - */ - @Test - void testCreateNamedUpdateStrOrderArgs() { - executeTest("testCreateNamedUpdateStrOrderArgs", 10, "Arbok"); - } - - /** - * Verify {@code createUpdate(String)} API method with named parameters. - */ - @Test - void testCreateUpdateNamedArgs() { - executeTest("testCreateUpdateNamedArgs", 11, "Ekans"); - } - - - /** - * Verify {@code createUpdate(String)} API method with named parameters. - */ - @Test - void testCreateUpdateOrderArgs() { - executeTest("testCreateUpdateOrderArgs", 12, "Diglett"); - } - - /** - * Verify {@code namedUpdate(String, String)} API method with ordered parameters. - */ - @Test - void testNamedUpdateNamedArgs() { - executeTest("testNamedUpdateNamedArgs", 13, "Sandshrew"); - } - - /** - * Verify {@code update(String)} API method with named parameters. - */ - @Test - void testUpdateOrderArgs() { - executeTest("testUpdateOrderArgs", 14, "Sandslash"); - } - - // DML update - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with update with named parameters. - */ - @Test - void testCreateNamedDmlWithUpdateStrStrNamedArgs() { - executeTest("testCreateNamedDmlWithUpdateStrStrNamedArgs", 29, "Prinplup"); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with update with named parameters. - */ - @Test - void testCreateNamedDmlWithUpdateStrNamedArgs() { - executeTest("testCreateNamedDmlWithUpdateStrNamedArgs", 30, "Empoleon"); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with update with ordered parameters. - */ - @Test - void testCreateNamedDmlWithUpdateStrOrderArgs() { - executeTest("testCreateNamedDmlWithUpdateStrOrderArgs", 31, "Piplup"); - } - - /** - * Verify {@code createDmlStatement(String)} API method with update with named parameters. - */ - @Test - void testCreateDmlWithUpdateNamedArgs() { - executeTest("testCreateDmlWithUpdateNamedArgs", 32, "Starmie"); - } - - /** - * Verify {@code createDmlStatement(String)} API method with update with ordered parameters. - */ - @Test - void testCreateDmlWithUpdateOrderArgs() { - executeTest("testCreateDmlWithUpdateOrderArgs", 33, "Staryu"); - } - - /** - * Verify {@code namedDml(String)} API method with update with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - void testNamedDmlWithUpdateOrderArgs() { - executeTest("testNamedDmlWithUpdateOrderArgs", 34, "Seadra"); - } - - /** - * Verify {@code dml(String)} API method with update with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - void testDmlWithUpdateOrderArgs() { - executeTest("testDmlWithUpdateOrderArgs", 35, "Horsea"); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementDmlIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementDmlIT.java deleted file mode 100644 index e4de9d1cd14..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementDmlIT.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.JsonValues; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Test DML statements. - */ -class StatementDmlIT { - - private static final System.Logger LOGGER = System.getLogger(StatementDmlIT.class.getName()); - - private final TestServiceClient testClient; - - StatementDmlIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("StatementDml") - .build(); - } - - private void executeTest(String testName, int id, String newName) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - 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 = JsonValues.asLong(data); - LOGGER.log(Level.DEBUG, () -> String.format("Rows modified: %d", count)); - JsonObject pokemonData = VerifyData.getPokemon(testClient, pokemon.getId()); - LogData.logJsonObject(Level.DEBUG, pokemonData); - assertThat(count, equalTo(1L)); - VerifyData.verifyPokemon(pokemonData, updatedPokemon); - } - - /** - * Verify {@code params(Object... parameters)} parameters setting method. - */ - @Test - void testDmlArrayParams() { - executeTest("testDmlArrayParams", 50, "Shinx"); - } - - /** - * Verify {@code params(List)} parameters setting method. - */ - @Test - void testDmlListParams() { - executeTest("testDmlListParams", 51, "Luxio"); - } - - /** - * Verify {@code params(Map)} parameters setting method. - */ - @Test - void testDmlMapParams() { - executeTest("testDmlMapParams", 52, "Luxray"); - } - - /** - * Verify {@code addParam(Object parameter)} parameters setting method. - */ - @Test - void testDmlOrderParam() { - executeTest("testDmlOrderParam", 53, "Kricketot"); - } - - /** - * Verify {@code addParam(String name, Object parameter)} parameters setting method. - */ - @Test - void testDmlNamedParam() { - executeTest("testDmlNamedParam", 54, "Kricketune"); - } - - /** - * Verify {@code namedParam(Object parameters)} mapped parameters setting method. - */ - @Test - void testDmlMappedNamedParam() { - executeTest("testDmlMappedNamedParam", 55, "Phione"); - } - - /** - * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. - */ - @Test - void testDmlMappedOrderParam() { - executeTest("testDmlMappedOrderParam", 56, "Chatot"); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementGetIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementGetIT.java deleted file mode 100644 index b8d78eee4b3..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementGetIT.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Test DML get statements. - */ -class StatementGetIT { - - private static final System.Logger LOGGER = System.getLogger(StatementGetIT.class.getName()); - - private final TestServiceClient testClient; - - StatementGetIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("StatementGet") - .build(); - } - - private void executeTest(String testName, int fromId, int toId) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonObject data = testClient - .callServiceAndGetData( - testName, - QueryParams.builder() - .add(QueryParams.FROM_ID, String.valueOf(fromId)) - .add(QueryParams.TO_ID, String.valueOf(toId)) - .build()) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - int[] counter = {0}; - Pokemon.POKEMONS.keySet().forEach(id -> { - if (id > fromId && id < toId) { - Pokemon pokemon = Pokemon.POKEMONS.get(id); - VerifyData.verifyPokemon(data, pokemon); - counter[0]++; - } - }); - assertThat(counter[0], equalTo(1)); - } - - /** - * Verify {@code params(Object... parameters)} parameters setting method. - */ - @Test - void testGetArrayParams() { - executeTest("testGetArrayParams", 0, 2); - } - - /** - * Verify {@code params(List)} parameters setting method. - */ - @Test - void testGetListParams() { - executeTest("testGetListParams", 1, 3); - } - - /** - * Verify {@code params(Map)} parameters setting method. - */ - @Test - void testGetMapParams() { - executeTest("testGetMapParams", 2, 4); - } - - /** - * Verify {@code addParam(Object parameter)} parameters setting method. - */ - @Test - void testGetOrderParam() { - executeTest("testGetOrderParam", 3, 5); - - } - - /** - * Verify {@code addParam(String name, Object parameter)} parameters setting method. - */ - @Test - void testGetNamedParam() { - executeTest("testGetNamedParam", 4, 6); - } - - /** - * Verify {@code namedParam(Object parameters)} mapped parameters setting method. - */ - @Test - void testGetMappedNamedParam() { - executeTest("testGetMappedNamedParam", 5, 7); - } - - /** - * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. - */ - @Test - void testGetMappedOrderParam() { - executeTest("testGetMappedOrderParam", 6, 8); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementQueryIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementQueryIT.java deleted file mode 100644 index 229285d11df..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementQueryIT.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.lessThan; - -/** - * Test DML query statements. - */ -class StatementQueryIT { - - private static final System.Logger LOGGER = System.getLogger(StatementQueryIT.class.getName()); - - private final TestServiceClient testClient; - - StatementQueryIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("StatementQuery") - .build(); - } - - private void executeTest(String testName, int fromId, int toId) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), 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.DEBUG, data); - assertThat(data.size(), equalTo(toId - fromId - 1)); - data.getValuesAs(JsonObject.class).forEach(dataPokemon -> { - int id = dataPokemon.getInt("id"); - Pokemon pokemon = Pokemon.POKEMONS.get(id); - assertThat(id, greaterThan(fromId)); - assertThat(id, lessThan(toId)); - VerifyData.verifyPokemon(dataPokemon, pokemon); - }); - } - - /** - * Verify {@code params(Object... parameters)} parameters setting method. - */ - @Test - void testQueryArrayParams() { - executeTest("testQueryArrayParams", 0, 7); - } - - /** - * Verify {@code params(List)} parameters setting method. - */ - @Test - void testQueryListParams() { - executeTest("testQueryListParams", 0, 7); - } - - /** - * Verify {@code params(Map)} parameters setting method. - */ - @Test - void testQueryMapParams() { - executeTest("testQueryMapParams", 0, 7); - } - - /** - * Verify {@code addParam(Object parameter)} parameters setting method. - */ - @Test - void testQueryOrderParam() { - executeTest("testQueryOrderParam", 0, 7); - } - - /** - * Verify {@code addParam(String name, Object parameter)} parameters setting method. - */ - @Test - void testQueryNamedParam() { - executeTest("testQueryNamedParam", 0, 7); - } - - /** - * Verify {@code namedParam(Object parameters)} mapped parameters setting method. - */ - @Test - void testQueryMappedNamedParam() { - executeTest("testQueryMappedNamedParam", 0, 7); - } - - /** - * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. - */ - @Test - void testQueryMappedOrderParam() { - executeTest("testQueryMappedOrderParam", 0, 7); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionDeleteIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionDeleteIT.java deleted file mode 100644 index be2d11b87a6..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionDeleteIT.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.JsonValues; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Test simple delete statements in transaction. - */ -class TransactionDeleteIT { - - private static final System.Logger LOGGER = System.getLogger(TransactionDeleteIT.class.getName()); - - private final TestServiceClient testClient; - - TransactionDeleteIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("TransactionDelete") - .build(); - } - - private void executeTest(String testName, int id) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonValue data = testClient - .callServiceAndGetData( - testName, - QueryParams.single(QueryParams.ID, String.valueOf(id))); - Long count = JsonValues.asLong(data); - LOGGER.log(Level.DEBUG, () -> String.format("Rows deleted: %d", count)); - JsonObject pokemonData = VerifyData.getPokemon(testClient, id); - LogData.logJsonObject(Level.DEBUG, pokemonData); - assertThat(count, equalTo(1L)); - assertThat(pokemonData.isEmpty(), equalTo(true)); - } - - /** - * Verify {@code createNamedDelete(String, String)} API method with ordered parameters. - */ - @Test - void testCreateNamedDeleteStrStrOrderArgs() { - executeTest("testCreateNamedDeleteStrStrOrderArgs", 71); - } - - /** - * Verify {@code createNamedDelete(String)} API method with named parameters. - */ - @Test - void testCreateNamedDeleteStrNamedArgs() { - executeTest("testCreateNamedDeleteStrNamedArgs", 72); - } - - /** - * Verify {@code createNamedDelete(String)} API method with ordered parameters. - */ - @Test - void testCreateNamedDeleteStrOrderArgs() { - executeTest("testCreateNamedDeleteStrOrderArgs", 73); - } - - /** - * Verify {@code createDelete(String)} API method with named parameters. - */ - @Test - void testCreateDeleteNamedArgs() { - executeTest("testCreateDeleteNamedArgs", 74); - } - - /** - * Verify {@code createDelete(String)} API method with ordered parameters. - */ - @Test - void testCreateDeleteOrderArgs() { - executeTest("testCreateDeleteOrderArgs", 75); - } - - /** - * Verify {@code namedDelete(String)} API method with ordered parameters. - */ - @Test - void testNamedDeleteOrderArgs() { - executeTest("testNamedDeleteOrderArgs", 76); - } - - /** - * Verify {@code delete(String)} API method with ordered parameters. - */ - @Test - void testDeleteOrderArgs() { - executeTest("testDeleteOrderArgs", 77); - } - - // DML delete - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with delete with ordered parameters. - */ - @Test - void testCreateNamedDmlWithDeleteStrStrOrderArgs() { - executeTest("testCreateNamedDmlWithDeleteStrStrOrderArgs", 78); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with delete with named parameters. - */ - @Test - void testCreateNamedDmlWithDeleteStrNamedArgs() { - executeTest("testCreateNamedDmlWithDeleteStrNamedArgs", 79); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with delete with ordered parameters. - */ - @Test - void testCreateNamedDmlWithDeleteStrOrderArgs() { - executeTest("testCreateNamedDmlWithDeleteStrOrderArgs", 80); - } - - /** - * Verify {@code createDmlStatement(String)} API method with delete with named parameters. - */ - @Test - void testCreateDmlWithDeleteNamedArgs() { - executeTest("testCreateDmlWithDeleteNamedArgs", 81); - } - - /** - * Verify {@code createDmlStatement(String)} API method with delete with ordered parameters. - */ - @Test - void testCreateDmlWithDeleteOrderArgs() { - executeTest("testCreateDmlWithDeleteOrderArgs", 82); - } - - /** - * Verify {@code namedDml(String)} API method with delete with ordered parameters. - */ - @Test - void testNamedDmlWithDeleteOrderArgs() { - executeTest("testNamedDmlWithDeleteOrderArgs", 83); - } - - /** - * Verify {@code dml(String)} API method with delete with ordered parameters. - */ - @Test - void testDmlWithDeleteOrderArgs() { - executeTest("testDmlWithDeleteOrderArgs", 84); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionGetIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionGetIT.java deleted file mode 100644 index bd989e0adea..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionGetIT.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import org.junit.jupiter.api.Test; - -/** - * Test simple get statements in transaction. - */ -class TransactionGetIT { - - private static final System.Logger LOGGER = System.getLogger(TransactionGetIT.class.getName()); - - private final TestServiceClient testClient; - - TransactionGetIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("TransactionGet") - .build(); - } - - private void executeTest(String testName, Pokemon pokemon) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonObject data = testClient - .callServiceAndGetData( - testName, - QueryParams.single(QueryParams.NAME, pokemon.getName())) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - VerifyData.verifyPokemon(data, pokemon); - } - - /** - * Verify {@code createNamedGet(String, String)} API method with named - * parameters. - */ - @Test - void testCreateNamedGetStrStrNamedArgs() { - executeTest("testCreateNamedGetStrStrNamedArgs", Pokemon.POKEMONS.get(1)); - } - - /** - * Verify {@code createNamedGet(String)} API method with named parameters. - */ - @Test - void testCreateNamedGetStrNamedArgs() { - executeTest("testCreateNamedGetStrNamedArgs", Pokemon.POKEMONS.get(2)); - } - - /** - * Verify {@code createNamedGet(String)} API method with ordered parameters. - */ - @Test - void testCreateNamedGetStrOrderArgs() { - executeTest("testCreateNamedGetStrOrderArgs", Pokemon.POKEMONS.get(3)); - } - - /** - * Verify {@code createGet(String)} API method with named parameters. - */ - @Test - void testCreateGetNamedArgs() { - executeTest("testCreateGetNamedArgs", Pokemon.POKEMONS.get(4)); - } - - /** - * Verify {@code createGet(String)} API method with ordered parameters. - */ - @Test - void testCreateGetOrderArgs() { - executeTest("testCreateGetOrderArgs", Pokemon.POKEMONS.get(5)); - } - - /** - * Verify {@code namedGet(String)} API method with ordered parameters passed - * directly to the {@code query} method. - */ - @Test - void testNamedGetStrOrderArgs() { - executeTest("testNamedGetStrOrderArgs", Pokemon.POKEMONS.get(6)); - } - - /** - * Verify {@code get(String)} API method with ordered parameters passed - * directly to the {@code query} method. - */ - @Test - void testGetStrOrderArgs() { - executeTest("testGetStrOrderArgs", Pokemon.POKEMONS.get(7)); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionInsertIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionInsertIT.java deleted file mode 100644 index 2da18e1bfd1..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionInsertIT.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import org.junit.jupiter.api.Test; - -/** - * Test simple insert statements in transaction. - */ -class TransactionInsertIT { - - private static final System.Logger LOGGER = System.getLogger(TransactionInsertIT.class.getName()); - - private final TestServiceClient testClient; - - TransactionInsertIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("TransactionInsert") - .build(); - } - - private void executeTest(String testName, int id) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonObject data = testClient - .callServiceAndGetData( - testName, - QueryParams.single(QueryParams.ID, String.valueOf(id))) - .asJsonObject(); - LogData.logJsonObject(Level.DEBUG, data); - JsonObject pokemonData = VerifyData.getPokemon(testClient, id); - LogData.logJsonObject(Level.DEBUG, pokemonData); - VerifyData.verifyPokemon(pokemonData, data); - } - - /** - * Verify {@code createNamedInsert(String, String)} API method with named parameters. - */ - @Test - void testCreateNamedInsertStrStrNamedArgs() { - executeTest("testCreateNamedInsertStrStrNamedArgs", 85); - } - - /** - * Verify {@code createNamedInsert(String)} API method with named parameters. - */ - @Test - void testCreateNamedInsertStrNamedArgs() { - executeTest("testCreateNamedInsertStrNamedArgs", 86); - } - - /** - * Verify {@code createNamedInsert(String)} API method with ordered parameters. - */ - @Test - void testCreateNamedInsertStrOrderArgs() { - executeTest("testCreateNamedInsertStrOrderArgs", 87); - } - - /** - * Verify {@code createInsert(String)} API method with named parameters. - */ - @Test - void testCreateInsertNamedArgs() { - executeTest("testCreateInsertNamedArgs", 88); - } - - /** - * Verify {@code createInsert(String)} API method with ordered parameters. - */ - @Test - void testCreateInsertOrderArgs() { - executeTest("testCreateInsertOrderArgs", 89); - } - - /** - * Verify {@code namedInsert(String)} API method with ordered parameters passed directly to the {@code insert} method. - */ - @Test - void testNamedInsertOrderArgs() { - executeTest("testNamedInsertOrderArgs", 90); - } - - /** - * Verify {@code insert(String)} API method with ordered parameters passed directly to the {@code insert} method. - */ - @Test - void testInsertOrderArgs() { - executeTest("testInsertOrderArgs", 91); - } - - // DML update - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with insert with named parameters. - */ - @Test - void testCreateNamedDmlWithInsertStrStrNamedArgs() { - executeTest("testCreateNamedDmlWithInsertStrStrNamedArgs", 92); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with insert with named parameters. - */ - @Test - void testCreateNamedDmlWithInsertStrNamedArgs() { - executeTest("testCreateNamedDmlWithInsertStrNamedArgs", 93); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with insert with ordered parameters. - */ - @Test - void testCreateNamedDmlWithInsertStrOrderArgs() { - executeTest("testCreateNamedDmlWithInsertStrOrderArgs", 94); - } - - /** - * Verify {@code createDmlStatement(String)} API method with insert with named parameters. - */ - @Test - void testCreateDmlWithInsertNamedArgs() { - executeTest("testCreateDmlWithInsertNamedArgs", 95); - } - - /** - * Verify {@code createDmlStatement(String)} API method with insert with ordered parameters. - */ - @Test - void testCreateDmlWithInsertOrderArgs() { - executeTest("testCreateDmlWithInsertOrderArgs", 96); - } - - /** - * Verify {@code namedDml(String)} API method with insert with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - void testNamedDmlWithInsertOrderArgs() { - executeTest("testNamedDmlWithInsertOrderArgs", 97); - } - - /** - * Verify {@code dml(String)} API method with insert with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - void testDmlWithInsertOrderArgs() { - executeTest("testDmlWithInsertOrderArgs", 98); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionQueriesIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionQueriesIT.java deleted file mode 100644 index 0e174779965..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionQueriesIT.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonArray; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; - -/** - * Test simple query statements in transaction. - */ -class TransactionQueriesIT { - - /** - * Local logger instance. - */ - static final System.Logger LOGGER = System.getLogger(TransactionQueriesIT.class.getName()); - - private final TestServiceClient testClient; - - TransactionQueriesIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("TransactionQueries") - .build(); - } - - private void executeTest(String testName, Pokemon pokemon) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName)); - JsonArray data = testClient - .callServiceAndGetData( - testName, - QueryParams.single(QueryParams.NAME, pokemon.getName())) - .asJsonArray(); - LogData.logJsonArray(Level.DEBUG, data); - assertThat(data.size(), Matchers.equalTo(1)); - VerifyData.verifyPokemon(data.getJsonObject(0), pokemon); - } - - /** - * Verify {@code createNamedQuery(String, String)} API method with ordered parameters. - */ - @Test - void testCreateNamedQueryStrStrOrderArgs() { - executeTest("testCreateNamedQueryStrStrOrderArgs", Pokemon.POKEMONS.get(1)); - } - - /** - * Verify {@code createNamedQuery(String)} API method with named parameters. - */ - @Test - void testCreateNamedQueryStrNamedArgs() { - executeTest("testCreateNamedQueryStrNamedArgs", Pokemon.POKEMONS.get(2)); - } - - /** - * Verify {@code createNamedQuery(String)} API method with ordered parameters. - */ - @Test - void testCreateNamedQueryStrOrderArgs() { - executeTest("testCreateNamedQueryStrOrderArgs", Pokemon.POKEMONS.get(3)); - } - - /** - * Verify {@code createQuery(String)} API method with named parameters. - */ - @Test - void testCreateQueryNamedArgs() { - executeTest("testCreateQueryNamedArgs", Pokemon.POKEMONS.get(4)); - } - - /** - * Verify {@code createQuery(String)} API method with ordered parameters. - */ - @Test - void testCreateQueryOrderArgs() { - executeTest("testCreateQueryOrderArgs", Pokemon.POKEMONS.get(5)); - } - - /** - * Verify {@code namedQuery(String)} API method with ordered parameters passed directly to the {@code namedQuery} method. - */ - @Test - void testNamedQueryOrderArgs() { - executeTest("testNamedQueryOrderArgs", Pokemon.POKEMONS.get(6)); - } - - /** - * Verify {@code query(String)} API method with ordered parameters passed directly to the {@code query} method. - */ - @Test - void testQueryOrderArgs() { - executeTest("testQueryOrderArgs", Pokemon.POKEMONS.get(7)); - } - -} diff --git a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionUpdateIT.java b/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionUpdateIT.java deleted file mode 100644 index 17f30ed15a6..00000000000 --- a/tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionUpdateIT.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.app.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.tests.integration.dbclient.app.LogData; -import io.helidon.tests.integration.dbclient.app.VerifyData; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.app.tools.QueryParams; -import io.helidon.tests.integration.harness.JsonValues; -import io.helidon.tests.integration.harness.TestClient; -import io.helidon.tests.integration.harness.TestServiceClient; - -import jakarta.json.JsonObject; -import jakarta.json.JsonValue; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Test simple update statements in transaction. - */ -class TransactionUpdateIT { - - private static final System.Logger LOGGER = System.getLogger(TransactionUpdateIT.class.getName()); - - private final TestServiceClient testClient; - - TransactionUpdateIT(int serverPort) { - this.testClient = TestClient.builder() - .port(serverPort) - .service("TransactionUpdate") - .build(); - } - - private void executeTest(String testName, int id, String newName) { - LOGGER.log(Level.DEBUG, () -> String.format("Running %s.%s on client", getClass().getSimpleName(), testName));; - 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 = JsonValues.asLong(data); - JsonObject pokemonData = VerifyData.getPokemon(testClient, pokemon.getId()); - LogData.logJsonObject(Level.DEBUG, pokemonData); - assertThat(count, equalTo(1L)); - VerifyData.verifyPokemon(pokemonData, updatedPokemon); - } - - /** - * Verify {@code createNamedUpdate(String, String)} API method with ordered parameters. - */ - @Test - void testCreateNamedUpdateStrStrNamedArgs() { - executeTest("testCreateNamedUpdateStrStrNamedArgs", 57, "Ursaring"); - } - - /** - * Verify {@code createNamedUpdate(String)} API method with named parameters. - */ - @Test - void testCreateNamedUpdateStrNamedArgs() { - executeTest("testCreateNamedUpdateStrNamedArgs", 58, "Teddiursa"); - } - - /** - * Verify {@code createNamedUpdate(String, String)} API method with ordered parameters. - */ - @Test - void testCreateNamedUpdateStrOrderArgs() { - executeTest("testCreateNamedUpdateStrOrderArgs", 59, "Magcargo"); - } - - /** - * Verify {@code createUpdate(String)} API method with named parameters. - */ - @Test - void testCreateUpdateNamedArgs() { - executeTest("testCreateUpdateNamedArgs", 60, "Slugma"); - } - - - /** - * Verify {@code createUpdate(String)} API method with named parameters. - */ - @Test - void testCreateUpdateOrderArgs() { - executeTest("testCreateUpdateOrderArgs", 61, "Lombre"); - } - - /** - * Verify {@code namedUpdate(String, String)} API method with ordered parameters. - */ - @Test - void testNamedUpdateNamedArgs() { - executeTest("testNamedUpdateNamedArgs", 62, "Ludicolo"); - } - - /** - * Verify {@code update(String)} API method with named parameters. - */ - @Test - void testUpdateOrderArgs() { - executeTest("testUpdateOrderArgs", 63, "Lotad"); - } - - // DML update - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with update with named parameters. - */ - @Test - void testCreateNamedDmlWithUpdateStrStrNamedArgs() { - executeTest("testCreateNamedDmlWithUpdateStrStrNamedArgs", 64, "Xatu"); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with update with named parameters. - */ - @Test - void testCreateNamedDmlWithUpdateStrNamedArgs() { - executeTest("testCreateNamedDmlWithUpdateStrNamedArgs", 65, "Natu"); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with update with ordered parameters. - */ - @Test - void testCreateNamedDmlWithUpdateStrOrderArgs() { - executeTest("testCreateNamedDmlWithUpdateStrOrderArgs", 66, "Granbull"); - } - - /** - * Verify {@code createDmlStatement(String)} API method with update with named parameters. - */ - @Test - void testCreateDmlWithUpdateNamedArgs() { - executeTest("testCreateDmlWithUpdateNamedArgs", 67, "Snubbull"); - } - - /** - * Verify {@code createDmlStatement(String)} API method with update with ordered parameters. - */ - @Test - void testCreateDmlWithUpdateOrderArgs() { - executeTest("testCreateDmlWithUpdateOrderArgs", 68, "Raikou"); - } - - /** - * Verify {@code namedDml(String)} API method with update with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - void testNamedDmlWithUpdateOrderArgs() { - executeTest("testNamedDmlWithUpdateOrderArgs", 69, "Suicune"); - } - - /** - * Verify {@code dml(String)} API method with update with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - void testDmlWithUpdateOrderArgs() { - executeTest("testDmlWithUpdateOrderArgs", 70, "Entei"); - } -} diff --git a/tests/integration/dbclient/app/src/test/resources/logging.properties b/tests/integration/dbclient/app/src/test/resources/logging.properties deleted file mode 100644 index e1b27ef2055..00000000000 --- a/tests/integration/dbclient/app/src/test/resources/logging.properties +++ /dev/null @@ -1,25 +0,0 @@ -# -# Copyright (c) 2020, 2023 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -handlers=io.helidon.logging.jul.HelidonConsoleHandler -# HelidonConsoleHandler uses a SimpleFormatter subclass that replaces "!thread!" with the current thread -java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$s %3$s !thread!: %5$s%6$s%n -# Global logging level. Can be overridden by specific loggers -.level=WARNING -io.helidon.level=INFO -io.helidon.config.level=INFO -io.helidon.webserver.http.level=WARNING -io.helidon.tests.integration.dbclient.app.level=INFO diff --git a/tests/integration/dbclient/common/pom.xml b/tests/integration/dbclient/common/pom.xml index a09d1f0565e..f59a76144e3 100644 --- a/tests/integration/dbclient/common/pom.xml +++ b/tests/integration/dbclient/common/pom.xml @@ -27,14 +27,9 @@ ../pom.xml helidon-tests-integration-dbclient-common - Helidon Tests Integration Database Client Common + Helidon Tests Integration DbClient Common - - io.helidon.tests.integration - helidon-tests-integration-harness - ${project.version} - io.helidon.config helidon-config @@ -59,10 +54,6 @@ org.eclipse.parsson parsson - - org.junit.jupiter - junit-jupiter-api - org.hamcrest hamcrest-all @@ -71,6 +62,10 @@ io.helidon.webserver helidon-webserver + + io.helidon.webserver + helidon-webserver-context + io.helidon.webserver.observe helidon-webserver-observe-metrics @@ -80,9 +75,8 @@ helidon-webserver-observe-health - io.micrometer - micrometer-core + io.helidon.webclient + helidon-webclient-http1 - diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/AbstractTestImpl.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/AbstractTestImpl.java new file mode 100644 index 00000000000..62d10013b36 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/AbstractTestImpl.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbRow; +import io.helidon.tests.integration.dbclient.common.model.Pokemon; +import io.helidon.tests.integration.dbclient.common.model.Pokemons; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; + +/** + * Base test implementation. + */ +public abstract class AbstractTestImpl { + + protected final DbClient db; + protected final Config config; + protected final Map statements; + + protected AbstractTestImpl(DbClient db, Config config) { + this.db = db; + this.config = config; + this.statements = config.get("db.statements").detach().asMap().get(); + } + + static void verifyPokemon(List rows, Pokemon expected) { + assertThat(rows, notNullValue()); + assertThat(rows, hasSize(1)); + DbRow row = rows.getFirst(); + int id = row.column(1).get(Integer.class); + String name = row.column(2).get(String.class); + assertThat(id, equalTo(expected.id())); + assertThat(name, expected.name().equals(name)); + } + + static void verifyPokemon(Stream rows, Pokemon pokemon) { + assertThat(rows, notNullValue()); + verifyPokemon(rows.toList(), pokemon); + } + + static void verifyPokemon(DbRow row, Pokemon expected) { + assertThat(row, is(not(nullValue()))); + int id = row.column(1).get(Integer.class); + String name = row.column(2).get(String.class); + assertThat(id, equalTo(expected.id())); + assertThat(name, expected.name().equals(name)); + } + + void verifyPokemonsIdRange(DbRow row, int idMin, int idMax) { + Map valid = range(idMin, idMax); + assertThat(row, is(not(nullValue()))); + int id = row.column(1).get(Integer.class); + String name = row.column(2).get(String.class); + assertThat(valid.containsKey(id), equalTo(true)); + assertThat(name, equalTo(valid.get(id).name())); + } + + static void verifyPokemon(Pokemon actual, Pokemon expected) { + assertThat(actual.id(), equalTo(expected.id())); + assertThat(actual.name(), equalTo(expected.name())); + } + + void verifyInsertPokemon(long result, Pokemon data) { + assertThat(result, equalTo(1L)); + DbRow row = db.execute() + .namedGet("select-pokemon-by-id", data.id()) + .orElse(null); + + assertThat(row, is(not(nullValue()))); + int id = row.column("id").get(Integer.class); + String name = row.column("name").get(String.class); + assertThat(id, equalTo(data.id())); + assertThat(name, data.name().equals(name)); + } + + void verifyUpdatePokemon(long result, Pokemon data) { + assertThat(result, equalTo(1L)); + DbRow row = db.execute() + .namedGet("select-pokemon-by-id", data.id()) + .orElse(null); + verifyPokemon(row, data); + } + + void verifyDeletePokemon(long result, Pokemon expected) { + assertThat(result, equalTo(1L)); + DbRow row = db.execute() + .namedGet("select-pokemon-by-id", expected.id()) + .orElse(null); + assertThat(row, is(nullValue())); + } + + Map range(int idMin, int idMax) { + return Pokemons.ALL.stream() + .filter(p -> p.id() > idMin && p.id() < idMax) + .collect(Collectors.toMap(Pokemon::id, Function.identity())); + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/DBHelper.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/DBHelper.java new file mode 100644 index 00000000000..c031ed61727 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/DBHelper.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbClientException; +import io.helidon.dbclient.DbExecute; +import io.helidon.tests.integration.dbclient.common.model.Pokemons; +import io.helidon.tests.integration.dbclient.common.model.Types; + +/** + * Database helper. + */ +public class DBHelper { + + private DBHelper() { + // cannot be instantiated + } + + /** + * Create the schema. + * + * @param db db client + */ + public static void createSchema(DbClient db) { + try { + DbExecute exec = db.execute(); + exec.namedDml("create-types"); + exec.namedDml("create-pokemons"); + exec.namedDml("create-poketypes"); + } catch (DbClientException ex) { + ex.printStackTrace(System.err); + } + } + + /** + * Insert the default data. + * + * @param db db client + */ + public static void insertDataSet(DbClient db) { + try { + DbExecute exec = db.execute(); + Types.ALL.forEach(t -> exec.namedInsert("insert-type", t.id(), t.name())); + Pokemons.ALL.forEach(p -> exec.namedInsert("insert-pokemon", p.id(), p.name())); + Pokemons.ALL.forEach(p -> p.types().forEach(t -> exec.namedInsert("insert-poketype", p.id(), t.id()))); + } catch (DbClientException ex) { + ex.printStackTrace(System.err); + } + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/DbClientITMain.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/DbClientITMain.java new file mode 100644 index 00000000000..11b8081049e --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/DbClientITMain.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.health.DbClientHealthCheck; +import io.helidon.logging.common.LogConfig; +import io.helidon.webserver.WebServer; +import io.helidon.webserver.WebServerConfig; +import io.helidon.webserver.observe.ObserveFeature; +import io.helidon.webserver.observe.health.HealthObserver; + +import static io.helidon.config.ConfigSources.classpath; + +/** + * The application main class. + */ +public class DbClientITMain { + + /** + * Cannot be instantiated. + */ + private DbClientITMain() { + } + + /** + * Application main entry point. + * + * @param args command line arguments. + */ + public static void main(String[] args) { + LogConfig.configureRuntime(); + Config config = Config.create( + classpath("db.yaml"), + classpath("db-common.yaml")); + Config.global(config); + + DbClient db = DbClient.create(config.get("db")); + if (config.get("db.create-schema").asBoolean().orElse(false)) { + DBHelper.createSchema(db); + } + if (config.get("db.insert-dataset").asBoolean().orElse(false)) { + DBHelper.insertDataSet(db); + } + + WebServer server = WebServer.builder() + .config(config.get("server")) + .update(r -> setup(db, config, r)) + .build() + .start(); + server.context().register(server); + + System.out.println("WEB server is up! http://localhost:" + server.port()); + } + + /** + * Set up the server. + * + * @param dbClient db client + * @param config config + * @param builder builder + */ + public static void setup(DbClient dbClient, Config config, WebServerConfig.Builder builder) { + builder.addFeature(observeFeature(dbClient, config, "healthNoDetails", "noDetails", false)); + builder.addFeature(observeFeature(dbClient, config, "healthDetails", "details", true)); + builder.routing(r -> r.register("/test", new TestService(dbClient, config))); + } + + private static ObserveFeature observeFeature(DbClient dbClient, + Config config, + String name, + String endpoint, + boolean details) { + return ObserveFeature.builder() + .observersDiscoverServices(false) + .endpoint(endpoint) + .name(name) + .addObserver(HealthObserver.builder() + .addCheck(DbClientHealthCheck.builder(dbClient) + .config(config.get("db.health-check")) + .name(name) + .build()) + .details(details) + .build()) + .build(); + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/DbMapperProviderImpl.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/DbMapperProviderImpl.java new file mode 100644 index 00000000000..85b83ad06df --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/DbMapperProviderImpl.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2019, 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import io.helidon.dbclient.DbMapper; +import io.helidon.dbclient.DbRow; +import io.helidon.dbclient.spi.DbMapperProvider; +import io.helidon.tests.integration.dbclient.common.model.Pokemon; +import io.helidon.tests.integration.dbclient.common.model.Range; + +/** + * Mapper provider used in integration tests. + */ +public final class DbMapperProviderImpl implements DbMapperProvider { + + private static final PokemonMapper POKEMON_MAPPER = new PokemonMapper(); + private static final RangeMapper RANGE_MAPPER = new RangeMapper(); + + @Override + @SuppressWarnings({"unchecked", "IfCanBeSwitch"}) + public Optional> mapper(Class type) { + if (type.equals(Range.class)) { + return Optional.of((DbMapper) RANGE_MAPPER); + } + if (type.equals(Pokemon.class)) { + return Optional.of((DbMapper) POKEMON_MAPPER); + } + return Optional.empty(); + } + + private static final class RangeMapper implements DbMapper { + + @Override + public Range read(DbRow row) { + throw new UnsupportedOperationException("Read operation is not implemented."); + } + + @Override + public Map toNamedParameters(Range value) { + return Map.of( + "idmin", value.idMin(), + "idmax", value.idMax()); + } + + @Override + public List toIndexedParameters(Range value) { + return List.of(value.idMin(), value.idMax()); + } + } + + private static final class PokemonMapper implements DbMapper { + + @Override + public Pokemon read(DbRow row) { + return new Pokemon(row.column("id").get(Integer.class), row.column("name").get(String.class)); + } + + @Override + public Map toNamedParameters(Pokemon pokemon) { + return Map.of( + "id", pokemon.id(), + "name", pokemon.name()); + } + + @Override + public List toIndexedParameters(Pokemon pokemon) { + return List.of(pokemon.name(), pokemon.id()); + } + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/LocalTextContext.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/LocalTextContext.java new file mode 100644 index 00000000000..4405ed23d8e --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/LocalTextContext.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import java.util.Map; +import java.util.Optional; +import java.util.function.BiFunction; +import java.util.function.Supplier; + +import io.helidon.config.Config; +import io.helidon.config.ConfigSources; +import io.helidon.config.spi.ConfigNode; +import io.helidon.config.spi.ConfigSource; +import io.helidon.config.spi.LazyConfigSource; +import io.helidon.dbclient.DbClient; + +/** + * Tuple for local tests. + * + * @param delegate type + */ +public record LocalTextContext(DbClient db, Config config, Supplier delegateSupplier) { + + /** + * Create a new context. + * + * @param factory delegate factory + * @param overrides config overrides + * @param createSchema {@code true} to create the schema + * @param delegate type + * @return context + */ + public static LocalTextContext create(BiFunction factory, + Map> overrides, + boolean createSchema) { + Config config = Config.create( + new LazyMapConfigSourceImpl(overrides), + ConfigSources.classpath("db.yaml"), + ConfigSources.classpath("db-common.yaml")); + Config.global(config); + DbClient db = DbClient.create(config.get("db")); + T delegate = factory.apply(db, config); + if (createSchema) { + DBHelper.createSchema(db); + } + DBHelper.insertDataSet(db); + return new LocalTextContext<>(db, config, () -> delegate); + } + + /** + * Get the delegate. + * + * @return delegate + */ + public T delegate() { + return delegateSupplier.get(); + } + + private record LazyMapConfigSourceImpl(Map> map) implements ConfigSource, LazyConfigSource { + + @Override + public Optional node(String key) { + return Optional.ofNullable(map.get(key)) + .flatMap(v -> Optional.ofNullable(v.get())) + .map(Object::toString) + .map(ConfigNode.ValueNode::create); + } + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/MapperProviderImpl.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/MapperProviderImpl.java new file mode 100644 index 00000000000..f2e58de9873 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/MapperProviderImpl.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import io.helidon.common.mapper.Mapper; +import io.helidon.common.mapper.spi.MapperProvider; + +/** + * Mapper provider. + */ +public class MapperProviderImpl implements MapperProvider { + + @Override + public ProviderResponse mapper(Class sourceClass, Class targetClass, String qualifier) { + if (Number.class.isAssignableFrom(sourceClass)) { + Mapper mapper = numberMapper(targetClass); + if (mapper != null) { + return new ProviderResponse(Support.SUPPORTED, mapper); + } + } + return ProviderResponse.unsupported(); + } + + private Mapper numberMapper(Class targetClass) { + return switch (targetClass.getName()) { + case "byte", "java.lang.Byte" -> Number::byteValue; + case "int", "java.lang.Integer" -> Number::intValue; + case "long", "java.lang.Long" -> Number::longValue; + case "float", "java.lang.Float" -> Number::floatValue; + case "double", "java.lang.Double" -> Number::doubleValue; + default -> null; + }; + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/MiscTest.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/MiscTest.java new file mode 100644 index 00000000000..564ec06fdc5 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/MiscTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + + +/** + * Miscellaneous test. + */ +public interface MiscTest { + + /** + * Source data verification. + */ + void testFlowControl(); + + /** + * Check that statement interceptor was called before statement execution. + */ + void testStatementInterceptor(); + + /** + * Verify insertion of using indexed mapping. + */ + void testInsertWithOrderMapping(); + + /** + * Verify insertion of using named mapping. + */ + void testInsertWithNamedMapping(); + + /** + * Verify update of using indexed mapping. + */ + void testUpdateWithOrderMapping(); + + /** + * Verify update of using named mapping. + */ + void testUpdateWithNamedMapping(); + + /** + * Verify delete of using indexed mapping. + */ + void testDeleteWithOrderMapping(); + + /** + * Verify delete of using named mapping. + */ + void testDeleteWithNamedMapping(); + + /** + * Verify query of as a result using mapping. + */ + void testQueryWithMapping(); + + /** + * Verify get of as a result using mapping. + */ + void testGetWithMapping(); +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/MiscTestImpl.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/MiscTestImpl.java new file mode 100644 index 00000000000..83b73e0bd68 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/MiscTestImpl.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import java.util.List; +import java.util.stream.Stream; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbClientService; +import io.helidon.dbclient.DbClientServiceContext; +import io.helidon.dbclient.DbRow; +import io.helidon.tests.integration.dbclient.common.model.Pokemon; +import io.helidon.tests.integration.dbclient.common.model.Pokemons; +import io.helidon.tests.integration.dbclient.common.model.Type; +import io.helidon.tests.integration.dbclient.common.model.Types; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; + +/** + * Actual implementation of {@link MiscTest}. + */ +public final class MiscTestImpl extends AbstractTestImpl implements MiscTest { + + /** + * Create a new instance. + * + * @param db db client + * @param config config + */ + public MiscTestImpl(DbClient db, Config config) { + super(db, config); + } + + @Override + public void testFlowControl() { + List actual = db.execute().namedQuery("select-types") + .map(row -> new Type(row.column(1).get(Integer.class), row.column(2).get(String.class))) + .toList(); + assertThat(actual.size(), equalTo(18)); + assertThat(actual, is(Types.ALL)); + } + + @Override + public void testStatementInterceptor() { + TestDbClientService interceptor = new TestDbClientService(); + try (DbClient db = DbClient.builder(config.get("db")).addService(interceptor).build()) { + db.execute() + .createNamedQuery("select-pokemon-named-arg") + .addParam("name", Pokemons.MEOWTH.name()) + .execute(); + assertThat(interceptor.called(), equalTo(true)); + } + } + + @Override + public void testInsertWithOrderMapping() { + Pokemon pokemon = new Pokemon(600, "Articuno", Types.FLYING, Types.ICE); + long result = db.execute() + .createNamedInsert("insert-pokemon-order-arg-rev") + .indexedParam(pokemon) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testInsertWithNamedMapping() { + Pokemon pokemon = new Pokemon(601, "Zapdos", Types.FLYING, Types.ELECTRIC); + long result = db.execute() + .createNamedInsert("insert-pokemon-named-arg") + .namedParam(pokemon) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testUpdateWithOrderMapping() { + Pokemon pokemon = new Pokemon(100, "UpdatedMasquerain", Types.FLYING, Types.ICE); + long result = db.execute() + .createNamedUpdate("update-pokemon-order-arg") + .indexedParam(pokemon) + .execute(); + verifyUpdatePokemon(result, pokemon); + } + + @Override + public void testUpdateWithNamedMapping() { + Pokemon pokemon = new Pokemon(99, "UpdatedMoltres", Types.FLYING, Types.ELECTRIC); + long result = db.execute() + .createNamedUpdate("update-pokemon-named-arg") + .namedParam(pokemon) + .execute(); + verifyUpdatePokemon(result, pokemon); + } + + @Override + public void testDeleteWithOrderMapping() { + Pokemon pokemon = Pokemons.MAKUHITA; + long result = db.execute() + .createNamedDelete("delete-pokemon-full-order-arg") + .indexedParam(pokemon) + .execute(); + + assertThat(result, equalTo(1L)); + DbRow row = db.execute() + .namedGet("select-pokemon-by-id", pokemon.id()) + .orElse(null); + assertThat(row, is(nullValue())); + } + + @Override + public void testDeleteWithNamedMapping() { + Pokemon pokemon = Pokemons.HARIYAMA; + + long result = db.execute() + .createNamedDelete("delete-pokemon-full-named-arg") + .namedParam(pokemon) + .execute(); + + assertThat(result, equalTo(1L)); + DbRow row = db.execute() + .namedGet("select-pokemon-by-id", pokemon.id()) + .orElse(null); + assertThat(row, is(nullValue())); + } + + @Override + public void testQueryWithMapping() { + Pokemon orig = Pokemons.RAICHU; + Stream rows = db.execute() + .createNamedQuery("select-pokemon-named-arg") + .addParam("name", orig.name()) + .execute(); + + Pokemon actual = rows.map(it -> it.as(Pokemon.class)).findFirst().orElseThrow(); + verifyPokemon(actual, orig); + } + + @Override + public void testGetWithMapping() { + Pokemon orig = Pokemons.MACHOP; + DbRow row = db.execute() + .createNamedGet("select-pokemon-named-arg") + .addParam("name", orig.name()) + .execute() + .orElse(null); + + assertThat(row, is(not(nullValue()))); + Pokemon actual = row.as(Pokemon.class); + verifyPokemon(actual, orig); + } + + private static final class TestDbClientService implements DbClientService { + + private boolean called; + + private TestDbClientService() { + this.called = false; + } + + @Override + public DbClientServiceContext statement(DbClientServiceContext context) { + this.called = true; + return context; + } + + private boolean called() { + return called; + } + + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/ObservabilityTest.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/ObservabilityTest.java new file mode 100644 index 00000000000..b57cced29ee --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/ObservabilityTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +/** + * Observability test. + */ +public interface ObservabilityTest { + + /** + * Read and check Database Client health status from Helidon Web Server. + */ + void testHttpHealthNoDetails(); + + /** + * Read and check Database Client health status from Helidon Web Server. + */ + void testHttpHealthDetails(); + + /** + * Read and check Database Client metrics from Helidon Web Server. + */ + void testHttpMetrics(); + + /** + * Verify health check implementation with default settings. + */ + void testHealthCheck(); + + /** + * Verify health check implementation with builder and custom name. + */ + void testHealthCheckWithName(); + + /** + * Verify health check implementation using custom DML named statement. + */ + void testHealthCheckWithCustomNamedDML(); + + /** + * Verify health check implementation using custom DML statement. + */ + void testHealthCheckWithCustomDML(); + + /** + * Verify health check implementation using custom query named statement. + */ + void testHealthCheckWithCustomNamedQuery(); + + /** + * Verify health check implementation using custom query statement. + */ + void testHealthCheckWithCustomQuery(); + +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/ObservabilityTestImpl.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/ObservabilityTestImpl.java new file mode 100644 index 00000000000..ee8f4990caf --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/ObservabilityTestImpl.java @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import java.util.List; +import java.util.function.Supplier; + +import io.helidon.common.LazyValue; +import io.helidon.common.media.type.MediaTypes; +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbRow; +import io.helidon.dbclient.health.DbClientHealthCheck; +import io.helidon.health.HealthCheck; +import io.helidon.health.HealthCheckResponse; +import io.helidon.http.Status; +import io.helidon.tests.integration.dbclient.common.model.Pokemon; +import io.helidon.tests.integration.dbclient.common.model.Types; +import io.helidon.webclient.api.ClientResponseTyped; +import io.helidon.webclient.http1.Http1Client; +import io.helidon.webclient.http1.Http1ClientRequest; + +import jakarta.json.JsonArray; +import jakarta.json.JsonObject; +import jakarta.json.JsonValue; +import org.hamcrest.CoreMatchers; + +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +/** + * Actual implementation of {@link ObservabilityTest}. + */ +public final class ObservabilityTestImpl extends AbstractTestImpl implements ObservabilityTest { + + private final LazyValue client; + + /** + * Create a new instance. + * + * @param db db client + * @param config config + * @param clientSupplier client supplier + */ + public ObservabilityTestImpl(DbClient db, Config config, Supplier clientSupplier) { + super(db, config); + client = LazyValue.create(clientSupplier); + } + + @Override + public void testHttpHealthNoDetails() { + // Call select-pokemons to warm up server + List ignored = db.execute().namedQuery("select-pokemons").toList(); + + ClientResponseTyped response = get("/noDetails/health").request(String.class); + assertThat(response.status(), equalTo(Status.NO_CONTENT_204)); + } + + @Override + public void testHttpHealthDetails() { + // Call select-pokemons to warm up server + List ignored = db.execute().namedQuery("select-pokemons").toList(); + + // Read and process health check response + ClientResponseTyped response = get("/details/health").request(JsonObject.class); + assertThat(response.status(), equalTo(Status.OK_200)); + + JsonArray checks = response.entity().asJsonObject().getJsonArray("checks"); + assertThat(checks.size(), greaterThan(0)); + for (JsonValue check : checks) { + String status = check.asJsonObject().getString("status"); + assertThat(status, equalTo("UP")); + } + } + + @Override + public void testHttpMetrics() { + // Read and process metrics response + JsonObject application = get("/observe/metrics/application") + .accept(MediaTypes.APPLICATION_JSON) + .requestEntity(JsonObject.class); + + int origSelectCount = application.getInt("db.counter.select-pokemons", 0); + int origInsertCount = application.getInt("db.counter.insert-pokemon", 0); + JsonObject insertTimer = application.getJsonObject("db.timer.insert-pokemon"); + int origInsertTimerCount = insertTimer == null ? 0 : insertTimer.getInt("count", 0); + + // Call select-pokemons + List ignored = db.execute().namedQuery("select-pokemons").toList(); + + // Call insert-pokemon + Pokemon pokemon = new Pokemon(401, "Lickitung", Types.NORMAL); + db.execute().namedInsert("insert-pokemon", pokemon.id(), pokemon.name()); + + // Read and process metrics response + application = get("/observe/metrics/application") + .accept(MediaTypes.APPLICATION_JSON) + .requestEntity(JsonObject.class); + + int actualSelectCount = application.getInt("db.counter.select-pokemons", 0); + assertThat(actualSelectCount, is(origSelectCount + 1)); + + int actualInsertCount = application.getInt("db.counter.insert-pokemon", 0); + assertThat(actualInsertCount, equalTo(origInsertCount + 1)); + assertThat(application.containsKey("db.timer.insert-pokemon"), equalTo(true)); + + insertTimer = application.getJsonObject("db.timer.insert-pokemon"); + assertThat(insertTimer, is(not(nullValue()))); + assertThat(insertTimer.containsKey("count"), equalTo(true)); + assertThat(insertTimer.containsKey("mean"), equalTo(true)); + assertThat(insertTimer.containsKey("max"), equalTo(true)); + + int actualInsertTimerCount = insertTimer.getInt("count"); + assertThat(actualInsertTimerCount, equalTo(origInsertTimerCount + 1)); + } + + @Override + public void testHealthCheck() { + HealthCheck check = DbClientHealthCheck.create(db, config.get("db.health-check")); + HealthCheckResponse response = check.call(); + HealthCheckResponse.Status state = response.status(); + assertThat("Health check failed, response: " + response.details(), state, equalTo(HealthCheckResponse.Status.UP)); + } + + @Override + public void testHealthCheckWithName() { + String hcName = "TestHC"; + HealthCheck check = DbClientHealthCheck.builder(db).config(config.get("db.health-check")).name(hcName).build(); + HealthCheckResponse response = check.call(); + String name = check.name(); + HealthCheckResponse.Status state = response.status(); + assertThat(name, equalTo(hcName)); + assertThat(state, equalTo(HealthCheckResponse.Status.UP)); + } + + @Override + public void testHealthCheckWithCustomNamedDML() { + HealthCheck check = DbClientHealthCheck.builder(db).dml().statementName("ping-dml").build(); + HealthCheckResponse response = check.call(); + HealthCheckResponse.Status state = response.status(); + assertThat("Health check failed, response: " + response.details(), state, equalTo(HealthCheckResponse.Status.UP)); + } + + @Override + public void testHealthCheckWithCustomDML() { + Config cfgStatement = config.get("db.statements.ping-dml"); + assertThat("Missing ping-dml statement in database configuration!", cfgStatement.exists(), equalTo(true)); + String statement = cfgStatement.asString().get(); + assertThat("Missing ping-dml statement String in database configuration!", statement, CoreMatchers.is(notNullValue())); + HealthCheck check = DbClientHealthCheck.builder(db).dml().statement(statement).build(); + HealthCheckResponse response = check.call(); + HealthCheckResponse.Status state = response.status(); + assertThat("Health check failed, response: " + response.details(), state, equalTo(HealthCheckResponse.Status.UP)); + } + + @Override + public void testHealthCheckWithCustomNamedQuery() { + HealthCheck check = DbClientHealthCheck.builder(db).query().statementName("ping").build(); + HealthCheckResponse response = check.call(); + HealthCheckResponse.Status state = response.status(); + assertThat("Health check failed, response: " + response.details(), state, equalTo(HealthCheckResponse.Status.UP)); + } + + @Override + public void testHealthCheckWithCustomQuery() { + Config cfgStatement = config.get("db.statements.ping"); + assertThat("Missing ping-query statement in database configuration!", cfgStatement.exists(), equalTo(true)); + String statement = cfgStatement.asString().get(); + assertThat("Missing ping-query statement String in database configuration!", statement, CoreMatchers.is(notNullValue())); + HealthCheck check = DbClientHealthCheck.builder(db).query().statement(statement).build(); + HealthCheckResponse response = check.call(); + HealthCheckResponse.Status state = response.status(); + assertThat("Health check failed, response: " + response.details(), state, equalTo(HealthCheckResponse.Status.UP)); + } + + private Http1ClientRequest get(String path) { + return client.get().get(path); + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/RemoteTest.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/RemoteTest.java new file mode 100644 index 00000000000..4898ce80dd1 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/RemoteTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import java.util.NoSuchElementException; + +import io.helidon.http.Status; +import io.helidon.webclient.http1.Http1Client; +import io.helidon.webclient.http1.Http1ClientResponse; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +/** + * Base class for remote tests. + */ +public abstract class RemoteTest { + private final Http1Client client; + + /** + * Create a new instance. + * + * @param path base path + * @param port port + */ + protected RemoteTest(String path, int port) { + client = Http1Client.builder() + .baseUri("http://localhost:" + port + path) + .build(); + } + + /** + * Invoke a GET request against {@code /{path}/{testName}} and assert a {@code 200} response status. + */ + protected void remoteTest() { + String testName = findTestName(); + Http1ClientResponse response = client.get(testName).request(); + assertThat(response.status(), is(Status.OK_200)); + } + + private String findTestName() { + return StackWalker.getInstance().walk(s -> + s.dropWhile(f -> f.getClassName().equals(RemoteTest.class.getName())) + .findFirst() + .map(StackWalker.StackFrame::getMethodName) + .orElseThrow(() -> new NoSuchElementException("Unable to find caller method name"))); + } +} diff --git a/tests/integration/dbclient/h2/src/main/java/module-info.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/SimpleTest.java similarity index 53% rename from tests/integration/dbclient/h2/src/main/java/module-info.java rename to tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/SimpleTest.java index bec50ffe7ec..6ffacc168bb 100644 --- a/tests/integration/dbclient/h2/src/main/java/module-info.java +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/SimpleTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,20 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package io.helidon.tests.integration.dbclient.common; /** - * Helidon Database Client Integration Tests with H2 Database. + * Simple test. */ -module io.helidon.tests.integration.dbclient.h2 { - - requires java.sql; - requires com.h2database; - - requires io.helidon.config; - requires io.helidon.dbclient; - requires io.helidon.tests.integration.dbclient.common; - - provides io.helidon.tests.integration.dbclient.common.spi.SetupProvider - with io.helidon.tests.integration.dbclient.jdbc.H2SetupProvider; - -} \ No newline at end of file +public interface SimpleTest extends SimpleTests.DeleteTest, + SimpleTests.DmlTest, + SimpleTests.GetTest, + SimpleTests.InsertTest, + SimpleTests.QueriesTest, + SimpleTests.UpdateTest { +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/SimpleTestImpl.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/SimpleTestImpl.java new file mode 100644 index 00000000000..54eacadc05e --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/SimpleTestImpl.java @@ -0,0 +1,614 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import java.util.stream.Stream; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbRow; +import io.helidon.tests.integration.dbclient.common.model.Pokemon; +import io.helidon.tests.integration.dbclient.common.model.Pokemons; +import io.helidon.tests.integration.dbclient.common.model.Types; + +/** + * Actual implementation of {@link SimpleTests}. + */ +public final class SimpleTestImpl extends AbstractTestImpl implements SimpleTest { + + /** + * Create a new instance. + * + * @param db db client + * @param config config + */ + public SimpleTestImpl(DbClient db, Config config) { + super(db, config); + } + + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + Pokemon orig = Pokemons.RAYQUAZA; + String stmt = statements.get("delete-pokemon-order-arg"); + long result = db.execute() + .createNamedDelete("delete-rayquaza", stmt) + .addParam(orig.id()).execute(); + verifyDeletePokemon(result, orig); + } + + @Override + public void testCreateNamedDeleteStrNamedArgs() { + Pokemon orig = Pokemons.LUGIA; + long result = db.execute() + .createNamedDelete("delete-pokemon-named-arg") + .addParam("id", orig.id()).execute(); + verifyDeletePokemon(result, orig); + } + + @Override + public void testCreateNamedDeleteStrOrderArgs() { + Pokemon orig = Pokemons.HOOH; + long result = db.execute() + .createNamedDelete("delete-pokemon-order-arg") + .addParam(orig.id()).execute(); + verifyDeletePokemon(result, orig); + } + + @Override + public void testCreateDeleteNamedArgs() { + Pokemon orig = Pokemons.RAIKOU; + String stmt = statements.get("delete-pokemon-named-arg"); + long result = db.execute() + .createDelete(stmt) + .addParam("id", orig.id()).execute(); + verifyDeletePokemon(result, orig); + } + + @Override + public void testCreateDeleteOrderArgs() { + Pokemon orig = Pokemons.GIRATINA; + String stmt = statements.get("delete-pokemon-order-arg"); + long result = db.execute() + .createDelete(stmt) + .addParam(orig.id()).execute(); + verifyDeletePokemon(result, orig); + } + + @Override + public void testNamedDeleteOrderArgs() { + Pokemon orig = Pokemons.REGIROCK; + long result = db.execute() + .namedDelete("delete-pokemon-order-arg", orig.id()); + verifyDeletePokemon(result, orig); + } + + @Override + public void testDeleteOrderArgs() { + Pokemon orig = Pokemons.KYOGRE; + String stmt = statements.get("delete-pokemon-order-arg"); + long result = db.execute() + .delete(stmt, orig.id()); + verifyDeletePokemon(result, orig); + } + + @Override + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + Pokemon pokemon = new Pokemon(200, "Torchic", Types.FIRE); + String stmt = statements.get("insert-pokemon-named-arg"); + long result = db.execute() + .createNamedDmlStatement("insert-torchic", stmt) + .addParam("id", pokemon.id()).addParam("name", pokemon.name()) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateNamedDmlWithInsertStrNamedArgs() { + Pokemon pokemon = new Pokemon(201, "Combusken", Types.FLYING, Types.FIRE); + long result = db.execute() + .createNamedDmlStatement("insert-pokemon-named-arg") + .addParam("id", pokemon.id()).addParam("name", pokemon.name()) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateNamedDmlWithInsertStrOrderArgs() { + Pokemon pokemon = new Pokemon(202, "Treecko", Types.GRASS); + long result = db.execute() + .createNamedDmlStatement("insert-pokemon-order-arg") + .addParam(pokemon.id()).addParam(pokemon.name()) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateDmlWithInsertNamedArgs() { + Pokemon pokemon = new Pokemon(203, "Grovyle", Types.GRASS); + String stmt = statements.get("insert-pokemon-named-arg"); + long result = db.execute() + .createDmlStatement(stmt) + .addParam("id", pokemon.id()).addParam("name", pokemon.name()) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateDmlWithInsertOrderArgs() { + Pokemon pokemon = new Pokemon(204, "Sceptile", Types.GRASS); + String stmt = statements.get("insert-pokemon-order-arg"); + long result = db.execute() + .createDmlStatement(stmt) + .addParam(pokemon.id()).addParam(pokemon.name()) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testNamedDmlWithInsertOrderArgs() { + Pokemon pokemon = new Pokemon(205, "Snover", Types.GRASS, Types.ICE); + long result = db.execute() + .namedDml("insert-pokemon-order-arg", pokemon.id(), pokemon.name()); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testDmlWithInsertOrderArgs() { + Pokemon pokemon = new Pokemon(206, "Abomasnow", Types.GRASS, Types.ICE); + String stmt = statements.get("insert-pokemon-order-arg"); + long result = db.execute() + .dml(stmt, pokemon.id(), pokemon.name()); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + Pokemon orig = Pokemons.PIPLUP; + Pokemon updated = new Pokemon(orig.id(), "UpdatedPiplup", orig.types()); + String stmt = statements.get("update-pokemon-named-arg"); + long result = db.execute() + .createNamedDmlStatement("update-piplup", stmt) + .addParam("name", updated.name()).addParam("id", updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + Pokemon orig = Pokemons.PRINPLUP; + Pokemon updated = new Pokemon(orig.id(), "UpdatedPrinplup", orig.types()); + long result = db.execute() + .createNamedDmlStatement("update-pokemon-named-arg") + .addParam("name", updated.name()).addParam("id", updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + Pokemon orig = Pokemons.EMPOLEON; + Pokemon updated = new Pokemon(orig.id(), "UpdatedEmpoleon", orig.types()); + long result = db.execute() + .createNamedDmlStatement("update-pokemon-order-arg") + .addParam(updated.name()).addParam(updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateDmlWithUpdateNamedArgs() { + Pokemon orig = Pokemons.STARYU; + Pokemon updated = new Pokemon(orig.id(), "UpdatedStaryu", orig.types()); + String stmt = statements.get("update-pokemon-named-arg"); + long result = db.execute() + .createDmlStatement(stmt) + .addParam("name", updated.name()).addParam("id", updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateDmlWithUpdateOrderArgs() { + Pokemon orig = Pokemons.STARMIE; + Pokemon updated = new Pokemon(orig.id(), "UpdatedStarmie", orig.types()); + String stmt = statements.get("update-pokemon-order-arg"); + long result = db.execute() + .createDmlStatement(stmt) + .addParam(updated.name()).addParam(updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testNamedDmlWithUpdateOrderArgs() { + Pokemon orig = Pokemons.HORSEA; + Pokemon updated = new Pokemon(orig.id(), "UpdatedHorsea", orig.types()); + long result = db.execute() + .namedDml("update-pokemon-order-arg", updated.name(), updated.id()); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testDmlWithUpdateOrderArgs() { + Pokemon orig = Pokemons.SEADRA; + Pokemon updated = new Pokemon(orig.id(), "UpdatedSeadra", orig.types()); + String stmt = statements.get("update-pokemon-order-arg"); + long result = db.execute() + .dml(stmt, updated.name(), updated.id()); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + Pokemon pokemon = Pokemons.MUDKIP; + String stmt = statements.get("delete-pokemon-order-arg"); + long result = db.execute() + .createNamedDmlStatement("delete-mudkip", stmt) + .addParam(pokemon.id()) + .execute(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + Pokemon pokemon = Pokemons.MARSHTOMP; + long result = db.execute() + .createNamedDmlStatement("delete-pokemon-named-arg") + .addParam("id", pokemon.id()) + .execute(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + Pokemon pokemon = Pokemons.SWAMPERT; + long result = db.execute() + .createNamedDmlStatement("delete-pokemon-order-arg") + .addParam(pokemon.id()) + .execute(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testCreateDmlWithDeleteNamedArgs() { + Pokemon pokemon = Pokemons.MUK; + String stmt = statements.get("delete-pokemon-named-arg"); + long result = db.execute() + .createDmlStatement(stmt) + .addParam("id", pokemon.id()) + .execute(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testCreateDmlWithDeleteOrderArgs() { + Pokemon pokemon = Pokemons.GRIMER; + String stmt = statements.get("delete-pokemon-order-arg"); + long result = db.execute() + .createDmlStatement(stmt) + .addParam(pokemon.id()) + .execute(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testNamedDmlWithDeleteOrderArgs() { + Pokemon pokemon = Pokemons.CUBCHOO; + long result = db.execute().namedDml("delete-pokemon-order-arg", pokemon.id()); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testDmlWithDeleteOrderArgs() { + Pokemon pokemon = Pokemons.BEARTIC; + String stmt = statements.get("delete-pokemon-order-arg"); + long result = db.execute().dml(stmt, pokemon.id()); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testCreateNamedGetStrStrNamedArgs() { + Pokemon expected = Pokemons.PIKACHU; + String stmt = statements.get("select-pokemon-named-arg"); + DbRow row = db.execute() + .createNamedGet("select-pikachu", stmt) + .addParam("name", expected.name()) + .execute() + .orElse(null); + verifyPokemon(row, expected); + } + + @Override + public void testCreateNamedGetStrNamedArgs() { + Pokemon expected = Pokemons.RAICHU; + DbRow row = db.execute() + .createNamedGet("select-pokemon-named-arg") + .addParam("name", expected.name()) + .execute() + .orElse(null); + verifyPokemon(row, expected); + } + + @Override + public void testCreateNamedGetStrOrderArgs() { + Pokemon expected = Pokemons.MACHOP; + DbRow row = db.execute() + .createNamedGet("select-pokemon-order-arg") + .addParam(expected.name()) + .execute() + .orElse(null); + verifyPokemon(row, expected); + } + + @Override + public void testCreateGetNamedArgs() { + Pokemon expected = Pokemons.SNORLAX; + String stmt = statements.get("select-pokemon-named-arg"); + DbRow row = db.execute() + .createGet(stmt) + .addParam("name", expected.name()) + .execute() + .orElse(null); + verifyPokemon(row, expected); + } + + @Override + public void testCreateGetOrderArgs() { + Pokemon expected = Pokemons.CHARIZARD; + String stmt = statements.get("select-pokemon-order-arg"); + DbRow row = db.execute() + .createGet(stmt) + .addParam(expected.name()) + .execute() + .orElse(null); + verifyPokemon(row, expected); + } + + @Override + public void testNamedGetStrOrderArgs() { + Pokemon expected = Pokemons.MEOWTH; + DbRow row = db.execute() + .namedGet("select-pokemon-order-arg", expected.name()) + .orElse(null); + verifyPokemon(row, expected); + } + + @Override + public void testGetStrOrderArgs() { + Pokemon expected = Pokemons.GYARADOS; + String stmt = statements.get("select-pokemon-order-arg"); + DbRow row = db.execute() + .get(stmt, expected.name()) + .orElse(null); + verifyPokemon(row, expected); + } + + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + Pokemon pokemon = new Pokemon(300, "Bulbasaur", Types.POISON, Types.GRASS); + String stmt = statements.get("insert-pokemon-named-arg"); + long result = db.execute() + .createNamedInsert("insert-bulbasaur", stmt) + .addParam("id", pokemon.id()).addParam("name", pokemon.name()) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateNamedInsertStrNamedArgs() { + Pokemon pokemon = new Pokemon(301, "Ivysaur", Types.POISON, Types.GRASS); + long result = db.execute() + .createNamedInsert("insert-pokemon-named-arg") + .addParam("id", pokemon.id()).addParam("name", pokemon.name()) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateNamedInsertStrOrderArgs() { + Pokemon pokemon = new Pokemon(302, "Venusaur", Types.POISON, Types.GRASS); + long result = db.execute() + .createNamedInsert("insert-pokemon-order-arg") + .addParam(pokemon.id()).addParam(pokemon.name()) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateInsertNamedArgs() { + Pokemon pokemon = new Pokemon(303, "Magby", Types.FIRE); + String stmt = statements.get("insert-pokemon-named-arg"); + long result = db.execute() + .createInsert(stmt) + .addParam("id", pokemon.id()).addParam("name", pokemon.name()) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateInsertOrderArgs() { + Pokemon pokemon = new Pokemon(304, "Magmar", Types.FIRE); + String stmt = statements.get("insert-pokemon-order-arg"); + long result = db.execute() + .createInsert(stmt) + .addParam(pokemon.id()).addParam(pokemon.name()) + .execute(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testNamedInsertOrderArgs() { + Pokemon pokemon = new Pokemon(305, "Rattata", Types.NORMAL); + long result = db.execute().namedInsert("insert-pokemon-order-arg", pokemon.id(), pokemon.name()); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testInsertOrderArgs() { + Pokemon pokemon = new Pokemon(306, "Raticate", Types.NORMAL); + String stmt = statements.get("insert-pokemon-order-arg"); + long result = db.execute().insert(stmt, pokemon.id(), pokemon.name()); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + Pokemon expected = Pokemons.PIKACHU; + String stmt = statements.get("select-pokemon-order-arg"); + Stream rows = db.execute() + .createNamedQuery("select-pikachu", stmt) + .addParam(expected.name()) + .execute(); + + verifyPokemon(rows, expected); + } + + @Override + public void testCreateNamedQueryStrNamedArgs() { + Pokemon expected = Pokemons.RAICHU; + Stream rows = db.execute() + .createNamedQuery("select-pokemon-named-arg") + .addParam("name", expected.name()) + .execute(); + verifyPokemon(rows, expected); + } + + @Override + public void testCreateNamedQueryStrOrderArgs() { + Pokemon expected = Pokemons.MACHOP; + Stream rows = db.execute() + .createNamedQuery("select-pokemon-order-arg") + .addParam(expected.name()) + .execute(); + verifyPokemon(rows, expected); + } + + @Override + public void testCreateQueryNamedArgs() { + Pokemon expected = Pokemons.SNORLAX; + String stmt = statements.get("select-pokemon-named-arg"); + Stream rows = db.execute() + .createQuery(stmt) + .addParam("name", expected.name()) + .execute(); + verifyPokemon(rows, expected); + } + + @Override + public void testCreateQueryOrderArgs() { + Pokemon expected = Pokemons.CHARIZARD; + String stmt = statements.get("select-pokemon-order-arg"); + Stream rows = db.execute() + .createQuery(stmt) + .addParam(expected.name()) + .execute(); + verifyPokemon(rows, expected); + } + + @Override + public void testNamedQueryOrderArgs() { + Pokemon expected = Pokemons.MEOWTH; + Stream rows = db.execute() + .namedQuery("select-pokemon-order-arg", expected.name()); + verifyPokemon(rows, expected); + } + + @Override + public void testQueryOrderArgs() { + Pokemon expected = Pokemons.GYARADOS; + String stmt = statements.get("select-pokemon-order-arg"); + Stream rows = db.execute() + .query(stmt, expected.name()); + verifyPokemon(rows, expected); + } + + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + Pokemon orig = Pokemons.SPEAROW; + Pokemon updated = new Pokemon(orig.id(), "UpdatedSpearow", orig.types()); + String stmt = statements.get("update-pokemon-named-arg"); + long result = db.execute() + .createNamedUpdate("update-spearow", stmt) + .addParam("name", updated.name()).addParam("id", updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateNamedUpdateStrNamedArgs() { + Pokemon orig = Pokemons.FEAROW; + Pokemon updated = new Pokemon(orig.id(), "UpdatedFearow", orig.types()); + long result = db.execute() + .createNamedUpdate("update-pokemon-named-arg") + .addParam("name", updated.name()).addParam("id", updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateNamedUpdateStrOrderArgs() { + Pokemon orig = Pokemons.EKANS; + Pokemon updated = new Pokemon(orig.id(), "UpdatedEkans", orig.types()); + long result = db.execute() + .createNamedUpdate("update-pokemon-order-arg") + .addParam(updated.name()).addParam(updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateUpdateNamedArgs() { + Pokemon orig = Pokemons.ARBOK; + Pokemon updated = new Pokemon(orig.id(), "UpdatedArbok", orig.types()); + String stmt = statements.get("update-pokemon-named-arg"); + long result = db.execute() + .createUpdate(stmt) + .addParam("name", updated.name()).addParam("id", updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateUpdateOrderArgs() { + Pokemon orig = Pokemons.SANDSHREW; + Pokemon updated = new Pokemon(orig.id(), "UpdatedSandshrew", orig.types()); + String stmt = statements.get("update-pokemon-order-arg"); + long result = db.execute() + .createUpdate(stmt) + .addParam(updated.name()).addParam(updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testNamedUpdateNamedArgs() { + Pokemon orig = Pokemons.SANDSLASH; + Pokemon updated = new Pokemon(orig.id(), "UpdatedSandslash", orig.types()); + long result = db.execute() + .namedUpdate("update-pokemon-order-arg", updated.name(), updated.id()); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testUpdateOrderArgs() { + Pokemon orig = Pokemons.DIGLETT; + Pokemon updated = new Pokemon(orig.id(), "UpdatedDiglett", orig.types()); + String stmt = statements.get("update-pokemon-order-arg"); + long result = db.execute() + .update(stmt, updated.name(), updated.id()); + verifyUpdatePokemon(result, updated); + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/SimpleTests.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/SimpleTests.java new file mode 100644 index 00000000000..b9b3a935d45 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/SimpleTests.java @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +/** + * Simple test. + */ +public interface SimpleTests { + + /** + * Test set of basic JDBC delete calls. + */ + interface DeleteTest { + + /** + * Verify {@code createNamedDelete(String, String)} API method with ordered parameters. + */ + void testCreateNamedDeleteStrStrOrderArgs(); + + /** + * Verify {@code createNamedDelete(String)} API method with named parameters. + */ + void testCreateNamedDeleteStrNamedArgs(); + + /** + * Verify {@code createNamedDelete(String)} API method with ordered parameters. + */ + void testCreateNamedDeleteStrOrderArgs(); + + /** + * Verify {@code createDelete(String)} API method with named parameters. + */ + void testCreateDeleteNamedArgs(); + + /** + * Verify {@code createDelete(String)} API method with ordered parameters. + */ + void testCreateDeleteOrderArgs(); + + /** + * Verify {@code namedDelete(String)} API method with ordered parameters. + */ + void testNamedDeleteOrderArgs(); + + /** + * Verify {@code delete(String)} API method with ordered parameters. + */ + void testDeleteOrderArgs(); + } + + /** + * Test set of basic JDBC DML statement calls. + */ + interface DmlTest { + + /** + * Verify {@code createNamedDmlStatement(String, String)} API method with insert with named parameters. + */ + void testCreateNamedDmlWithInsertStrStrNamedArgs(); + + /** + * Verify {@code createNamedDmlStatement(String)} API method with insert with named parameters. + */ + void testCreateNamedDmlWithInsertStrNamedArgs(); + + /** + * Verify {@code createNamedDmlStatement(String)} API method with insert with ordered parameters. + */ + void testCreateNamedDmlWithInsertStrOrderArgs(); + + /** + * Verify {@code createDmlStatement(String)} API method with insert with named parameters. + */ + void testCreateDmlWithInsertNamedArgs(); + + /** + * Verify {@code createDmlStatement(String)} API method with insert with ordered parameters. + */ + void testCreateDmlWithInsertOrderArgs(); + + /** + * Verify {@code namedDml(String)} API method with insert with ordered parameters passed directly + * to the {@code insert} method. + */ + void testNamedDmlWithInsertOrderArgs(); + + /** + * Verify {@code dml(String)} API method with insert with ordered parameters passed directly + * to the {@code insert} method. + */ + void testDmlWithInsertOrderArgs(); + + /** + * Verify {@code createNamedDmlStatement(String, String)} API method with update with named parameters. + */ + void testCreateNamedDmlWithUpdateStrStrNamedArgs(); + + /** + * Verify {@code createNamedDmlStatement(String)} API method with update with named parameters. + */ + void testCreateNamedDmlWithUpdateStrNamedArgs(); + + /** + * Verify {@code createNamedDmlStatement(String)} API method with update with ordered parameters. + */ + void testCreateNamedDmlWithUpdateStrOrderArgs(); + + /** + * Verify {@code createDmlStatement(String)} API method with update with named parameters. + */ + void testCreateDmlWithUpdateNamedArgs(); + + /** + * Verify {@code createDmlStatement(String)} API method with update with ordered parameters. + */ + void testCreateDmlWithUpdateOrderArgs(); + + /** + * Verify {@code namedDml(String)} API method with update with ordered parameters passed directly + * to the {@code insert} method. + */ + void testNamedDmlWithUpdateOrderArgs(); + + /** + * Verify {@code dml(String)} API method with update with ordered parameters passed directly + * to the {@code insert} method. + */ + void testDmlWithUpdateOrderArgs(); + + /** + * Verify {@code createNamedDmlStatement(String, String)} API method with delete with ordered parameters. + */ + void testCreateNamedDmlWithDeleteStrStrOrderArgs(); + + /** + * Verify {@code createNamedDmlStatement(String)} API method with delete with named parameters. + */ + void testCreateNamedDmlWithDeleteStrNamedArgs(); + + /** + * Verify {@code createNamedDmlStatement(String)} API method with delete with ordered parameters. + */ + void testCreateNamedDmlWithDeleteStrOrderArgs(); + + /** + * Verify {@code createDmlStatement(String)} API method with delete with named parameters. + */ + void testCreateDmlWithDeleteNamedArgs(); + + /** + * Verify {@code createDmlStatement(String)} API method with delete with ordered parameters. + */ + void testCreateDmlWithDeleteOrderArgs(); + + /** + * Verify {@code namedDml(String)} API method with delete with ordered parameters. + */ + void testNamedDmlWithDeleteOrderArgs(); + + /** + * Verify {@code dml(String)} API method with delete with ordered parameters. + */ + void testDmlWithDeleteOrderArgs(); + } + + /** + * Test set of basic JDBC get calls. + */ + interface GetTest { + + /** + * Verify {@code createNamedGet(String, String)} API method with named parameters. + */ + void testCreateNamedGetStrStrNamedArgs(); + + /** + * Verify {@code createNamedGet(String)} API method with named parameters. + */ + void testCreateNamedGetStrNamedArgs(); + + /** + * Verify {@code createNamedGet(String)} API method with ordered parameters. + */ + void testCreateNamedGetStrOrderArgs(); + + /** + * Verify {@code createGet(String)} API method with named parameters. + */ + void testCreateGetNamedArgs(); + + /** + * Verify {@code createGet(String)} API method with ordered parameters. + */ + void testCreateGetOrderArgs(); + + /** + * Verify {@code namedGet(String)} API method with ordered parameters passed directly to the {@code query} method. + */ + void testNamedGetStrOrderArgs(); + + /** + * Verify {@code get(String)} API method with ordered parameters passed directly to the {@code query} method. + */ + void testGetStrOrderArgs(); + } + + /** + * Test set of basic JDBC inserts. + */ + interface InsertTest { + + /** + * Verify {@code createNamedInsert(String, String)} API method with named parameters. + */ + void testCreateNamedInsertStrStrNamedArgs(); + + /** + * Verify {@code createNamedInsert(String)} API method with named parameters. + */ + void testCreateNamedInsertStrNamedArgs(); + + /** + * Verify {@code createNamedInsert(String)} API method with ordered parameters. + */ + void testCreateNamedInsertStrOrderArgs(); + + /** + * Verify {@code createInsert(String)} API method with named parameters. + */ + void testCreateInsertNamedArgs(); + + /** + * Verify {@code createInsert(String)} API method with ordered parameters. + */ + void testCreateInsertOrderArgs(); + + /** + * Verify {@code namedInsert(String)} API method with ordered parameters passed directly to the {@code insert} method. + */ + void testNamedInsertOrderArgs(); + + /** + * Verify {@code insert(String)} API method with ordered parameters passed directly to the {@code insert} method. + */ + void testInsertOrderArgs(); + } + + /** + * Test set of basic JDBC queries. + */ + interface QueriesTest { + + /** + * Verify {@code createNamedQuery(String, String)} API method with ordered parameters. + */ + void testCreateNamedQueryStrStrOrderArgs(); + + /** + * Verify {@code createNamedQuery(String)} API method with named parameters. + */ + void testCreateNamedQueryStrNamedArgs(); + + /** + * Verify {@code createNamedQuery(String)} API method with ordered parameters. + */ + void testCreateNamedQueryStrOrderArgs(); + + /** + * Verify {@code createQuery(String)} API method with named parameters. + */ + void testCreateQueryNamedArgs(); + + /** + * Verify {@code createQuery(String)} API method with ordered parameters. + */ + void testCreateQueryOrderArgs(); + + /** + * Verify {@code namedQuery(String)} API method with ordered parameters passed directly to the {@code namedQuery} method. + */ + void testNamedQueryOrderArgs(); + + /** + * Verify {@code query(String)} API method with ordered parameters passed directly to the {@code query} method. + */ + void testQueryOrderArgs(); + } + + /** + * Test set of basic JDBC updates. + */ + interface UpdateTest { + + /** + * Verify {@code createNamedUpdate(String, String)} API method with named parameters. + */ + void testCreateNamedUpdateStrStrNamedArgs(); + + /** + * Verify {@code createNamedUpdate(String)} API method with named parameters. + */ + void testCreateNamedUpdateStrNamedArgs(); + + /** + * Verify {@code createNamedUpdate(String)} API method with ordered parameters. + */ + void testCreateNamedUpdateStrOrderArgs(); + + /** + * Verify {@code createUpdate(String)} API method with named parameters. + */ + void testCreateUpdateNamedArgs(); + + /** + * Verify {@code createUpdate(String)} API method with ordered parameters. + */ + void testCreateUpdateOrderArgs(); + + /** + * Verify {@code namedUpdate(String)} API method with named parameters. + */ + void testNamedUpdateNamedArgs(); + + /** + * Verify {@code update(String)} API method with ordered parameters. + */ + void testUpdateOrderArgs(); + } +} \ No newline at end of file diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/spi/SetupProvider.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/StatementTest.java similarity index 55% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/spi/SetupProvider.java rename to tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/StatementTest.java index d3c110cb658..d3a2eb73106 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/spi/SetupProvider.java +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/StatementTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,23 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.spi; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; - -public interface SetupProvider { - - /** - * Provide root {@Config} instance for the tests. - */ - Config config(); - - /** - * Provide {@link DbClient} instance for the tests. - * - * @return the {@link DbClient} instance - */ - DbClient dbClient(); +package io.helidon.tests.integration.dbclient.common; +/** + * Statement tests. + */ +public interface StatementTest extends StatementTests.StmtExceptionalTest, + StatementTests.StmtGetTest, + StatementTests.StmtQueryTest, + StatementTests.StmtDmlTest { } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/StatementTestImpl.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/StatementTestImpl.java new file mode 100644 index 00000000000..92d2a813fdf --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/StatementTestImpl.java @@ -0,0 +1,381 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbRow; +import io.helidon.tests.integration.dbclient.common.model.Pokemon; +import io.helidon.tests.integration.dbclient.common.model.Pokemons; +import io.helidon.tests.integration.dbclient.common.model.Range; +import io.helidon.tests.integration.dbclient.common.model.Types; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.notNullValue; + +/** + * Actual implementation of {@link StatementTests}. + */ +public final class StatementTestImpl extends AbstractTestImpl implements StatementTest { + + /** + * Create a new instance. + * + * @param db db client + * @param config config + */ + public StatementTestImpl(DbClient db, Config config) { + super(db, config); + } + + @Override + public void testCreateNamedQueryNonExistentStmt() { + try { + List ignored = db.execute() + .createNamedQuery("select-pokemons-not-exists") + .execute() + .toList(); + throw new AssertionError("Execution of non existing statement shall cause an exception to be thrown."); + } catch (Throwable ex) { + // expected + } + } + + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + try { + List ignored = db.execute() + .createNamedQuery("select-pokemons-error-arg") + .execute() + .toList(); + throw new AssertionError("Execution of query with both named and ordered parameters without passing any shall fail."); + } catch (Throwable ex) { + // expected + } + } + + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + try { + Pokemon pokemon = Pokemons.CHARIZARD; + List ignored = db.execute() + .createNamedQuery("select-pokemons-error-arg") + .addParam("id", pokemon.id()) + .addParam(pokemon.name()) + .execute() + .toList(); + throw new AssertionError("Execution of query with both named and ordered parameters without passing them shall fail" + + "."); + } catch (Throwable ex) { + // expected + } + } + + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + try { + Pokemon pokemon = Pokemons.CHARIZARD; + List ignored = db.execute() + .createNamedQuery("select-pokemon-named-arg") + .addParam(pokemon.name()) + .execute() + .toList(); + throw new AssertionError("Execution of query with named parameter with passing ordered parameter value shall fail."); + } catch (Throwable ex) { + // expected + } + } + + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + try { + Pokemon pokemon = Pokemons.MEOWTH; + List ignored = db.execute() + .createNamedQuery("select-pokemon-order-arg") + .addParam("name", pokemon.name()) + .execute() + .toList(); + throw new AssertionError("Execution of query with ordered parameter with passing named parameter value shall fail."); + } catch (Throwable ex) { + // expected + } + } + + @Override + public void testGetArrayParams() { + DbRow row = db.execute() + .createNamedGet("select-pokemons-idrng-order-arg") + .params(1, 3) + .execute() + .orElse(null); + verifyPokemonsIdRange(row, 1, 3); + } + + @Override + public void testGetListParams() { + DbRow row = db.execute() + .createNamedGet("select-pokemons-idrng-order-arg") + .params(List.of(2, 4)) + .execute() + .orElse(null); + verifyPokemonsIdRange(row, 2, 4); + } + + @Override + public void testGetMapParams() { + DbRow row = db.execute() + .createNamedGet("select-pokemons-idrng-named-arg") + .params(Map.of( + "idmin", 3, + "idmax", 5)) + .execute() + .orElse(null); + verifyPokemonsIdRange(row, 3, 5); + } + + @Override + public void testGetOrderParam() { + DbRow row = db.execute() + .createNamedGet("select-pokemons-idrng-order-arg") + .addParam(4) + .addParam(6) + .execute() + .orElse(null); + verifyPokemonsIdRange(row, 4, 6); + } + + @Override + public void testGetNamedParam() { + DbRow row = db.execute() + .createNamedGet("select-pokemons-idrng-named-arg") + .addParam("idmin", 5) + .addParam("idmax", 7) + .execute() + .orElse(null); + verifyPokemonsIdRange(row, 5, 7); + } + + @Override + public void testGetMappedNamedParam() { + Range range = new Range(0, 2); + DbRow row = db.execute() + .createNamedGet("select-pokemons-idrng-named-arg") + .namedParam(range) + .execute() + .orElse(null); + verifyPokemonsIdRange(row, 0, 2); + } + + @Override + public void testGetMappedOrderParam() { + Range range = new Range(6, 8); + DbRow row = db.execute() + .createNamedGet("select-pokemons-idrng-order-arg") + .indexedParam(range) + .execute() + .orElse(null); + verifyPokemonsIdRange(row, 6, 8); + } + + @Override + public void testQueryArrayParams() { + Stream rows = db.execute() + .createNamedQuery("select-pokemons-idrng-order-arg") + .params(1, 7) + .execute(); + + verifyPokemonsIdRange(rows); + } + + @Override + public void testQueryListParams() { + Stream rows = db.execute() + .createNamedQuery("select-pokemons-idrng-order-arg") + .params(List.of(1, 7)) + .execute(); + + verifyPokemonsIdRange(rows); + } + + @Override + public void testQueryMapParams() { + Stream rows = db.execute() + .createNamedQuery("select-pokemons-idrng-named-arg") + .params(Map.of( + "idmin", 1, + "idmax", 7)) + .execute(); + + verifyPokemonsIdRange(rows); + } + + @Override + public void testQueryMapMissingParams() { + Stream rows = db.execute() + .createNamedQuery("select-pokemons-idname-named-arg") + .params(Map.of("id", 1)) + .execute(); + assertThat(rows, notNullValue()); + List rowsList = rows.toList(); + assertThat(rowsList, hasSize(0)); + } + + @Override + public void testQueryOrderParam() { + Stream rows = db.execute() + .createNamedQuery("select-pokemons-idrng-order-arg") + .addParam(1) + .addParam(7) + .execute(); + + verifyPokemonsIdRange(rows); + } + + @Override + public void testQueryNamedParam() { + Stream rows = db.execute() + .createNamedQuery("select-pokemons-idrng-named-arg") + .addParam("idmin", 1) + .addParam("idmax", 7) + .execute(); + + verifyPokemonsIdRange(rows); + } + + @Override + public void testQueryMappedNamedParam() { + Range range = new Range(1, 7); + Stream rows = db.execute() + .createNamedQuery("select-pokemons-idrng-named-arg") + .namedParam(range) + .execute(); + + verifyPokemonsIdRange(rows); + } + + @Override + public void testQueryMappedOrderParam() { + Range range = new Range(1, 7); + Stream rows = db.execute() + .createNamedQuery("select-pokemons-idrng-order-arg") + .indexedParam(range) + .execute(); + + verifyPokemonsIdRange(rows); + } + + @Override + public void testDmlArrayParams() { + Pokemon orig = Pokemons.SHINX; + Pokemon updated = new Pokemon(orig.id(), "UpdatedShinx", Types.ELECTRIC); + long result = db.execute() + .createNamedDmlStatement("update-pokemon-order-arg") + .params(updated.name(), updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testDmlListParams() { + Pokemon orig = Pokemons.LUXIO; + Pokemon updated = new Pokemon(orig.id(), "UpdatedLuxio", Types.ELECTRIC); + long result = db.execute() + .createNamedDmlStatement("update-pokemon-order-arg") + .params(List.of(updated.name(), updated.id())) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testDmlMapParams() { + Pokemon orig = Pokemons.LUXRAY; + Pokemon updated = new Pokemon(orig.id(), "UpdatedLuxray", Types.ELECTRIC); + long result = db.execute() + .createNamedDmlStatement("update-pokemon-named-arg") + .params(Map.of( + "name", updated.name(), + "id", updated.id())) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testDmlOrderParam() { + Pokemon orig = Pokemons.KRICKETOT; + Pokemon updated = new Pokemon(orig.id(), "UpdatedKricketot", Types.BUG); + long result = db.execute() + .createNamedDmlStatement("update-pokemon-order-arg") + .addParam(updated.name()) + .addParam(updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testDmlNamedParam() { + Pokemon orig = Pokemons.KRICKETUNE; + Pokemon updated = new Pokemon(orig.id(), "UpdatedKricketune", Types.BUG); + long result = db.execute() + .createNamedDmlStatement("update-pokemon-named-arg") + .addParam("name", updated.name()) + .addParam("id", updated.id()) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testDmlMappedNamedParam() { + Pokemon orig = Pokemons.PHIONE; + Pokemon updated = new Pokemon(orig.id(), "UpdatedPhione", Types.NORMAL, Types.FLYING); + long result = db.execute() + .createNamedDmlStatement("update-pokemon-named-arg") + .namedParam(updated) + .execute(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testDmlMappedOrderParam() { + Pokemon orig = Pokemons.CHATOT; + Pokemon updated = new Pokemon(orig.id(), "UpdatedChatot", Types.WATER); + long result = db.execute() + .createNamedDmlStatement("update-pokemon-order-arg") + .indexedParam(updated) + .execute(); + verifyUpdatePokemon(result, updated); + } + + private void verifyPokemonsIdRange(Stream rows) { + Map valid = range(1, 7); + + // Compare result with valid data + assertThat(rows, notNullValue()); + List rowsList = rows.toList(); + assertThat(rowsList, hasSize(valid.size())); + for (DbRow row : rowsList) { + int id = row.column(1).get(Integer.class); + String name = row.column(2).get(String.class); + assertThat(valid.containsKey(id), equalTo(true)); + assertThat(name, equalTo(valid.get(id).name())); + } + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/StatementTests.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/StatementTests.java new file mode 100644 index 00000000000..b5602f49221 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/StatementTests.java @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +/** + * Statement tests. + */ +public interface StatementTests { + + /** + * Test exceptional states. + */ + interface StmtExceptionalTest { + + /** + * Verify that execution of query with non-existing named statement throws an exception. + */ + void testCreateNamedQueryNonExistentStmt(); + + /** + * Verify that execution of query with both named and ordered arguments throws an exception. + */ + void testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + + /** + * Verify that execution of query with both named and ordered arguments throws an exception. + */ + void testCreateNamedQueryNamedAndOrderArgsWithArgs(); + + /** + * Verify that execution of query with named arguments throws an exception while trying to set ordered argument. + */ + void testCreateNamedQueryNamedArgsSetOrderArg(); + + /** + * Verify that execution of query with ordered arguments throws an exception while trying to set named argument. + */ + void testCreateNamedQueryOrderArgsSetNamedArg(); + } + + /** + * Test DbStatementGet methods. + */ + interface StmtGetTest { + + /** + * Verify {@code params(Object... parameters)} parameters setting method. + */ + void testGetArrayParams(); + + /** + * Verify {@code params(List)} parameters setting method. + */ + void testGetListParams(); + + /** + * Verify {@code params(Map)} parameters setting method. + */ + void testGetMapParams(); + + /** + * Verify {@code addParam(Object parameter)} parameters setting method. + */ + void testGetOrderParam(); + + /** + * Verify {@code addParam(String name, Object parameter)} parameters setting method. + */ + void testGetNamedParam(); + + /** + * Verify {@code namedParam(Object parameters)} mapped parameters setting method. + */ + void testGetMappedNamedParam(); + + /** + * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. + */ + void testGetMappedOrderParam(); + } + + /** + * Test DbStatementQuery methods. + */ + interface StmtQueryTest { + + /** + * Verify {@code params(Object... parameters)} parameters setting method. + */ + void testQueryArrayParams(); + + /** + * Verify {@code params(List)} parameters setting method. + */ + void testQueryListParams(); + + /** + * Verify {@code params(Map)} parameters setting method. + */ + void testQueryMapParams(); + + /** + * Verify {@code params(Map)} with missing parameters. + */ + void testQueryMapMissingParams(); + + /** + * Verify {@code addParam(Object parameter)} parameters setting method. + */ + void testQueryOrderParam(); + + /** + * Verify {@code addParam(String name, Object parameter)} parameters setting method. + */ + void testQueryNamedParam(); + + /** + * Verify {@code namedParam(Object parameters)} mapped parameters setting method. + */ + void testQueryMappedNamedParam(); + + /** + * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. + */ + void testQueryMappedOrderParam(); + } + + /** + * Test DbStatementDml methods. + */ + interface StmtDmlTest { + + /** + * Verify {@code params(Object... parameters)} parameters setting method. + */ + void testDmlArrayParams(); + + /** + * Verify {@code params(List)} parameters setting method. + */ + void testDmlListParams(); + + /** + * Verify {@code params(Map)} parameters setting method. + */ + void testDmlMapParams(); + + /** + * Verify {@code addParam(Object parameter)} parameters setting method. + */ + void testDmlOrderParam(); + + /** + * Verify {@code addParam(String name, Object parameter)} parameters setting method. + */ + void testDmlNamedParam(); + + /** + * Verify {@code namedParam(Object parameters)} mapped parameters setting method. + */ + void testDmlMappedNamedParam(); + + /** + * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. + */ + void testDmlMappedOrderParam(); + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TestService.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TestService.java new file mode 100644 index 00000000000..15e78a130a7 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TestService.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import java.lang.reflect.InvocationTargetException; + +import io.helidon.common.context.Contexts; +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.http.InternalServerException; +import io.helidon.http.NotFoundException; +import io.helidon.webclient.http1.Http1Client; +import io.helidon.webserver.WebServer; +import io.helidon.webserver.http.HttpRules; +import io.helidon.webserver.http.HttpService; +import io.helidon.webserver.http.ServerRequest; +import io.helidon.webserver.http.ServerResponse; + +import static java.util.Objects.requireNonNullElse; + +/** + * Service to expose all tests. + */ +final class TestService implements HttpService { + + private final TransactionTestImpl transaction; + private final StatementTestImpl statement; + private final SimpleTestImpl simple; + private final MiscTestImpl misc; + private final ObservabilityTestImpl observability; + + TestService(DbClient db, Config config) { + transaction = new TransactionTestImpl(db, config); + statement = new StatementTestImpl(db, config); + simple = new SimpleTestImpl(db, config); + misc = new MiscTestImpl(db, config); + observability = new ObservabilityTestImpl(db, config, this::client); + } + + private Http1Client client() { + return Contexts.context() + .flatMap(c -> c.get(WebServer.class)) + .map(server -> Http1Client.builder() + .baseUri("http://localhost:" + server.port()) + .build()) + .orElseThrow(() -> new IllegalStateException("Unable to get server instance from current context")); + } + + @Override + public void routing(HttpRules rules) { + rules + .get("/transaction/{testName}", this::transaction) + .get("/statement/{testName}", this::statement) + .get("/simple/{testName}", this::simple) + .get("/misc/{testName}", this::misc) + .get("/observability/{testName}", this::observability); + } + + private void transaction(ServerRequest req, ServerResponse res) { + invokeTest(transaction, req, res); + } + + private void statement(ServerRequest req, ServerResponse res) { + invokeTest(statement, req, res); + } + + private void simple(ServerRequest req, ServerResponse res) { + invokeTest(simple, req, res); + + } + + private void misc(ServerRequest req, ServerResponse res) { + invokeTest(misc, req, res); + } + + private void observability(ServerRequest req, ServerResponse res) { + invokeTest(observability, req, res); + } + + private static void invokeTest(Object o, ServerRequest req, ServerResponse res) { + String testName = req.path().pathParameters().get("testName"); + try { + o.getClass().getMethod(testName).invoke(o); + res.send("OK"); + } catch (IllegalAccessException ex) { + throw new InternalServerException(ex.getMessage(), ex); + } catch (InvocationTargetException ex) { + requireNonNullElse(ex.getCause(), ex).printStackTrace(System.err); + throw new InternalServerException(ex.getMessage(), ex); + } catch (NoSuchMethodException ignored) { + throw new NotFoundException("Test not found: " + testName); + } + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TransactionTest.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TransactionTest.java new file mode 100644 index 00000000000..101d26a2865 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TransactionTest.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +/** + * Test set of basic JDBC delete calls in transaction. + */ +public interface TransactionTest extends TransactionTests.TxDeleteTest, + TransactionTests.TxExceptionalStmtTest, + TransactionTests.TxGetTest, + TransactionTests.TxInsertTest, + TransactionTests.TxQueriesTest, + TransactionTests.TxUpdateTest { +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TransactionTestImpl.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TransactionTestImpl.java new file mode 100644 index 00000000000..504463395e6 --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TransactionTestImpl.java @@ -0,0 +1,559 @@ +/* + * Copyright (c) 2019, 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +import java.util.List; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbRow; +import io.helidon.dbclient.DbTransaction; +import io.helidon.tests.integration.dbclient.common.model.Pokemon; +import io.helidon.tests.integration.dbclient.common.model.Pokemons; +import io.helidon.tests.integration.dbclient.common.model.Types; + +/** + * Actual implementation of {@link TransactionTests}. + */ +public final class TransactionTestImpl extends AbstractTestImpl implements TransactionTest { + + /** + * Create a new instance. + * + * @param db db client + * @param config config + */ + public TransactionTestImpl(DbClient db, Config config) { + super(db, config); + } + + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + Pokemon pokemon = Pokemons.OMANYTE; + String stmt = statements.get("delete-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .createNamedDelete("delete-rayquaza", stmt) + .addParam(pokemon.id()) + .execute(); + tx.commit(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testCreateNamedDeleteStrNamedArgs() { + Pokemon pokemon = Pokemons.OMASTAR; + DbTransaction tx = db.transaction(); + long result = tx + .createNamedDelete("delete-pokemon-named-arg") + .addParam("id", pokemon.id()) + .execute(); + tx.commit(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testCreateNamedDeleteStrOrderArgs() { + Pokemon pokemon = Pokemons.KABUTO; + DbTransaction tx = db.transaction(); + long result = tx + .createNamedDelete("delete-pokemon-order-arg") + .addParam(pokemon.id()) + .execute(); + tx.commit(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testCreateDeleteNamedArgs() { + Pokemon pokemon = Pokemons.KABUTOPS; + String stmt = statements.get("delete-pokemon-named-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .createDelete(stmt) + .addParam("id", pokemon.id()) + .execute(); + tx.commit(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testCreateDeleteOrderArgs() { + Pokemon pokemon = Pokemons.CHIKORITA; + String stmt = statements.get("delete-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .createDelete(stmt) + .addParam(pokemon.id()) + .execute(); + tx.commit(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testNamedDeleteOrderArgs() { + Pokemon pokemon = Pokemons.BAYLEEF; + DbTransaction tx = db.transaction(); + long result = tx + .namedDelete("delete-pokemon-order-arg", pokemon.id()); + tx.commit(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testDeleteOrderArgs() { + Pokemon pokemon = Pokemons.MEGANIUM; + String stmt = statements.get("delete-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .delete(stmt, pokemon.id()); + tx.commit(); + verifyDeletePokemon(result, pokemon); + } + + @Override + public void testCreateNamedQueryNonExistentStmt() { + try { + DbTransaction tx = db.transaction(); + List ignored = tx.createNamedQuery("select-pokemons-not-exists") + .execute() + .toList(); + tx.commit(); + throw new AssertionError("Execution of non existing statement shall cause an exception to be thrown."); + } catch (Throwable ex) { + // expected + } + } + + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + try { + DbTransaction tx = db.transaction(); + List ignored = tx.createNamedQuery("select-pokemons-error-arg") + .execute() + .toList(); + tx.commit(); + throw new AssertionError("Execution of query with both named and ordered parameters without passing any shall fail."); + } catch (Throwable ex) { + // expected + } + } + + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + try { + DbTransaction tx = db.transaction(); + List ignored = tx.createNamedQuery("select-pokemons-error-arg") + .addParam("id", 6789) + .addParam("a-name") + .execute() + .toList(); + tx.commit(); + throw new AssertionError("Execution of query with both named and ordered parameters without passing them shall fail" + + "."); + } catch (Throwable ex) { + // expected + } + } + + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + try { + DbTransaction tx = db.transaction(); + List ignored = tx.createNamedQuery("select-pokemon-named-arg") + .addParam("a-name") + .execute() + .toList(); + tx.commit(); + throw new AssertionError("Execution of query with named parameter with passing ordered parameter value shall fail."); + } catch (Throwable ex) { + // expected + } + } + + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + try { + DbTransaction tx = db.transaction(); + List ignored = tx.createNamedQuery("select-pokemon-order-arg") + .addParam("name", "a-name") + .execute() + .toList(); + tx.commit(); + throw new AssertionError("Execution of query with ordered parameter with passing named parameter value shall fail."); + } catch (Throwable ex) { + // expected + } + } + + @Override + public void testCreateNamedGetStrStrNamedArgs() { + Pokemon expected = Pokemons.PIKACHU; + String stmt = statements.get("select-pokemon-named-arg"); + DbTransaction tx = db.transaction(); + DbRow row = tx + .createNamedGet("select-pikachu", stmt) + .addParam("name", expected.name()) + .execute() + .orElse(null); + tx.commit(); + verifyPokemon(row, expected); + } + + @Override + public void testCreateNamedGetStrNamedArgs() { + Pokemon expected = Pokemons.RAICHU; + DbTransaction tx = db.transaction(); + DbRow row = tx + .createNamedGet("select-pokemon-named-arg") + .addParam("name", expected.name()) + .execute() + .orElse(null); + tx.commit(); + + verifyPokemon(row, expected); + } + + @Override + public void testCreateNamedGetStrOrderArgs() { + Pokemon expected = Pokemons.MACHOP; + DbTransaction tx = db.transaction(); + DbRow row = tx + .createNamedGet("select-pokemon-order-arg") + .addParam(expected.name()) + .execute() + .orElse(null); + tx.commit(); + + verifyPokemon(row, expected); + } + + @Override + public void testCreateGetNamedArgs() { + Pokemon expected = Pokemons.SNORLAX; + String stmt = statements.get("select-pokemon-named-arg"); + DbTransaction tx = db.transaction(); + DbRow row = tx + .createGet(stmt) + .addParam("name", expected.name()) + .execute() + .orElse(null); + tx.commit(); + + verifyPokemon(row, expected); + } + + @Override + public void testCreateGetOrderArgs() { + Pokemon expected = Pokemons.CHARIZARD; + String stmt = statements.get("select-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + DbRow row = tx + .createGet(stmt) + .addParam(expected.name()) + .execute() + .orElse(null); + tx.commit(); + + verifyPokemon(row, expected); + } + + @Override + public void testNamedGetStrOrderArgs() { + Pokemon expected = Pokemons.MEOWTH; + DbTransaction tx = db.transaction(); + DbRow row = tx + .namedGet("select-pokemon-order-arg", expected.name()) + .orElse(null); + tx.commit(); + + verifyPokemon(row, expected); + } + + @Override + public void testGetStrOrderArgs() { + Pokemon expected = Pokemons.GYARADOS; + String stmt = statements.get("select-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + DbRow row = tx + .get(stmt, expected.name()) + .orElse(null); + tx.commit(); + + verifyPokemon(row, expected); + } + + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + Pokemon pokemon = new Pokemon(85, "Sentret", Types.NORMAL); + String stmt = statements.get("insert-pokemon-named-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .createNamedInsert("insert-bulbasaur", stmt) + .addParam("id", pokemon.id()).addParam("name", pokemon.name()).execute(); + tx.commit(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateNamedInsertStrNamedArgs() { + Pokemon pokemon = new Pokemon(86, "Furret", Types.NORMAL); + DbTransaction tx = db.transaction(); + long result = tx + .createNamedInsert("insert-pokemon-named-arg") + .addParam("id", pokemon.id()).addParam("name", pokemon.name()).execute(); + tx.commit(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateNamedInsertStrOrderArgs() { + Pokemon pokemon = new Pokemon(87, "Chinchou", Types.WATER, Types.ELECTRIC); + DbTransaction tx = db.transaction(); + long result = tx + .createNamedInsert("insert-pokemon-order-arg") + .addParam(pokemon.id()).addParam(pokemon.name()).execute(); + tx.commit(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateInsertNamedArgs() { + Pokemon pokemon = new Pokemon(88, "Lanturn", Types.WATER, Types.ELECTRIC); + String stmt = statements.get("insert-pokemon-named-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .createInsert(stmt) + .addParam("id", pokemon.id()).addParam("name", pokemon.name()).execute(); + tx.commit(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateInsertOrderArgs() { + Pokemon pokemon = new Pokemon(89, "Swinub", Types.GROUND, Types.ICE); + String stmt = statements.get("insert-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .createInsert(stmt) + .addParam(pokemon.id()).addParam(pokemon.name()).execute(); + tx.commit(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testNamedInsertOrderArgs() { + Pokemon pokemon = new Pokemon(90, "Piloswine", Types.GROUND, Types.ICE); + DbTransaction tx = db.transaction(); + long result = tx + .namedInsert("insert-pokemon-order-arg", pokemon.id(), pokemon.name()); + tx.commit(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testInsertOrderArgs() { + Pokemon pokemon = new Pokemon(91, "Mamoswine", Types.GROUND, Types.ICE); + String stmt = statements.get("insert-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .insert(stmt, pokemon.id(), pokemon.name()); + tx.commit(); + verifyInsertPokemon(result, pokemon); + } + + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + Pokemon expected = Pokemons.PIKACHU; + String stmt = statements.get("select-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + List rows = tx + .createNamedQuery("select-pikachu", stmt) + .addParam(expected.name()) + .execute() + .toList(); + tx.commit(); + verifyPokemon(rows, expected); + } + + @Override + public void testCreateNamedQueryStrNamedArgs() { + Pokemon expected = Pokemons.RAICHU; + DbTransaction tx = db.transaction(); + List rows = tx + .createNamedQuery("select-pokemon-named-arg") + .addParam("name", expected.name()) + .execute() + .toList(); + tx.commit(); + verifyPokemon(rows, expected); + } + + @Override + public void testCreateNamedQueryStrOrderArgs() { + Pokemon expected = Pokemons.MACHOP; + DbTransaction tx = db.transaction(); + List rows = tx + .createNamedQuery("select-pokemon-order-arg") + .addParam(expected.name()) + .execute() + .toList(); + tx.commit(); + verifyPokemon(rows, expected); + } + + @Override + public void testCreateQueryNamedArgs() { + Pokemon expected = Pokemons.SNORLAX; + String stmt = statements.get("select-pokemon-named-arg"); + DbTransaction tx = db.transaction(); + List rows = tx + .createQuery(stmt) + .addParam("name", expected.name()) + .execute() + .toList(); + tx.commit(); + verifyPokemon(rows, expected); + } + + @Override + public void testCreateQueryOrderArgs() { + Pokemon expected = Pokemons.CHARIZARD; + String stmt = statements.get("select-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + List rows = tx + .createQuery(stmt) + .addParam(expected.name()) + .execute() + .toList(); + tx.commit(); + verifyPokemon(rows, expected); + } + + @Override + public void testNamedQueryOrderArgs() { + Pokemon expected = Pokemons.MEOWTH; + DbTransaction tx = db.transaction(); + List rows = tx + .namedQuery("select-pokemon-order-arg", expected.name()) + .toList(); + tx.commit(); + verifyPokemon(rows, expected); + } + + @Override + public void testQueryOrderArgs() { + Pokemon expected = Pokemons.GYARADOS; + String stmt = statements.get("select-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + List rows = tx + .query(stmt, expected.name()) + .toList(); + tx.commit(); + verifyPokemon(rows, expected); + } + + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + Pokemon orig = Pokemons.TEDDIURSA; + Pokemon updated = new Pokemon(orig.id(), "UpdatedTeddiursa", orig.types()); + String stmt = statements.get("update-pokemon-named-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .createNamedUpdate("update-pokemon-named-arg", stmt) + .addParam("name", updated.name()).addParam("id", updated.id()) + .execute(); + tx.commit(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateNamedUpdateStrNamedArgs() { + Pokemon orig = Pokemons.URSARING; + Pokemon updated = new Pokemon(orig.id(), "UpdatedUrsaring", orig.types()); + DbTransaction tx = db.transaction(); + long result = tx + .createNamedUpdate("update-pokemon-named-arg") + .addParam("name", updated.name()).addParam("id", updated.id()) + .execute(); + tx.commit(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateNamedUpdateStrOrderArgs() { + Pokemon orig = Pokemons.SLUGMA; + Pokemon updated = new Pokemon(orig.id(), "UpdatedSlugma", orig.types()); + DbTransaction tx = db.transaction(); + long result = tx + .createNamedUpdate("update-pokemon-order-arg") + .addParam(updated.name()).addParam(updated.id()) + .execute(); + tx.commit(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateUpdateNamedArgs() { + Pokemon orig = Pokemons.MAGCARGO; + Pokemon updated = new Pokemon(orig.id(), "UpdatedMagcargo", orig.types()); + String stmt = statements.get("update-pokemon-named-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .createUpdate(stmt) + .addParam("name", updated.name()).addParam("id", updated.id()) + .execute(); + tx.commit(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testCreateUpdateOrderArgs() { + Pokemon orig = Pokemons.LOTAD; + Pokemon updated = new Pokemon(orig.id(), "UpdatedLotad", orig.types()); + String stmt = statements.get("update-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .createUpdate(stmt) + .addParam(updated.name()).addParam(updated.id()) + .execute(); + tx.commit(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testNamedUpdateNamedArgs() { + Pokemon orig = Pokemons.LUDICOLO; + Pokemon updated = new Pokemon(orig.id(), "UpdatedLudicolo", orig.types()); + DbTransaction tx = db.transaction(); + long result = tx + .namedUpdate("update-pokemon-order-arg", updated.name(), updated.id()); + tx.commit(); + verifyUpdatePokemon(result, updated); + } + + @Override + public void testUpdateOrderArgs() { + Pokemon orig = Pokemons.LOMBRE; + Pokemon updated = new Pokemon(orig.id(), "UpdatedLombre", orig.types()); + String stmt = statements.get("update-pokemon-order-arg"); + DbTransaction tx = db.transaction(); + long result = tx + .update(stmt, updated.name(), updated.id()); + tx.commit(); + verifyUpdatePokemon(result, updated); + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TransactionTests.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TransactionTests.java new file mode 100644 index 00000000000..a72aa0194ff --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/TransactionTests.java @@ -0,0 +1,258 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common; + +/** + * Test set of basic JDBC delete calls in transaction. + */ +public interface TransactionTests { + + /** + * Test set of basic JDBC delete calls in transaction. + */ + interface TxDeleteTest { + + /** + * Verify {@code createNamedDelete(String, String)} API method with ordered parameters. + */ + void testCreateNamedDeleteStrStrOrderArgs(); + + /** + * Verify {@code createNamedDelete(String)} API method with named parameters. + */ + void testCreateNamedDeleteStrNamedArgs(); + + /** + * Verify {@code createNamedDelete(String)} API method with ordered parameters. + */ + void testCreateNamedDeleteStrOrderArgs(); + + /** + * Verify {@code createDelete(String)} API method with named parameters. + */ + void testCreateDeleteNamedArgs(); + + /** + * Verify {@code createDelete(String)} API method with ordered parameters. + */ + void testCreateDeleteOrderArgs(); + + /** + * Verify {@code namedDelete(String)} API method with ordered parameters. + */ + void testNamedDeleteOrderArgs(); + + /** + * Verify {@code delete(String)} API method with ordered parameters. + */ + void testDeleteOrderArgs(); + } + + /** + * Test exceptional statements. + */ + interface TxExceptionalStmtTest { + + /** + * Verify that execution of query with non-existing named statement throws an exception. + */ + void testCreateNamedQueryNonExistentStmt(); + + /** + * Verify that execution of query with both named and ordered arguments throws an exception. + */ + void testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + + /** + * Verify that execution of query with both named and ordered arguments throws an exception. + */ + void testCreateNamedQueryNamedAndOrderArgsWithArgs(); + + /** + * Verify that execution of query with named arguments throws an exception while trying to set ordered argument. + */ + void testCreateNamedQueryNamedArgsSetOrderArg(); + + /** + * Verify that execution of query with ordered arguments throws an exception while trying to set named argument. + */ + void testCreateNamedQueryOrderArgsSetNamedArg(); + } + + /** + * Test set of basic JDBC get calls in transaction. + */ + interface TxGetTest { + + /** + * Verify {@code createNamedGet(String, String)} API method with named parameters. + */ + void testCreateNamedGetStrStrNamedArgs(); + + /** + * Verify {@code createNamedGet(String)} API method with named parameters. + */ + void testCreateNamedGetStrNamedArgs(); + + /** + * Verify {@code createNamedGet(String)} API method with ordered parameters. + */ + void testCreateNamedGetStrOrderArgs(); + + /** + * Verify {@code createGet(String)} API method with named parameters. + */ + void testCreateGetNamedArgs(); + + /** + * Verify {@code createGet(String)} API method with ordered parameters. + */ + void testCreateGetOrderArgs(); + + /** + * Verify {@code namedGet(String)} API method with ordered parameters passed directly to the {@code query} method. + */ + void testNamedGetStrOrderArgs(); + + /** + * Verify {@code get(String)} API method with ordered parameters passed directly to the {@code query} method. + */ + void testGetStrOrderArgs(); + } + + /** + * Test set of basic JDBC inserts in transaction. + */ + interface TxInsertTest { + + /** + * Verify {@code createNamedInsert(String, String)} API method with named parameters. + */ + void testCreateNamedInsertStrStrNamedArgs(); + + /** + * Verify {@code createNamedInsert(String)} API method with named parameters. + */ + void testCreateNamedInsertStrNamedArgs(); + + /** + * Verify {@code createNamedInsert(String)} API method with ordered parameters. + */ + void testCreateNamedInsertStrOrderArgs(); + + /** + * Verify {@code createInsert(String)} API method with named parameters. + */ + void testCreateInsertNamedArgs(); + + /** + * Verify {@code createInsert(String)} API method with ordered parameters. + */ + void testCreateInsertOrderArgs(); + + /** + * Verify {@code namedInsert(String)} API method with ordered parameters passed directly to the {@code insert} method. + */ + void testNamedInsertOrderArgs(); + + /** + * Verify {@code insert(String)} API method with ordered parameters passed directly to the {@code insert} method. + */ + void testInsertOrderArgs(); + } + + /** + * Test set of basic JDBC queries in transaction. + */ + interface TxQueriesTest { + + /** + * Verify {@code createNamedQuery(String, String)} API method with ordered parameters. + */ + void testCreateNamedQueryStrStrOrderArgs(); + + /** + * Verify {@code createNamedQuery(String)} API method with named parameters. + */ + void testCreateNamedQueryStrNamedArgs(); + + /** + * Verify {@code createNamedQuery(String)} API method with ordered parameters. + */ + void testCreateNamedQueryStrOrderArgs(); + + /** + * Verify {@code createQuery(String)} API method with named parameters. + */ + void testCreateQueryNamedArgs(); + + /** + * Verify {@code createQuery(String)} API method with ordered parameters. + */ + void testCreateQueryOrderArgs(); + + /** + * Verify {@code namedQuery(String)} API method with ordered parameters passed directly to the {@code namedQuery} method. + */ + void testNamedQueryOrderArgs(); + + /** + * Verify {@code query(String)} API method with ordered parameters passed directly to the {@code query} method. + */ + void testQueryOrderArgs(); + } + + /** + * Test set of basic JDBC updates in transaction. + */ + interface TxUpdateTest { + + /** + * Verify {@code createNamedUpdate(String, String)} API method with named parameters. + */ + void testCreateNamedUpdateStrStrNamedArgs(); + + /** + * Verify {@code createNamedUpdate(String)} API method with named parameters. + */ + void testCreateNamedUpdateStrNamedArgs(); + + /** + * Verify {@code createNamedUpdate(String)} API method with ordered parameters. + */ + void testCreateNamedUpdateStrOrderArgs(); + + /** + * Verify {@code createUpdate(String)} API method with named parameters. + */ + void testCreateUpdateNamedArgs(); + + /** + * Verify {@code createUpdate(String)} API method with ordered parameters. + */ + void testCreateUpdateOrderArgs(); + + /** + * Verify {@code namedUpdate(String)} API method with named parameters. + */ + void testNamedUpdateNamedArgs(); + + /** + * Verify {@code update(String)} API method with ordered parameters. + */ + void testUpdateOrderArgs(); + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Pokemon.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Pokemon.java index 2305475ddbe..e6fa9b3ec32 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Pokemon.java +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Pokemon.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,226 +15,25 @@ */ package io.helidon.tests.integration.dbclient.common.model; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; - -import io.helidon.dbclient.DbMapper; -import io.helidon.dbclient.DbRow; - -import jakarta.json.Json; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; /** - * {@code Pokemon} POJO. + * {@code Pokemon}. + * + * @param id id + * @param name name + * @param types types */ -@SuppressWarnings("SpellCheckingInspection") -public class Pokemon { +public record Pokemon(int id, String name, List types) { /** - * {@code Pokemon} POJO mapper. + * Create a new instance. + * + * @param id id + * @param name name + * @param types types */ - public static final class PokemonMapper implements DbMapper { - - public static final PokemonMapper INSTANCE = new PokemonMapper(); - - @Override - public Pokemon read(DbRow row) { - return new Pokemon(row.column("id").get(Integer.class), row.column("name").get(String.class)); - } - - @Override - public Map toNamedParameters(Pokemon value) { - Map params = new HashMap<>(2); - params.put("id", value.getId()); - params.put("name", value.getName()); - return params; - } - - @Override - public List toIndexedParameters(Pokemon value) { - List params = new ArrayList<>(2); - params.add(value.getName()); - params.add(value.getId()); - return params; - } - - } - - /** - * Map of {@code Pokemon} by ID. - */ - public static final Map POKEMONS = new HashMap<>(); - - static { - // query tests - POKEMONS.put(1, new Pokemon(1, "Pikachu", Type.TYPES.get(13))); - POKEMONS.put(2, new Pokemon(2, "Raichu", Type.TYPES.get(13))); - POKEMONS.put(3, new Pokemon(3, "Machop", Type.TYPES.get(2))); - POKEMONS.put(4, new Pokemon(4, "Snorlax", Type.TYPES.get(1))); - POKEMONS.put(5, new Pokemon(5, "Charizard", Type.TYPES.get(10), Type.TYPES.get(3))); - POKEMONS.put(6, new Pokemon(6, "Meowth", Type.TYPES.get(1))); - POKEMONS.put(7, new Pokemon(7, "Gyarados", Type.TYPES.get(3), Type.TYPES.get(11))); - // update tests - POKEMONS.put(8, new Pokemon(8, "Spearow", Type.TYPES.get(1), Type.TYPES.get(3))); - POKEMONS.put(9, new Pokemon(9, "Fearow", Type.TYPES.get(1), Type.TYPES.get(3))); - POKEMONS.put(10, new Pokemon(10, "Ekans", Type.TYPES.get(4))); - POKEMONS.put(11, new Pokemon(11, "Arbok", Type.TYPES.get(4))); - POKEMONS.put(12, new Pokemon(12, "Sandshrew", Type.TYPES.get(5))); - POKEMONS.put(13, new Pokemon(13, "Sandslash", Type.TYPES.get(5))); - POKEMONS.put(14, new Pokemon(14, "Diglett", Type.TYPES.get(5))); - // delete tests - POKEMONS.put(15, new Pokemon(15, "Rayquaza", Type.TYPES.get(3), Type.TYPES.get(16))); - POKEMONS.put(16, new Pokemon(16, "Lugia", Type.TYPES.get(3), Type.TYPES.get(14))); - POKEMONS.put(17, new Pokemon(17, "Ho-Oh", Type.TYPES.get(3), Type.TYPES.get(10))); - POKEMONS.put(18, new Pokemon(18, "Raikou", Type.TYPES.get(13))); - POKEMONS.put(19, new Pokemon(19, "Giratina", Type.TYPES.get(8), Type.TYPES.get(16))); - POKEMONS.put(20, new Pokemon(20, "Regirock", Type.TYPES.get(6))); - POKEMONS.put(21, new Pokemon(21, "Kyogre", Type.TYPES.get(11))); - // IDs reserved for insert tests are 22 - 28 - // DML update tests - POKEMONS.put(29, new Pokemon(29, "Piplup", Type.TYPES.get(11))); - POKEMONS.put(30, new Pokemon(30, "Prinplup", Type.TYPES.get(11))); - POKEMONS.put(31, new Pokemon(31, "Empoleon", Type.TYPES.get(9), Type.TYPES.get(11))); - POKEMONS.put(32, new Pokemon(32, "Staryu", Type.TYPES.get(11))); - POKEMONS.put(33, new Pokemon(33, "Starmie", Type.TYPES.get(11), Type.TYPES.get(14))); - POKEMONS.put(34, new Pokemon(34, "Horsea", Type.TYPES.get(11))); - POKEMONS.put(35, new Pokemon(35, "Seadra", Type.TYPES.get(11))); - // DML delete tests - POKEMONS.put(36, new Pokemon(36, "Mudkip", Type.TYPES.get(11))); - POKEMONS.put(37, new Pokemon(37, "Marshtomp", Type.TYPES.get(5), Type.TYPES.get(11))); - POKEMONS.put(38, new Pokemon(38, "Swampert", Type.TYPES.get(5), Type.TYPES.get(11))); - POKEMONS.put(39, new Pokemon(39, "Muk", Type.TYPES.get(4))); - POKEMONS.put(40, new Pokemon(40, "Grimer", Type.TYPES.get(4))); - POKEMONS.put(41, new Pokemon(41, "Cubchoo", Type.TYPES.get(15))); - POKEMONS.put(42, new Pokemon(42, "Beartic", Type.TYPES.get(15))); - // IDs reserved for DML insert tests are 43 - 49 - // DML statement IT - POKEMONS.put(50, new Pokemon(50, "Shinx", Type.TYPES.get(13))); - POKEMONS.put(51, new Pokemon(51, "Luxio", Type.TYPES.get(13))); - POKEMONS.put(52, new Pokemon(52, "Luxray", Type.TYPES.get(13))); - POKEMONS.put(53, new Pokemon(53, "Kricketot", Type.TYPES.get(7))); - POKEMONS.put(54, new Pokemon(54, "Kricketune", Type.TYPES.get(7))); - POKEMONS.put(55, new Pokemon(55, "Phione", Type.TYPES.get(11))); - POKEMONS.put(56, new Pokemon(56, "Chatot", Type.TYPES.get(1), Type.TYPES.get(3))); - // update tests in transaction - POKEMONS.put(57, new Pokemon(57, "Teddiursa", Type.TYPES.get(1))); - POKEMONS.put(58, new Pokemon(58, "Ursaring", Type.TYPES.get(1))); - POKEMONS.put(59, new Pokemon(59, "Slugma", Type.TYPES.get(10))); - POKEMONS.put(60, new Pokemon(60, "Magcargo", Type.TYPES.get(6), Type.TYPES.get(10))); - POKEMONS.put(61, new Pokemon(61, "Lotad", Type.TYPES.get(11), Type.TYPES.get(12))); - POKEMONS.put(62, new Pokemon(62, "Lombre", Type.TYPES.get(11), Type.TYPES.get(12))); - POKEMONS.put(63, new Pokemon(63, "Ludicolo", Type.TYPES.get(11), Type.TYPES.get(12))); - // DML update tests in transaction - POKEMONS.put(64, new Pokemon(64, "Natu", Type.TYPES.get(3), Type.TYPES.get(14))); - POKEMONS.put(65, new Pokemon(65, "Xatu", Type.TYPES.get(3), Type.TYPES.get(14))); - POKEMONS.put(66, new Pokemon(66, "Snubbull", Type.TYPES.get(18))); - POKEMONS.put(67, new Pokemon(67, "Granbull", Type.TYPES.get(18))); - POKEMONS.put(68, new Pokemon(68, "Entei", Type.TYPES.get(10))); - POKEMONS.put(69, new Pokemon(69, "Raikou", Type.TYPES.get(13))); - POKEMONS.put(70, new Pokemon(70, "Suicune", Type.TYPES.get(11))); - // delete tests in transaction - POKEMONS.put(71, new Pokemon(71, "Omanyte", Type.TYPES.get(6), Type.TYPES.get(11))); - POKEMONS.put(72, new Pokemon(72, "Omastar", Type.TYPES.get(6), Type.TYPES.get(11))); - POKEMONS.put(73, new Pokemon(73, "Kabuto", Type.TYPES.get(6), Type.TYPES.get(11))); - POKEMONS.put(74, new Pokemon(74, "Kabutops", Type.TYPES.get(6), Type.TYPES.get(11))); - POKEMONS.put(75, new Pokemon(75, "Chikorita", Type.TYPES.get(12))); - POKEMONS.put(76, new Pokemon(76, "Bayleef", Type.TYPES.get(12))); - POKEMONS.put(77, new Pokemon(77, "Meganium", Type.TYPES.get(12))); - // DML delete tests in transaction - POKEMONS.put(78, new Pokemon(78, "Trapinch", Type.TYPES.get(5))); - POKEMONS.put(79, new Pokemon(79, "Vibrava", Type.TYPES.get(5), Type.TYPES.get(16))); - POKEMONS.put(80, new Pokemon(80, "Spoink", Type.TYPES.get(14))); - POKEMONS.put(81, new Pokemon(81, "Grumpig", Type.TYPES.get(14))); - POKEMONS.put(82, new Pokemon(82, "Beldum", Type.TYPES.get(9), Type.TYPES.get(14))); - POKEMONS.put(83, new Pokemon(83, "Metang", Type.TYPES.get(9), Type.TYPES.get(14))); - POKEMONS.put(84, new Pokemon(84, "Metagross", Type.TYPES.get(9), Type.TYPES.get(14))); - // IDs reserved for DML insert tests in transaction are 85 - 98 - // mapping tests - POKEMONS.put(99, new Pokemon(99, "Moltres", Type.TYPES.get(3), Type.TYPES.get(10))); - POKEMONS.put(100, new Pokemon(100, "Masquerain", Type.TYPES.get(3), Type.TYPES.get(7))); - POKEMONS.put(101, new Pokemon(101, "Makuhita", Type.TYPES.get(2))); - POKEMONS.put(102, new Pokemon(102, "Hariyama", Type.TYPES.get(2))); - // IDs reserved for mapping tests with insert are 103 - 104 - } - - public static List typesList(Type... types) { - if (types == null) { - return null; - } - List typesList = new ArrayList<>(types.length); - typesList.addAll(Arrays.asList(types)); - return typesList; - } - - private final int id; - private final String name; - private final List types; - public Pokemon(int id, String name, Type... types) { - this.id = id; - this.name = name; - this.types = new ArrayList<>(types != null ? types.length : 0); - if (types != null) { - this.types.addAll(Arrays.asList(types)); - } - } - - public Pokemon(int id, String name, List types) { - this.id = id; - this.name = name; - this.types = types != null ? types : List.of(); - } - - public int getId() { - return id; - } - - public String getName() { - return name; - } - - public List getTypes() { - return types; - } - - public Type[] getTypesArray() { - return types.toArray(new Type[0]); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("Pokemon: {id="); - sb.append(id); - sb.append(", name="); - sb.append(name); - sb.append(", types=["); - boolean first = true; - for (Type type : types) { - if (first) { - first = false; - } else { - sb.append(", "); - } - sb.append(type.toString()); - } - sb.append("]}"); - return sb.toString(); - } - - public JsonObject toJsonObject() { - JsonObjectBuilder job = Json.createObjectBuilder(); - job.add("id", id); - job.add("name", name); - JsonArrayBuilder typesArray = Json.createArrayBuilder(); - types.forEach(type -> typesArray.add(type.toJsonObject())); - job.add("types", typesArray.build()); - return job.build(); + this(id, name, List.of(types)); } - } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Pokemons.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Pokemons.java new file mode 100644 index 00000000000..218af74d1ff --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Pokemons.java @@ -0,0 +1,405 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common.model; + +import java.util.List; + +/** + * {@code Pokemon} data set. + */ +@SuppressWarnings("SpellCheckingInspection") +public final class Pokemons { + + private Pokemons() { + // cannot be instantiated + } + + /** + * {@code Pikachu}. + */ + public static final Pokemon PIKACHU = new Pokemon(1, "Pikachu", Types.ELECTRIC); + + /** + * {@code Raichu}. + */ + public static final Pokemon RAICHU = new Pokemon(2, "Raichu", Types.ELECTRIC); + + /** + * {@code Machop}. + */ + public static final Pokemon MACHOP = new Pokemon(3, "Machop", Types.FIGHTING); + + /** + * {@code Snorlax}. + */ + public static final Pokemon SNORLAX = new Pokemon(4, "Snorlax", Types.NORMAL); + + /** + * {@code Charizard}. + */ + public static final Pokemon CHARIZARD = new Pokemon(5, "Charizard", Types.FIRE, Types.FLYING); + + /** + * {@code Meowth}. + */ + public static final Pokemon MEOWTH = new Pokemon(6, "Meowth", Types.NORMAL); + + /** + * {@code Gyarados}. + */ + public static final Pokemon GYARADOS = new Pokemon(7, "Gyarados", Types.FLYING, Types.WATER); + + /** + * {@code Spearow}. + */ + public static final Pokemon SPEAROW = new Pokemon(8, "Spearow", Types.NORMAL, Types.FLYING); + + /** + * {@code Fearow}. + */ + public static final Pokemon FEAROW = new Pokemon(9, "Fearow", Types.NORMAL, Types.FLYING); + + /** + * {@code Ekans}. + */ + public static final Pokemon EKANS = new Pokemon(10, "Ekans", Types.POISON); + + /** + * {@code Arbok}. + */ + public static final Pokemon ARBOK = new Pokemon(11, "Arbok", Types.POISON); + + /** + * {@code Sandshrew}. + */ + public static final Pokemon SANDSHREW = new Pokemon(12, "Sandshrew", Types.GROUND); + + /** + * {@code Sandslash}. + */ + public static final Pokemon SANDSLASH = new Pokemon(13, "Sandslash", Types.GROUND); + + /** + * {@code Diglett}. + */ + public static final Pokemon DIGLETT = new Pokemon(14, "Diglett", Types.GROUND); + + /** + * {@code Rayquaza}. + */ + public static final Pokemon RAYQUAZA = new Pokemon(15, "Rayquaza", Types.FLYING, Types.DRAGON); + + /** + * {@code Lugia}. + */ + public static final Pokemon LUGIA = new Pokemon(16, "Lugia", Types.FLYING, Types.PSYCHIC); + + /** + * {@code Ho-Oh}. + */ + public static final Pokemon HOOH = new Pokemon(17, "Ho-Oh", Types.FLYING, Types.FIRE); + + /** + * {@code Raikou}. + */ + public static final Pokemon RAIKOU = new Pokemon(18, "Raikou", Types.ELECTRIC); + + /** + * {@code Giratina}. + */ + public static final Pokemon GIRATINA = new Pokemon(19, "Giratina", Types.GHOST, Types.DRAGON); + + /** + * {@code Regirock}. + */ + public static final Pokemon REGIROCK = new Pokemon(20, "Regirock", Types.ROCK); + + /** + * {@code Kyogre}. + */ + public static final Pokemon KYOGRE = new Pokemon(21, "Kyogre", Types.WATER); + + /** + * {@code Piplup}. + */ + public static final Pokemon PIPLUP = new Pokemon(29, "Piplup", Types.WATER); + + /** + * {@code Prinplup}. + */ + public static final Pokemon PRINPLUP = new Pokemon(30, "Prinplup", Types.WATER); + + /** + * {@code Empoleon}. + */ + public static final Pokemon EMPOLEON = new Pokemon(31, "Empoleon", Types.STEEL, Types.WATER); + + /** + * {@code Staryu}. + */ + public static final Pokemon STARYU = new Pokemon(32, "Staryu", Types.WATER); + + /** + * {@code Starmie}. + */ + public static final Pokemon STARMIE = new Pokemon(33, "Starmie", Types.WATER, Types.PSYCHIC); + + /** + * {@code Horsea}. + */ + public static final Pokemon HORSEA = new Pokemon(34, "Horsea", Types.WATER); + + /** + * {@code Seadra}. + */ + public static final Pokemon SEADRA = new Pokemon(35, "Seadra", Types.WATER); + + /** + * {@code Mudkip}. + */ + public static final Pokemon MUDKIP = new Pokemon(36, "Mudkip", Types.WATER); + + /** + * {@code Marshtomp}. + */ + public static final Pokemon MARSHTOMP = new Pokemon(37, "Marshtomp", Types.GROUND, Types.WATER); + + /** + * {@code Swampert}. + */ + public static final Pokemon SWAMPERT = new Pokemon(38, "Swampert", Types.GROUND, Types.WATER); + + /** + * {@code Muk}. + */ + public static final Pokemon MUK = new Pokemon(39, "Muk", Types.POISON); + + /** + * {@code Grimer}. + */ + public static final Pokemon GRIMER = new Pokemon(40, "Grimer", Types.POISON); + + /** + * {@code Cubchoo}. + */ + public static final Pokemon CUBCHOO = new Pokemon(41, "Cubchoo", Types.ICE); + + /** + * {@code Beartic}. + */ + public static final Pokemon BEARTIC = new Pokemon(42, "Beartic", Types.ICE); + + /** + * {@code Shinx}. + */ + public static final Pokemon SHINX = new Pokemon(50, "Shinx", Types.ELECTRIC); + + /** + * {@code Luxio}. + */ + public static final Pokemon LUXIO = new Pokemon(51, "Luxio", Types.ELECTRIC); + + /** + * {@code Luxray}. + */ + public static final Pokemon LUXRAY = new Pokemon(52, "Luxray", Types.ELECTRIC); + + /** + * {@code Kricketot}. + */ + public static final Pokemon KRICKETOT = new Pokemon(53, "Kricketot", Types.GHOST); + + /** + * {@code Kricketune}. + */ + public static final Pokemon KRICKETUNE = new Pokemon(54, "Kricketune", Types.GHOST); + + /** + * {@code Phione}. + */ + public static final Pokemon PHIONE = new Pokemon(55, "Phione", Types.WATER); + + /** + * {@code Chatot}. + */ + public static final Pokemon CHATOT = new Pokemon(56, "Chatot", Types.NORMAL, Types.FLYING); + + /** + * {@code Teddiursa}. + */ + public static final Pokemon TEDDIURSA = new Pokemon(57, "Teddiursa", Types.NORMAL); + + /** + * {@code Ursaring}. + */ + public static final Pokemon URSARING = new Pokemon(58, "Ursaring", Types.NORMAL); + + /** + * {@code Slugma}. + */ + public static final Pokemon SLUGMA = new Pokemon(59, "Slugma", Types.FIRE); + + /** + * {@code Magcargo}. + */ + public static final Pokemon MAGCARGO = new Pokemon(60, "Magcargo", Types.ROCK, Types.FIRE); + + /** + * {@code Lotad}. + */ + public static final Pokemon LOTAD = new Pokemon(61, "Lotad", Types.WATER, Types.GRASS); + + /** + * {@code Lombre}. + */ + public static final Pokemon LOMBRE = new Pokemon(62, "Lombre", Types.WATER, Types.GRASS); + + /** + * {@code Ludicolo}. + */ + public static final Pokemon LUDICOLO = new Pokemon(63, "Ludicolo", Types.WATER, Types.GRASS); + + /** + * {@code Natu}. + */ + public static final Pokemon NATU = new Pokemon(64, "Natu", Types.FLYING, Types.PSYCHIC); + + /** + * {@code Xatu}. + */ + public static final Pokemon XATU = new Pokemon(65, "Xatu", Types.FLYING, Types.PSYCHIC); + + /** + * {@code Snubbull}. + */ + public static final Pokemon SNUBBULL = new Pokemon(66, "Snubbull", Types.FAIRY); + + /** + * {@code Granbull}. + */ + public static final Pokemon GRANBULL = new Pokemon(67, "Granbull", Types.FAIRY); + + /** + * {@code Entei}. + */ + public static final Pokemon ENTEI = new Pokemon(68, "Entei", Types.FIRE); + + /** + * {@code Suicune}. + */ + public static final Pokemon SUICUNE = new Pokemon(70, "Suicune", Types.WATER); + + /** + * {@code Omanyte}. + */ + public static final Pokemon OMANYTE = new Pokemon(71, "Omanyte", Types.ROCK, Types.WATER); + + /** + * {@code Omastar}. + */ + public static final Pokemon OMASTAR = new Pokemon(72, "Omastar", Types.ROCK, Types.WATER); + + /** + * {@code Kabuto}. + */ + public static final Pokemon KABUTO = new Pokemon(73, "Kabuto", Types.ROCK, Types.WATER); + + /** + * {@code Kabutops}. + */ + public static final Pokemon KABUTOPS = new Pokemon(74, "Kabutops", Types.ROCK, Types.WATER); + + /** + * {@code Chikorita}. + */ + public static final Pokemon CHIKORITA = new Pokemon(75, "Chikorita", Types.GRASS); + + /** + * {@code Bayleef}. + */ + public static final Pokemon BAYLEEF = new Pokemon(76, "Bayleef", Types.GRASS); + + /** + * {@code Meganium}. + */ + public static final Pokemon MEGANIUM = new Pokemon(77, "Meganium", Types.GRASS); + + /** + * {@code Trapinch}. + */ + public static final Pokemon TRAPINCH = new Pokemon(78, "Trapinch", Types.GROUND); + + /** + * {@code Vibrava}. + */ + public static final Pokemon VIBRAVA = new Pokemon(79, "Vibrava", Types.GROUND, Types.DRAGON); + + /** + * {@code Spoink}. + */ + public static final Pokemon SPOINK = new Pokemon(80, "Spoink", Types.PSYCHIC); + + /** + * {@code Grumpig}. + */ + public static final Pokemon GRUMPIG = new Pokemon(81, "Grumpig", Types.PSYCHIC); + + /** + * {@code Beldum}. + */ + public static final Pokemon BELDUM = new Pokemon(82, "Beldum", Types.STEEL, Types.PSYCHIC); + + /** + * {@code Metang}. + */ + public static final Pokemon METANG = new Pokemon(83, "Metang", Types.STEEL, Types.PSYCHIC); + + /** + * {@code Metagross}. + */ + public static final Pokemon METAGROSS = new Pokemon(84, "Metagross", Types.STEEL, Types.PSYCHIC); + + /** + * {@code Moltres}. + */ + public static final Pokemon MOLTRES = new Pokemon(99, "Moltres", Types.FLYING, Types.FIRE); + + /** + * {@code Masquerain}. + */ + public static final Pokemon MASQUERAIN = new Pokemon(100, "Masquerain", Types.FLYING, Types.GHOST); + + /** + * {@code Makuhita}. + */ + public static final Pokemon MAKUHITA = new Pokemon(101, "Makuhita", Types.FIGHTING); + + /** + * {@code Hariyama}. + */ + public static final Pokemon HARIYAMA = new Pokemon(102, "Hariyama", Types.FIGHTING); + + /** + * All {@code pokemons}. + */ + public static final List ALL = List.of( + PIKACHU, RAICHU, MACHOP, SNORLAX, CHARIZARD, MEOWTH, GYARADOS, SPEAROW, FEAROW, EKANS, ARBOK, SANDSHREW, SANDSLASH, + DIGLETT, RAYQUAZA, LUGIA, HOOH, RAIKOU, GIRATINA, REGIROCK, KYOGRE, PIPLUP, PRINPLUP, EMPOLEON, STARYU, STARMIE, + HORSEA, SEADRA, MUDKIP, MARSHTOMP, SWAMPERT, MUK, GRIMER, CUBCHOO, BEARTIC, SHINX, LUXIO, LUXRAY, KRICKETOT, + KRICKETUNE, PHIONE, CHATOT, TEDDIURSA, URSARING, SLUGMA, MAGCARGO, LOTAD, LOMBRE, LUDICOLO, NATU, XATU, SNUBBULL, + GRANBULL, ENTEI, SUICUNE, OMANYTE, OMASTAR, KABUTO, KABUTOPS, CHIKORITA, BAYLEEF, MEGANIUM, TRAPINCH, VIBRAVA, + SPOINK, GRUMPIG, BELDUM, METANG, METAGROSS, MOLTRES, MASQUERAIN, MAKUHITA, HARIYAMA); +} diff --git a/tests/integration/harness/src/main/java/module-info.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Range.java similarity index 53% rename from tests/integration/harness/src/main/java/module-info.java rename to tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Range.java index 298fa495e84..10cb03e1970 100644 --- a/tests/integration/harness/src/main/java/module-info.java +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Range.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,23 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package io.helidon.tests.integration.dbclient.common.model; /** - * Helidon Tests Integration Harness. + * Range. + * + * @param idMin beginning of range. + * @param idMax end of range. */ -module io.helidon.tests.integration.harness { - - requires jakarta.json; - - requires org.junit.platform.suite.api; - requires org.junit.jupiter.api; - requires org.junit.platform.engine; - requires org.junit.platform.launcher; - - requires io.helidon.common.media.type; - requires io.helidon.http.media.jsonp; - requires io.helidon.webclient.http1; - - exports io.helidon.tests.integration.harness; - +public record Range(int idMin, int idMax) { } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/RangePoJo.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/RangePoJo.java deleted file mode 100644 index 74d98b15dad..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/RangePoJo.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.model; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import io.helidon.dbclient.DbMapper; -import io.helidon.dbclient.DbRow; - -/** - * POJO used to define {@code Pokemon} IDs range in query statement tests. - * - * @param idMin Beginning of IDs range. - * @param idMax End of IDs range. - */ -public record RangePoJo(int idMin, int idMax) { - - public static final class Mapper implements DbMapper { - - public static final Mapper INSTANCE = new Mapper(); - - @Override - public RangePoJo read(DbRow row) { - throw new UnsupportedOperationException("Read operation is not implemented."); - } - - @Override - public Map toNamedParameters(RangePoJo value) { - Map params = new HashMap<>(2); - params.put("idmin", value.idMin()); - params.put("idmax", value.idMax()); - return params; - } - - @Override - public List toIndexedParameters(RangePoJo value) { - List params = new ArrayList<>(2); - params.add(value.idMin()); - params.add(value.idMax()); - return params; - } - - } - - /** - * Creates an instance of Range POJO. - * - * @param idMin beginning of IDs range - * @param idMax end of IDs range - */ - public RangePoJo { - } - - /** - * Get beginning of IDs range. - * - * @return beginning of IDs range - */ - @Override - public int idMin() { - return idMin; - } - - /** - * Get end of IDs range. - * - * @return end of IDs range - */ - @Override - public int idMax() { - return idMax; - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Type.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Type.java index 45b938455c1..066aabf4cc5 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Type.java +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Type.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,53 +15,11 @@ */ package io.helidon.tests.integration.dbclient.common.model; -import java.util.HashMap; -import java.util.Map; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; - /** - * {@code Pokemon} type POJO. + * {@code Pokemon}. + * + * @param id id + * @param name name */ public record Type(int id, String name) { - - /** - * Map of {@code Pokemon} types by ID. - */ - public static final Map TYPES = new HashMap<>(); - - static { - TYPES.put(1, new Type(1, "Normal")); - TYPES.put(2, new Type(2, "Fighting")); - TYPES.put(3, new Type(3, "Flying")); - TYPES.put(4, new Type(4, "Poison")); - TYPES.put(5, new Type(5, "Ground")); - TYPES.put(6, new Type(6, "Rock")); - TYPES.put(7, new Type(7, "Bug")); - TYPES.put(8, new Type(8, "Ghost")); - TYPES.put(9, new Type(9, "Steel")); - TYPES.put(10, new Type(10, "Fire")); - TYPES.put(11, new Type(11, "Water")); - TYPES.put(12, new Type(12, "Grass")); - TYPES.put(13, new Type(13, "Electric")); - TYPES.put(14, new Type(14, "Psychic")); - TYPES.put(15, new Type(15, "Ice")); - TYPES.put(16, new Type(16, "Dragon")); - TYPES.put(17, new Type(17, "Dark")); - TYPES.put(18, new Type(18, "Fairy")); - } - - @Override - public String toString() { - return "Type: {id=" + id + ", name=" + name + "}"; - } - - public JsonObject toJsonObject() { - final JsonObjectBuilder job = Json.createObjectBuilder(); - job.add("id", id); - job.add("name", name); - return job.build(); - } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Types.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Types.java new file mode 100644 index 00000000000..3fa6415703a --- /dev/null +++ b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Types.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.common.model; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * {@code type} data set. + */ +public final class Types { + + private Types() { + // cannot be instantiated + } + + /** + * Map of {@code Pokemon} types by ID. + */ + public static final Map TYPES = new HashMap<>(); + + /** + * {@code Normal}. + */ + public static final Type NORMAL = new Type(1, "Normal"); + + /** + * {@code Fighting}. + */ + public static final Type FIGHTING = new Type(2, "Fighting"); + + /** + * {@code Flying}. + */ + public static final Type FLYING = new Type(3, "Flying"); + + /** + * {@code Poison}. + */ + public static final Type POISON = new Type(4, "Poison"); + + /** + * {@code Ground}. + */ + public static final Type GROUND = new Type(5, "Ground"); + + /** + * {@code Rock}. + */ + public static final Type ROCK = new Type(6, "Rock"); + + /** + * {@code Bug}. + */ + public static final Type BUG = new Type(7, "Bug"); + + /** + * {@code Ghost}. + */ + public static final Type GHOST = new Type(8, "Ghost"); + + /** + * {@code Steel}. + */ + public static final Type STEEL = new Type(9, "Steel"); + + /** + * {@code Fire}. + */ + public static final Type FIRE = new Type(10, "Fire"); + + /** + * {@code Water}. + */ + public static final Type WATER = new Type(11, "Water"); + + /** + * {@code Grass}. + */ + public static final Type GRASS = new Type(12, "Grass"); + + /** + * {@code Electric}. + */ + public static final Type ELECTRIC = new Type(13, "Electric"); + + /** + * {@code Psychic}. + */ + public static final Type PSYCHIC = new Type(14, "Psychic"); + + /** + * {@code Ice}. + */ + public static final Type ICE = new Type(15, "Ice"); + + /** + * {@code Dragon}. + */ + public static final Type DRAGON = new Type(16, "Dragon"); + + /** + * {@code Dark}. + */ + public static final Type DARK = new Type(17, "Dark"); + + /** + * {@code Fairy}. + */ + public static final Type FAIRY = new Type(18, "Fairy"); + + /** + * All types. + */ + public static final List ALL = List.of(NORMAL, FIGHTING, FLYING, POISON, GROUND, ROCK, BUG, GHOST, STEEL, FIRE, WATER, + GRASS, ELECTRIC, PSYCHIC, ICE, DRAGON, DARK, FAIRY); + + static { + Types.TYPES.put(1, Types.NORMAL); + Types.TYPES.put(2, Types.FIGHTING); + Types.TYPES.put(3, Types.FLYING); + Types.TYPES.put(4, Types.POISON); + Types.TYPES.put(5, Types.GROUND); + Types.TYPES.put(6, Types.ROCK); + Types.TYPES.put(7, Types.BUG); + Types.TYPES.put(8, Types.GHOST); + Types.TYPES.put(9, Types.STEEL); + Types.TYPES.put(10, Types.FIRE); + Types.TYPES.put(11, Types.WATER); + Types.TYPES.put(12, Types.GRASS); + Types.TYPES.put(13, Types.ELECTRIC); + Types.TYPES.put(14, Types.PSYCHIC); + Types.TYPES.put(15, Types.ICE); + Types.TYPES.put(16, Types.DRAGON); + Types.TYPES.put(17, Types.DARK); + Types.TYPES.put(18, Types.FAIRY); + } +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/DbClientParameterResolver.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/DbClientParameterResolver.java deleted file mode 100644 index 59004a87b0d..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/DbClientParameterResolver.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.util.List; -import java.util.ServiceLoader; - -import io.helidon.common.HelidonServiceLoader; -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.tests.integration.dbclient.common.spi.SetupProvider; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.ParameterContext; -import org.junit.jupiter.api.extension.ParameterResolutionException; -import org.junit.jupiter.api.extension.ParameterResolver; - -public class DbClientParameterResolver implements ParameterResolver { - - private static final SetupProvider SETUP_PROVIDER = initSetupProvider(); - - private static SetupProvider initSetupProvider() { - ServiceLoader loader = ServiceLoader.load(SetupProvider.class); - List providers = HelidonServiceLoader - .builder(loader) - .build() - .asList(); - switch (providers.size()) { - case 0: throw new IllegalStateException("No SetupProvider instance found on the classpath"); - case 1: return providers.getFirst(); - default: throw new IllegalStateException("Multiple SetupProvider instances found on the classpath"); - } - } - - @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - throws ParameterResolutionException { - Class type = parameterContext.getParameter().getType(); - if (DbClient.class.isAssignableFrom(type)) { - return true; - } - if (Config.class.isAssignableFrom(type)) { - return true; - } - return false; - } - - @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - throws ParameterResolutionException { - Class type = parameterContext.getParameter().getType(); - if (DbClient.class.isAssignableFrom(type)) { - return SETUP_PROVIDER.dbClient(); - } - if (Config.class.isAssignableFrom(type)) { - return SETUP_PROVIDER.config(); - } - return null; - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ExceptionalStmtIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ExceptionalStmtIT.java deleted file mode 100644 index dfc5ac3ddd6..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ExceptionalStmtIT.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbClientException; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; -import static org.junit.jupiter.api.Assertions.fail; - -/** - * Test exceptional states. - */ -@ExtendWith(DbClientParameterResolver.class) -class ExceptionalStmtIT { - - private static final System.Logger LOGGER = System.getLogger(ExceptionalStmtIT.class.getName()); - - private final DbClient dbClient; - - ExceptionalStmtIT(DbClient dbClient) { - this.dbClient = dbClient; - } - - /** - * Verify that execution of query with non-existing named statement throws an exception. - */ - @Test - void testCreateNamedQueryNonExistentStmt() { - try { - dbClient.execute() - .createNamedQuery("select-pokemons-not-exists") - .execute() - .forEach(it -> {}); - fail("Execution of non existing statement shall cause an exception to be thrown."); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format("Expected exception: %s", ex.getMessage()), ex); - } - } - - /** - * Verify that execution of query with both named and ordered arguments throws an exception. - */ - @Test - void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { - try { - dbClient.execute() - .createNamedQuery("select-pokemons-error-arg") - .execute() - .forEach(it -> {}); - fail("Execution of query with both named and ordered parameters without passing any shall fail."); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format("Expected exception: %s", ex.getMessage()), ex); - } - } - - /** - * Verify that execution of query with both named and ordered arguments throws an exception. - */ - @Test - void testCreateNamedQueryNamedAndOrderArgsWithArgs() { - try { - dbClient.execute() - .createNamedQuery("select-pokemons-error-arg") - .addParam("id", POKEMONS.get(5).getId()) - .addParam(POKEMONS.get(5).getName()) - .execute() - .forEach(it -> {}); - fail("Execution of query with both named and ordered parameters without passing them shall fail."); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format("Expected exception: %s", ex.getMessage()), ex); - } - } - - /** - * Verify that execution of query with named arguments throws an exception while trying to set ordered argument. - */ - @Test - void testCreateNamedQueryNamedArgsSetOrderArg() { - try { - dbClient.execute() - .createNamedQuery("select-pokemon-named-arg") - .addParam(POKEMONS.get(5).getName()) - .execute() - .forEach(it -> {}); - fail("Execution of query with named parameter with passing ordered parameter value shall fail."); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format("Expected exception: %s", ex.getMessage()), ex); - } - } - - /** - * Verify that execution of query with ordered arguments throws an exception while trying to set named argument. - */ - @Test - void testCreateNamedQueryOrderArgsSetNamedArg() { - try { - dbClient.execute() - .createNamedQuery("select-pokemon-order-arg") - .addParam("name", POKEMONS.get(6).getName()) - .execute() - .forEach(it -> {}); - fail("Execution of query with ordered parameter with passing named parameter value shall fail."); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format("Expected exception: %s", ex.getMessage()), ex); - } - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/FlowControlIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/FlowControlIT.java deleted file mode 100644 index 06e18eb0f4e..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/FlowControlIT.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; -import java.util.List; -import java.util.stream.Stream; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.model.Type; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; - -/** - * Verify proper flow control handling in query processing. - */ -@ExtendWith(DbClientParameterResolver.class) -public class FlowControlIT { - - private static final System.Logger LOGGER = System.getLogger(FlowControlIT.class.getName()); - - private final DbClient dbClient; - - FlowControlIT(DbClient dbClient) { - this.dbClient = dbClient; - } - - /** - * Source data verification. - */ - @Test - public void testSourceData() { - Stream rows = dbClient.execute() - .namedQuery("select-types"); - assertThat(rows, notNullValue()); - List list = rows.toList(); - assertThat(list, not(empty())); - assertThat(list.size(), equalTo(18)); - for (DbRow row : list) { - Integer id = row.column(1).get(Integer.class); - String name = row.column(2).get(String.class); - Type type = new Type(id, name); - assertThat(name, TYPES.get(id).name().equals(name)); - LOGGER.log(Level.DEBUG, () -> String.format("Type: %s", type)); - } - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/GetStatementIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/GetStatementIT.java deleted file mode 100644 index 0d4a7bc24a2..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/GetStatementIT.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.utils.RangePoJo; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyPokemonsIdRange; - -/** - * Test DbStatementGet methods. - */ -@ExtendWith(DbClientParameterResolver.class) -public class GetStatementIT { - - private final DbClient dbClient; - - GetStatementIT(DbClient dbClient) { - this.dbClient = dbClient; - } - - /** - * Verify {@code params(Object... parameters)} parameters setting method. - */ - @Test - public void testGetArrayParams() { - Optional maybeRow = dbClient.execute() - .createNamedGet("select-pokemons-idrng-order-arg") - .params(1, 3) - .execute(); - verifyPokemonsIdRange(maybeRow, 1, 3); - } - - /** - * Verify {@code params(List)} parameters setting method. - */ - @Test - public void testGetListParams() { - List params = new ArrayList<>(2); - params.add(2); - params.add(4); - Optional maybeRow = dbClient.execute() - .createNamedGet("select-pokemons-idrng-order-arg") - .params(params) - .execute(); - - verifyPokemonsIdRange(maybeRow, 2, 4); - } - - /** - * Verify {@code params(Map)} parameters setting method. - */ - @Test - public void testGetMapParams() { - Map params = new HashMap<>(2); - params.put("idmin", 3); - params.put("idmax", 5); - Optional maybeRow = dbClient.execute() - .createNamedGet("select-pokemons-idrng-named-arg") - .params(params) - .execute(); - - verifyPokemonsIdRange(maybeRow, 3, 5); - } - - /** - * Verify {@code addParam(Object parameter)} parameters setting method. - */ - @Test - public void testGetOrderParam() { - Optional maybeRow = dbClient.execute() - .createNamedGet("select-pokemons-idrng-order-arg") - .addParam(4) - .addParam(6) - .execute(); - verifyPokemonsIdRange(maybeRow, 4, 6); - } - - /** - * Verify {@code addParam(String name, Object parameter)} parameters setting method. - */ - @Test - public void testGetNamedParam() { - Optional maybeRow = dbClient.execute() - .createNamedGet("select-pokemons-idrng-named-arg") - .addParam("idmin", 5) - .addParam("idmax", 7) - .execute(); - verifyPokemonsIdRange(maybeRow, 5, 7); - } - - /** - * Verify {@code namedParam(Object parameters)} mapped parameters setting method. - */ - @Test - public void testGetMappedNamedParam() { - RangePoJo range = new RangePoJo(0, 2); - Optional maybeRow = dbClient.execute() - .createNamedGet("select-pokemons-idrng-named-arg") - .namedParam(range) - .execute(); - verifyPokemonsIdRange(maybeRow, 0, 2); - } - - /** - * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. - */ - @Test - public void testGetMappedOrderParam() { - RangePoJo range = new RangePoJo(6, 8); - Optional maybeRow = dbClient.execute() - .createNamedGet("select-pokemons-idrng-order-arg") - .indexedParam(range) - .execute(); - verifyPokemonsIdRange(maybeRow, 6, 8); - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/HealthCheckIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/HealthCheckIT.java deleted file mode 100644 index a3fc9eea2ca..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/HealthCheckIT.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.health.DbClientHealthCheck; -import io.helidon.health.HealthCheck; -import io.helidon.health.HealthCheckResponse; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Verify that health check works. - */ -@ExtendWith(DbClientParameterResolver.class) -public class HealthCheckIT { - - private static final System.Logger LOGGER = System.getLogger(HealthCheckIT.class.getName()); - - private final DbClient dbClient; - private final Config config; - private final boolean pingDml; - - HealthCheckIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - Config cfgPingDml = config.get("test.ping-dml"); - this.pingDml = cfgPingDml.exists() ? cfgPingDml.asBoolean().get() : true; - } - - /** - * Verify health check implementation with default settings. - */ - @Test - public void testHealthCheck() { - HealthCheck check = DbClientHealthCheck.create(dbClient, config.get("db.health-check")); - HealthCheckResponse response = check.call(); - HealthCheckResponse.Status state = response.status(); - assertThat("Health check failed, response: " + response.details(), state, equalTo(HealthCheckResponse.Status.UP)); - } - - /** - * Verify health check implementation with builder and custom name. - */ - @Test - public void testHealthCheckWithName() { - String hcName = "TestHC"; - HealthCheck check = DbClientHealthCheck.builder(dbClient).config(config.get("db.health-check")).name(hcName).build(); - HealthCheckResponse response = check.call(); - String name = check.name(); - HealthCheckResponse.Status state = response.status(); - assertThat(name, equalTo(hcName)); - assertThat(state, equalTo(HealthCheckResponse.Status.UP)); - } - - /** - * Verify health check implementation using custom DML named statement. - */ - @Test - public void testHealthCheckWithCustomNamedDML() { - if (!pingDml) { - LOGGER.log(Level.DEBUG, () -> String.format("Database %s does not support DML ping, skipping this test", dbClient.dbType())); - return; - } - HealthCheck check = DbClientHealthCheck.builder(dbClient).dml().statementName("ping-dml").build(); - HealthCheckResponse response = check.call(); - HealthCheckResponse.Status state = response.status(); - assertThat("Health check failed, response: " + response.details(), state, equalTo(HealthCheckResponse.Status.UP)); - } - - /** - * Verify health check implementation using custom DML statement. - */ - @Test - public void testHealthCheckWithCustomDML() { - if (!pingDml) { - LOGGER.log(Level.DEBUG, () -> String.format("Database %s does not support DML ping, skipping this test", dbClient.dbType())); - return; - } - Config cfgStatement = config.get("db.statements.ping-dml"); - assertThat("Missing ping-dml statement in database configuration!", cfgStatement.exists(), equalTo(true)); - String statement = cfgStatement.asString().get(); - assertThat("Missing ping-dml statement String in database configuration!", statement, is(notNullValue())); - LOGGER.log(Level.DEBUG, () -> String.format("Using db.statements.ping-dml value %s", statement)); - HealthCheck check = DbClientHealthCheck.builder(dbClient).dml().statement(statement).build(); - HealthCheckResponse response = check.call(); - HealthCheckResponse.Status state = response.status(); - assertThat("Health check failed, response: " + response.details(), state, equalTo(HealthCheckResponse.Status.UP)); - } - - /** - * Verify health check implementation using custom query named statement. - */ - @Test - public void testHealthCheckWithCustomNamedQuery() { - HealthCheck check = DbClientHealthCheck.builder(dbClient).query().statementName("ping-query").build(); - HealthCheckResponse response = check.call(); - HealthCheckResponse.Status state = response.status(); - assertThat("Health check failed, response: " + response.details(), state, equalTo(HealthCheckResponse.Status.UP)); - } - - /** - * Verify health check implementation using custom query statement. - */ - @Test - public void testHealthCheckWithCustomQuery() { - Config cfgStatement = config.get("db.statements.ping-query"); - assertThat("Missing ping-query statement in database configuration!", cfgStatement.exists(), equalTo(true)); - String statement = cfgStatement.asString().get(); - assertThat("Missing ping-query statement String in database configuration!", statement, is(notNullValue())); - LOGGER.log(Level.DEBUG, () -> String.format("Using db.statements.ping-query value %s", statement)); - HealthCheck check = DbClientHealthCheck.builder(dbClient).query().statement(statement).build(); - HealthCheckResponse response = check.call(); - HealthCheckResponse.Status state = response.status(); - assertThat("Health check failed, response: " + response.details(), state, equalTo(HealthCheckResponse.Status.UP)); - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/InterceptorIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/InterceptorIT.java deleted file mode 100644 index 00fa855a673..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/InterceptorIT.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbClientService; -import io.helidon.dbclient.DbClientServiceContext; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Verify services handling. - */ -@ExtendWith(DbClientParameterResolver.class) -public class InterceptorIT { - - private final Config config; - - public InterceptorIT(Config config) { - this.config = config; - } - - private static final class TestClientService implements DbClientService { - - private boolean called; - - private TestClientService() { - this.called = false; - } - - @Override - public DbClientServiceContext statement(DbClientServiceContext context) { - this.called = true; - return context; - } - - private boolean called() { - return called; - } - - } - - /** - * Check that statement interceptor was called before statement execution. - */ - @Test - public void testStatementInterceptor() { - TestClientService interceptor = new TestClientService(); - DbClient dbClient = DbClient.builder(config.get("db")).addService(interceptor).build(); - dbClient.execute() - .createNamedQuery("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(6).getName()) - .execute(); - assertThat(interceptor.called(), equalTo(true)); - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/MapperIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/MapperIT.java deleted file mode 100644 index e3c73e6ed39..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/MapperIT.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; -import java.util.Optional; -import java.util.concurrent.ExecutionException; -import java.util.stream.Stream; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbExecute; -import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyInsertPokemon; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyPokemon; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyUpdatePokemon; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * Verify mapping interface. - */ -@SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class MapperIT { - - private static final System.Logger LOGGER = System.getLogger(MapperIT.class.getName()); - private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 400; - - private final DbClient dbClient; - - MapperIT(DbClient dbClient) { - this.dbClient = dbClient; - } - - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { - POKEMONS.put(pokemon.getId(), pokemon); - long result = dbClient.execute() - .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - - @BeforeAll - public static void setup(DbClient dbClient) throws ExecutionException, InterruptedException { - try { - // BASE_ID+1, 2 is used for inserts - int curId = BASE_ID + 2; - addPokemon(dbClient, new Pokemon(++curId, "Moltres", TYPES.get(3), TYPES.get(10))); // BASE_ID+3 - addPokemon(dbClient, new Pokemon(++curId, "Masquerain", TYPES.get(3), TYPES.get(7))); // BASE_ID+4 - addPokemon(dbClient, new Pokemon(++curId, "Makuhita", TYPES.get(2))); // BASE_ID+5 - addPokemon(dbClient, new Pokemon(++curId, "Hariyama", TYPES.get(2))); // BASE_ID+6 - } catch (Exception ex) { - LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex.getMessage()), ex); - throw ex; - } - } - - /** - * Verify insertion of using indexed mapping. - */ - @Test - public void testInsertWithOrderMapping() { - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Articuno", TYPES.get(3), TYPES.get(15)); - long result = dbClient.execute() - .createNamedInsert("insert-pokemon-order-arg-rev") - .indexedParam(pokemon) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify insertion of using named mapping. - */ - @Test - public void testInsertWithNamedMapping() { - Pokemon pokemon = new Pokemon(BASE_ID + 2, "Zapdos", TYPES.get(3), TYPES.get(13)); - long result = dbClient.execute() - .createNamedInsert("insert-pokemon-named-arg") - .namedParam(pokemon) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify update of using indexed mapping. - */ - @Test - public void testUpdateWithOrderMapping() { - Pokemon pokemon = new Pokemon(BASE_ID + 3, "Masquerain", TYPES.get(3), TYPES.get(15)); - long result = dbClient.execute() - .createNamedUpdate("update-pokemon-order-arg") - .indexedParam(pokemon) - .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); - } - - /** - * Verify update of using named mapping. - */ - @Test - public void testUpdateWithNamedMapping() { - Pokemon pokemon = new Pokemon(BASE_ID + 4, "Moltres", TYPES.get(3), TYPES.get(13)); - long result = dbClient.execute() - .createNamedUpdate("update-pokemon-named-arg") - .namedParam(pokemon) - .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); - } - - /** - * Verify delete of using indexed mapping. - */ - @Test - public void testDeleteWithOrderMapping() { - DbExecute exec = dbClient.execute(); - Pokemon pokemon = POKEMONS.get(BASE_ID + 5); - - long result = exec.createNamedDelete("delete-pokemon-full-order-arg") - .indexedParam(pokemon) - .execute(); - - assertThat(result, equalTo(1L)); - Optional maybeRow = exec - .namedGet("select-pokemon-by-id", pokemon.getId()); - assertThat(maybeRow.isPresent(), equalTo(false)); - } - - /** - * Verify delete of using named mapping. - */ - @Test - public void testDeleteWithNamedMapping() { - DbExecute exec = dbClient.execute(); - Pokemon pokemon = POKEMONS.get(BASE_ID + 6); - - long result = exec.createNamedDelete("delete-pokemon-full-named-arg") - .namedParam(pokemon) - .execute(); - - assertThat(result, equalTo(1L)); - Optional maybeRow = exec - .namedGet("select-pokemon-by-id", pokemon.getId()); - assertThat(maybeRow.isPresent(), equalTo(false)); - } - - /** - * Verify query of as a result using mapping. - */ - @Test - public void testQueryWithMapping() { - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(2).getName()) - .execute(); - - Pokemon pokemon = rows.map(it -> it.as(Pokemon.class)).toList().get(0); - verifyPokemon(pokemon, POKEMONS.get(2)); - } - - /** - * Verify get of as a result using mapping. - */ - @Test - public void testGetWithMapping() { - Optional maybeRow = dbClient.execute() - .createNamedGet("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(3).getName()) - .execute(); - - assertThat(maybeRow.isPresent(), equalTo(true)); - Pokemon pokemon = maybeRow.get().as(Pokemon.class); - verifyPokemon(pokemon, POKEMONS.get(3)); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/QueryStatementIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/QueryStatementIT.java deleted file mode 100644 index b23948b881e..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/QueryStatementIT.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2019, 2024 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.utils.RangePoJo; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyPokemonsIdRange; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.notNullValue; - -/** - * Test DbStatementQuery methods. - */ -@ExtendWith(DbClientParameterResolver.class) -public class QueryStatementIT { - - private final DbClient dbClient; - - QueryStatementIT(DbClient dbClient) { - this.dbClient = dbClient; - } - - /** - * Verify {@code params(Object... parameters)} parameters setting method. - */ - @Test - public void testQueryArrayParams() { - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemons-idrng-order-arg") - .params(1, 7) - .execute(); - - verifyPokemonsIdRange(rows, 1, 7); - } - - /** - * Verify {@code params(List)} parameters setting method. - */ - @Test - public void testQueryListParams() { - List params = new ArrayList<>(2); - params.add(1); - params.add(7); - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemons-idrng-order-arg") - .params(params) - .execute(); - - verifyPokemonsIdRange(rows, 1, 7); - } - - /** - * Verify {@code params(Map)} parameters setting method. - */ - @Test - public void testQueryMapParams() { - Map params = new HashMap<>(2); - params.put("idmin", 1); - params.put("idmax", 7); - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemons-idrng-named-arg") - .params(params) - .execute(); - - verifyPokemonsIdRange(rows, 1, 7); - } - - @Test - public void testQueryMapMissingParams() { - Map params = new HashMap<>(2); - params.put("id", 1); - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemons-idname-named-arg") - .params(params) - .execute(); - assertThat(rows, notNullValue()); - List rowsList = rows.toList(); - assertThat(rowsList, hasSize(0)); - } - - /** - * Verify {@code addParam(Object parameter)} parameters setting method. - */ - @Test - public void testQueryOrderParam() { - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemons-idrng-order-arg") - .addParam(1) - .addParam(7) - .execute(); - - verifyPokemonsIdRange(rows, 1, 7); - } - - /** - * Verify {@code addParam(String name, Object parameter)} parameters setting method. - */ - @Test - public void testQueryNamedParam() { - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemons-idrng-named-arg") - .addParam("idmin", 1) - .addParam("idmax", 7) - .execute(); - - verifyPokemonsIdRange(rows, 1, 7); - } - - /** - * Verify {@code namedParam(Object parameters)} mapped parameters setting method. - */ - @Test - public void testQueryMappedNamedParam() { - RangePoJo range = new RangePoJo(1, 7); - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemons-idrng-named-arg") - .namedParam(range) - .execute(); - - verifyPokemonsIdRange(rows, 1, 7); - } - - /** - * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. - */ - @Test - public void testQueryMappedOrderParam() { - RangePoJo range = new RangePoJo(1, 7); - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemons-idrng-order-arg") - .indexedParam(range) - .execute(); - - verifyPokemonsIdRange(rows, 1, 7); - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ServerHealthCheckIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ServerHealthCheckIT.java deleted file mode 100644 index 5a4d10cd63e..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ServerHealthCheckIT.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.io.IOException; -import java.io.StringReader; -import java.lang.System.Logger.Level; -import java.net.URI; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.health.DbClientHealthCheck; -import io.helidon.http.Status; -import io.helidon.webserver.WebServer; -import io.helidon.webserver.WebServerConfig; -import io.helidon.webserver.observe.ObserveFeature; -import io.helidon.webserver.observe.health.HealthObserver; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonReader; -import jakarta.json.JsonStructure; -import jakarta.json.stream.JsonParsingException; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.junit.jupiter.api.Assertions.fail; - -/** - * Verify health check in web server environment. - */ -@ExtendWith(DbClientParameterResolver.class) -public class ServerHealthCheckIT { - - private static final System.Logger LOGGER = System.getLogger(ServerHealthCheckIT.class.getName()); - - private static WebServer SERVER; - private static String URL; - private final DbClient dbClient; - - public ServerHealthCheckIT(DbClient dbClient) { - this.dbClient = dbClient; - } - - @BeforeAll - public static void setup(DbClient dbClient, Config config) { - SERVER = WebServer.builder() - .update(builder -> routing(dbClient, config, builder)) - .config(config.get("server")) - .build() - .start(); - URL = "http://localhost:" + SERVER.port(); - LOGGER.log(Level.TRACE, () -> "WEB server is running at " + URL); - } - - // Add 2 endpoints: - // - HealthCheck /noDetails/health with details turned off - // - HealthCheck /details/health with details turned on - private static void routing(DbClient dbClient, Config config, WebServerConfig.Builder router) { - router.addFeature( - createObserveFeature(dbClient, config, "healthNoDetails", "noDetails", false)); - router.addFeature( - createObserveFeature(dbClient, config, "healthDetails", "details", true)); - } - - private static ObserveFeature createObserveFeature(DbClient dbClient, Config config, String name, String endpoint, boolean details) { - return ObserveFeature.builder() - .observersDiscoverServices(false) - .endpoint(endpoint) - .name(name) - .addObserver(HealthObserver.builder() - .addCheck(DbClientHealthCheck.builder(dbClient) - .config(config.get("db.health-check")) - .name(name) - .build()) - .details(details) - .build()) - .build(); - } - - @AfterAll - public static void shutdown() { - SERVER.stop(); - LOGGER.log(Level.TRACE, () -> "WEB server stopped"); - } - - /** - * Retrieve server health status from Helidon Web Server. - * - * @param url server health status URL - * @return server health status response (JSON) - * @throws IOException if an I/O error occurs when sending or receiving HTTP request - * @throws InterruptedException if the current thread was interrupted - */ - private static HttpResponse get(String url) throws IOException, InterruptedException { - HttpResponse response; - try (HttpClient client = HttpClient.newHttpClient()) { - HttpRequest request = HttpRequest.newBuilder() - .uri(URI.create(url)) - .header("Accept", "application/json") - .build(); - response = client.send(request, HttpResponse.BodyHandlers.ofString()); - } - return response; - } - - /** - * Read and check Database 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 - void testHttpHealthNoDetails() throws IOException, InterruptedException { - // Call select-pokemons to warm up server - dbClient.execute().namedQuery("select-pokemons").forEach(it -> {}); - String url = URL + "/noDetails/health"; - // Read and process health check response - HttpResponse response = get(url); - LOGGER.log(Level.TRACE, () -> String.format("%s RESPONSE: %d", response.statusCode())); - assertThat(response.statusCode(), equalTo(Status.NO_CONTENT_204.code())); - } - - /** - * Read and check Database 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 - void testHttpHealthDetails() throws IOException, InterruptedException { - // Call select-pokemons to warm up server - dbClient.execute().namedQuery("select-pokemons").forEach(it -> {}); - String url = URL + "/details/health"; - // Read and process health check response - HttpResponse response = get(url); - assertThat(response.statusCode(), equalTo(Status.OK_200.code())); - String jsonSrc = response.body(); - LOGGER.log(Level.TRACE, () -> String.format("%s RESPONSE: %s", url, jsonSrc)); - JsonStructure jsonResponse = null; - try (JsonReader jr = Json.createReader(new StringReader(jsonSrc))) { - 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.forEach((check) -> { - String status = check.asJsonObject().getString("status"); - assertThat(status, equalTo("UP")); - }); - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ServerMetricsCheckIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ServerMetricsCheckIT.java deleted file mode 100644 index ea0bc2a2e62..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ServerMetricsCheckIT.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.io.IOException; -import java.io.StringReader; -import java.lang.System.Logger.Level; -import java.net.URI; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; - -import io.helidon.common.config.GlobalConfig; -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbStatementType; -import io.helidon.dbclient.metrics.DbClientMetrics; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; -import io.helidon.webserver.WebServer; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import jakarta.json.JsonReader; -import jakarta.json.JsonValue; -import jakarta.json.stream.JsonParsingException; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.jupiter.api.Assertions.fail; - -/** - * Verify metrics check in web server environment. - */ -@SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class ServerMetricsCheckIT { - - private static final System.Logger LOGGER = System.getLogger(ServerMetricsCheckIT.class.getName()); - private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 300; - - private static DbClient DB_CLIENT; - private static WebServer SERVER; - private static String URL; - - private static DbClient initDbClient(Config config) { - Config dbConfig = config.get("db"); - return DbClient.builder(dbConfig) - // add an interceptor to named statement(s) - .addService(DbClientMetrics.counter() - .statementNames("select-pokemons", "insert-pokemon")) - // add an interceptor to statement type(s) - .addService(DbClientMetrics.timer() - .statementTypes(DbStatementType.INSERT)) - .build(); - } - - @BeforeAll - public static void startup(Config config) { - GlobalConfig.config(() -> config); - DB_CLIENT = initDbClient(config); - SERVER = WebServer.builder() - .config(config.get("server")) - .build() - .start(); - URL = "http://localhost:" + SERVER.port(); - LOGGER.log(Level.TRACE, () -> "WEB server is running at " + URL); - } - - @AfterAll - public static void shutdown() { - if (null != SERVER) { - SERVER.stop(); - LOGGER.log(Level.TRACE, () -> "WEB server stopped"); - } - } - - /** - * Retrieve server metrics status from Helidon Web Server. - * - * @param url server health status URL - * @return server health status response (JSON) - * @throws IOException if an I/O error occurs when sending or receiving HTTP request - * @throws InterruptedException if the current thread was interrupted - */ - private static String get(String url) throws IOException, InterruptedException { - HttpClient client = HttpClient.newHttpClient(); - HttpRequest request = HttpRequest.newBuilder() - .uri(URI.create(url)) - .header("Accept", "application/json") - .build(); - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - return response.body(); - } - - /** - * Read and check Database Client metrics 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 testHttpMetrics() throws IOException, InterruptedException { - // Call select-pokemons to trigger it - - DB_CLIENT.execute() - .namedQuery("select-pokemons") - .forEach(p -> { - }); - - // Call insert-pokemon to trigger it - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Lickitung", TYPES.get(1)); - DB_CLIENT.execute() - .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - // Read and process metrics response - String response = get(URL + "/observe/metrics/application"); - LOGGER.log(Level.TRACE, () -> String.format("RESPONSE: %s", response)); - JsonObject application = null; - try (JsonReader jr = Json.createReader(new StringReader(response))) { - application = jr.readObject(); - } catch (JsonParsingException | IllegalStateException ex) { - fail(String.format("Error parsing response: %s", ex.getMessage())); - } - assertThat(application, notNullValue()); - assertThat(application.getValueType(), equalTo(JsonValue.ValueType.OBJECT)); - - assertThat(application.size(), greaterThan(0)); - assertThat(application.containsKey("db.counter.select-pokemons"), equalTo(true)); - assertThat(application.containsKey("db.counter.insert-pokemon"), equalTo(true)); - int selectPokemons = application.getInt("db.counter.select-pokemons"); - int insertPokemons = application.getInt("db.counter.insert-pokemon"); - assertThat(selectPokemons, equalTo(1)); - assertThat(insertPokemons, equalTo(1)); - assertThat(application.containsKey("db.timer.insert-pokemon"), equalTo(true)); - JsonObject insertTimer = application.getJsonObject("db.timer.insert-pokemon"); - assertThat(insertTimer.containsKey("count"), equalTo(true)); - assertThat(insertTimer.containsKey("mean"), equalTo(true)); - assertThat(insertTimer.containsKey("max"), equalTo(true)); - int timerCount = insertTimer.getInt("count"); - assertThat(timerCount, equalTo(1)); - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDeleteIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDeleteIT.java deleted file mode 100644 index f2b657c0ce5..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDeleteIT.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; -import java.util.HashMap; -import java.util.Map; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyDeletePokemon; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyInsertPokemon; - -/** - * Test set of basic JDBC delete calls. - */ -@SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class SimpleDeleteIT { - - private static final System.Logger LOGGER = System.getLogger(SimpleDeleteIT.class.getName()); - private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 30; - private static final Map POKEMONS = new HashMap<>(); - - private final DbClient dbClient; - private final Config config; - - public SimpleDeleteIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { - POKEMONS.put(pokemon.getId(), pokemon); - long result = dbClient.execute() - .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - - @BeforeAll - public static void setup(DbClient dbClient) { - try { - int curId = BASE_ID; - addPokemon(dbClient, new Pokemon(++curId, "Rayquaza", TYPES.get(3), TYPES.get(16))); // BASE_ID+1 - addPokemon(dbClient, new Pokemon(++curId, "Lugia", TYPES.get(3), TYPES.get(14))); // BASE_ID+2 - addPokemon(dbClient, new Pokemon(++curId, "Ho-Oh", TYPES.get(3), TYPES.get(10))); // BASE_ID+3 - addPokemon(dbClient, new Pokemon(++curId, "Raikou", TYPES.get(13))); // BASE_ID+4 - addPokemon(dbClient, new Pokemon(++curId, "Giratina", TYPES.get(8), TYPES.get(16))); // BASE_ID+5 - addPokemon(dbClient, new Pokemon(++curId, "Regirock", TYPES.get(6))); // BASE_ID+6 - addPokemon(dbClient, new Pokemon(++curId, "Kyogre", TYPES.get(11))); // BASE_ID+7 - } catch (Exception ex) { - LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex)); - throw ex; - } - } - - - /** - * Verify {@code createNamedDelete(String, String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedDeleteStrStrOrderArgs() { - String stmt = config.get("db.statements.delete-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .createNamedDelete("delete-rayquaza", stmt) - .addParam(POKEMONS.get(BASE_ID + 1).getId()).execute(); - verifyDeletePokemon(dbClient, result, POKEMONS.get(BASE_ID + 1)); - } - - /** - * Verify {@code createNamedDelete(String)} API method with named parameters. - */ - @Test - public void testCreateNamedDeleteStrNamedArgs() { - long result = dbClient.execute() - .createNamedDelete("delete-pokemon-named-arg") - .addParam("id", POKEMONS.get(BASE_ID + 2).getId()).execute(); - verifyDeletePokemon(dbClient, result, POKEMONS.get(BASE_ID + 2)); - } - - /** - * Verify {@code createNamedDelete(String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedDeleteStrOrderArgs() { - long result = dbClient.execute() - .createNamedDelete("delete-pokemon-order-arg") - .addParam(POKEMONS.get(BASE_ID + 3).getId()).execute(); - verifyDeletePokemon(dbClient, result, POKEMONS.get(BASE_ID + 3)); - } - - /** - * Verify {@code createDelete(String)} API method with named parameters. - */ - @Test - public void testCreateDeleteNamedArgs() { - String stmt = config.get("db.statements.delete-pokemon-named-arg").asString().get(); - long result = dbClient.execute() - .createDelete(stmt) - .addParam("id", POKEMONS.get(BASE_ID + 4).getId()).execute(); - verifyDeletePokemon(dbClient, result, POKEMONS.get(BASE_ID + 4)); - } - - /** - * Verify {@code createDelete(String)} API method with ordered parameters. - */ - @Test - public void testCreateDeleteOrderArgs() { - String stmt = config.get("db.statements.delete-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .createDelete(stmt) - .addParam(POKEMONS.get(BASE_ID + 5).getId()).execute(); - verifyDeletePokemon(dbClient, result, POKEMONS.get(BASE_ID + 5)); - } - - /** - * Verify {@code namedDelete(String)} API method with ordered parameters. - */ - @Test - public void testNamedDeleteOrderArgs() { - long result = dbClient.execute() - .namedDelete("delete-pokemon-order-arg", POKEMONS.get(BASE_ID + 6).getId()); - verifyDeletePokemon(dbClient, result, POKEMONS.get(BASE_ID + 6)); - } - - /** - * Verify {@code delete(String)} API method with ordered parameters. - */ - @Test - public void testDeleteOrderArgs() { - String stmt = config.get("db.statements.delete-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .delete(stmt, POKEMONS.get(BASE_ID + 7).getId()); - verifyDeletePokemon(dbClient, result, POKEMONS.get(BASE_ID + 7)); - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDmlIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDmlIT.java deleted file mode 100644 index 95b7fb1d505..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDmlIT.java +++ /dev/null @@ -1,368 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; -import java.util.HashMap; -import java.util.Map; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyDeletePokemon; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyInsertPokemon; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyUpdatePokemon; - -/** - * Test set of basic JDBC DML statement calls. - */ -@SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class SimpleDmlIT { - - private static final System.Logger LOGGER = System.getLogger(SimpleDmlIT.class.getName()); - private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 40; - private static final Map POKEMONS = new HashMap<>(); - private final DbClient dbClient; - private final Config config; - - public SimpleDmlIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { - POKEMONS.put(pokemon.getId(), pokemon); - long result = dbClient.execute() - .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - - @BeforeAll - public static void setup(DbClient dbClient) { - try { - // [BASE_ID + 1 .. BASE_ID + 9] is reserved for inserts - // [BASE_ID + 10 .. BASE_ID + 19] are reserved for updates - addPokemon(dbClient, new Pokemon(BASE_ID + 10, "Piplup", TYPES.get(11))); // BASE_ID+10 - addPokemon(dbClient, new Pokemon(BASE_ID + 11, "Prinplup", TYPES.get(11))); // BASE_ID+11 - addPokemon(dbClient, new Pokemon(BASE_ID + 12, "Empoleon", TYPES.get(9), TYPES.get(11))); // BASE_ID+12 - addPokemon(dbClient, new Pokemon(BASE_ID + 13, "Staryu", TYPES.get(11))); // BASE_ID+13 - addPokemon(dbClient,new Pokemon(BASE_ID + 14, "Starmie", TYPES.get(11), TYPES.get(14))); // BASE_ID+14 - addPokemon(dbClient,new Pokemon(BASE_ID + 15, "Horsea", TYPES.get(11))); // BASE_ID+15 - addPokemon(dbClient,new Pokemon(BASE_ID + 16, "Seadra", TYPES.get(11))); // BASE_ID+16 - // BASE_ID + 20 .. BASE_ID + 29 are reserved for deletes - addPokemon(dbClient,new Pokemon(BASE_ID + 20, "Mudkip", TYPES.get(11))); // BASE_ID+20 - addPokemon(dbClient,new Pokemon(BASE_ID + 21, "Marshtomp", TYPES.get(5), TYPES.get(11))); // BASE_ID+21 - addPokemon(dbClient,new Pokemon(BASE_ID + 22, "Swampert", TYPES.get(5), TYPES.get(11))); // BASE_ID+22 - addPokemon(dbClient,new Pokemon(BASE_ID + 23, "Muk", TYPES.get(4))); // BASE_ID+23 - addPokemon(dbClient,new Pokemon(BASE_ID + 24, "Grimer", TYPES.get(4))); // BASE_ID+24 - addPokemon(dbClient,new Pokemon(BASE_ID + 25, "Cubchoo", TYPES.get(15))); // BASE_ID+25 - addPokemon(dbClient,new Pokemon(BASE_ID + 26, "Beartic", TYPES.get(15))); // BASE_ID+26 - } catch (Exception ex) { - LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex)); - throw ex; - } - } - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with insert with named parameters. - */ - @Test - public void testCreateNamedDmlWithInsertStrStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Torchic", TYPES.get(10)); - String stmt = config.get("db.statements.insert-pokemon-named-arg").asString().get(); - long result = dbClient.execute() - .createNamedDmlStatement("insert-torchic", stmt) - .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with insert with named parameters. - */ - @Test - public void testCreateNamedDmlWithInsertStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 2, "Combusken", TYPES.get(2), TYPES.get(10)); - long result = dbClient.execute() - .createNamedDmlStatement("insert-pokemon-named-arg") - .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with insert with ordered parameters. - */ - @Test - public void testCreateNamedDmlWithInsertStrOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 3, "Treecko", TYPES.get(12)); - long result = dbClient.execute() - .createNamedDmlStatement("insert-pokemon-order-arg") - .addParam(pokemon.getId()).addParam(pokemon.getName()) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createDmlStatement(String)} API method with insert with named parameters. - */ - @Test - public void testCreateDmlWithInsertNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 4, "Grovyle", TYPES.get(12)); - String stmt = config.get("db.statements.insert-pokemon-named-arg").asString().get(); - long result = dbClient.execute() - .createDmlStatement(stmt) - .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createDmlStatement(String)} API method with insert with ordered parameters. - */ - @Test - public void testCreateDmlWithInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 5, "Sceptile", TYPES.get(12)); - String stmt = config.get("db.statements.insert-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .createDmlStatement(stmt) - .addParam(pokemon.getId()).addParam(pokemon.getName()) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code namedDml(String)} API method with insert with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - public void testNamedDmlWithInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 6, "Snover", TYPES.get(12), TYPES.get(15)); - long result = dbClient.execute() - .namedDml("insert-pokemon-order-arg", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code dml(String)} API method with insert with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - public void testDmlWithInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 7, "Abomasnow", TYPES.get(12), TYPES.get(15)); - String stmt = config.get("db.statements.insert-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .dml(stmt, pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with update with named parameters. - */ - @Test - public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 10); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 10, "Prinplup", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-named-arg").asString().get(); - long result = dbClient.execute() - .createNamedDmlStatement("update-piplup", stmt) - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with update with named parameters. - */ - @Test - public void testCreateNamedDmlWithUpdateStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 11); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 11, "Empoleon", srcPokemon.getTypesArray()); - long result = dbClient.execute() - .createNamedDmlStatement("update-pokemon-named-arg") - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with update with ordered parameters. - */ - @Test - public void testCreateNamedDmlWithUpdateStrOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 12); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 12, "Piplup", srcPokemon.getTypesArray()); - long result = dbClient.execute() - .createNamedDmlStatement("update-pokemon-order-arg") - .addParam(updatedPokemon.getName()).addParam(updatedPokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createDmlStatement(String)} API method with update with named parameters. - */ - @Test - public void testCreateDmlWithUpdateNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 13); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 13, "Starmie", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-named-arg").asString().get(); - long result = dbClient.execute() - .createDmlStatement(stmt) - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createDmlStatement(String)} API method with update with ordered parameters. - */ - @Test - public void testCreateDmlWithUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 14); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 14, "Staryu", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .createDmlStatement(stmt) - .addParam(updatedPokemon.getName()).addParam(updatedPokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code namedDml(String)} API method with update with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - public void testNamedDmlWithUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 15); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 15, "Seadra", srcPokemon.getTypesArray()); - long result = dbClient.execute() - .namedDml("update-pokemon-order-arg", updatedPokemon.getName(), updatedPokemon.getId()); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code dml(String)} API method with update with ordered parameters passed directly - * to the {@code insert} method. - */ - @Test - public void testDmlWithUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 16); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 16, "Horsea", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .dml(stmt, updatedPokemon.getName(), updatedPokemon.getId()); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createNamedDmlStatement(String, String)} API method with delete with ordered parameters. - */ - @Test - public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 20); - String stmt = config.get("db.statements.delete-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .createNamedDmlStatement("delete-mudkip", stmt) - .addParam(pokemon.getId()) - .execute(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with delete with named parameters. - */ - @Test - public void testCreateNamedDmlWithDeleteStrNamedArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 21); - long result = dbClient.execute() - .createNamedDmlStatement("delete-pokemon-named-arg") - .addParam("id", pokemon.getId()) - .execute(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedDmlStatement(String)} API method with delete with ordered parameters. - */ - @Test - public void testCreateNamedDmlWithDeleteStrOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 22); - long result = dbClient.execute() - .createNamedDmlStatement("delete-pokemon-order-arg") - .addParam(pokemon.getId()) - .execute(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createDmlStatement(String)} API method with delete with named parameters. - */ - @Test - public void testCreateDmlWithDeleteNamedArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 23); - String stmt = config.get("db.statements.delete-pokemon-named-arg").asString().get(); - long result = dbClient.execute() - .createDmlStatement(stmt) - .addParam("id", pokemon.getId()) - .execute(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createDmlStatement(String)} API method with delete with ordered parameters. - */ - @Test - public void testCreateDmlWithDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 24); - String stmt = config.get("db.statements.delete-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .createDmlStatement(stmt) - .addParam(pokemon.getId()) - .execute(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code namedDml(String)} API method with delete with ordered parameters. - */ - @Test - public void testNamedDmlWithDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 25); - long result = dbClient.execute().namedDml("delete-pokemon-order-arg", pokemon.getId()); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code dml(String)} API method with delete with ordered parameters. - */ - @Test - public void testDmlWithDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 26); - String stmt = config.get("db.statements.delete-pokemon-order-arg").asString().get(); - long result = dbClient.execute().dml(stmt, pokemon.getId()); - verifyDeletePokemon(dbClient, result, pokemon); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleGetIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleGetIT.java deleted file mode 100644 index 07ba959e42a..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleGetIT.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.util.Optional; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyPokemon; - -/** - * Test set of basic JDBC get calls. - */ -@ExtendWith(DbClientParameterResolver.class) -public class SimpleGetIT { - - private final DbClient dbClient; - private final Config config; - - public SimpleGetIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - /** - * Verify {@code createNamedGet(String, String)} API method with named parameters. - */ - @Test - public void testCreateNamedGetStrStrNamedArgs() { - String stmt = config.get("db.statements.select-pokemon-named-arg").asString().get(); - Optional maybeRow = - dbClient.execute().createNamedGet("select-pikachu", stmt) - .addParam("name", POKEMONS.get(1).getName()) - .execute(); - verifyPokemon(maybeRow, POKEMONS.get(1)); - } - - /** - * Verify {@code createNamedGet(String)} API method with named parameters. - */ - @Test - public void testCreateNamedGetStrNamedArgs() { - Optional maybeRow = dbClient.execute() - .createNamedGet("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(2).getName()) - .execute(); - verifyPokemon(maybeRow, POKEMONS.get(2)); - } - - /** - * Verify {@code createNamedGet(String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedGetStrOrderArgs() { - Optional maybeRow = dbClient.execute() - .createNamedGet("select-pokemon-order-arg") - .addParam(POKEMONS.get(3).getName()) - .execute(); - verifyPokemon(maybeRow, POKEMONS.get(3)); - } - - /** - * Verify {@code createGet(String)} API method with named parameters. - */ - @Test - public void testCreateGetNamedArgs() { - String stmt = config.get("db.statements.select-pokemon-named-arg").asString().get(); - Optional maybeRow = dbClient.execute() - .createGet(stmt) - .addParam("name", POKEMONS.get(4).getName()) - .execute(); - verifyPokemon(maybeRow, POKEMONS.get(4)); - } - - /** - * Verify {@code createGet(String)} API method with ordered parameters. - */ - @Test - public void testCreateGetOrderArgs() { - String stmt = config.get("db.statements.select-pokemon-order-arg").asString().get(); - Optional maybeRow = dbClient.execute() - .createGet(stmt) - .addParam(POKEMONS.get(5).getName()) - .execute(); - verifyPokemon(maybeRow, POKEMONS.get(5)); - } - - /** - * Verify {@code namedGet(String)} API method with ordered parameters passed directly to the {@code query} method. - */ - @Test - public void testNamedGetStrOrderArgs() { - Optional maybeRow = dbClient.execute() - .namedGet("select-pokemon-order-arg", POKEMONS.get(6).getName()); - verifyPokemon(maybeRow, POKEMONS.get(6)); - } - - /** - * Verify {@code get(String)} API method with ordered parameters passed directly to the {@code query} method. - */ - @Test - public void testGetStrOrderArgs() { - String stmt = config.get("db.statements.select-pokemon-order-arg").asString().get(); - Optional maybeRow = dbClient.execute() - .get(stmt, POKEMONS.get(7).getName()); - verifyPokemon(maybeRow, POKEMONS.get(7)); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleInsertIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleInsertIT.java deleted file mode 100644 index de26e70a6e7..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleInsertIT.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyInsertPokemon; - -/** - * Test set of basic JDBC inserts. - */ -@SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class SimpleInsertIT { - - /** - * Maximum Pokemon ID. - */ - private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 10; - - private final DbClient dbClient; - private final Config config; - - public SimpleInsertIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - /** - * Verify {@code createNamedInsert(String, String)} API method with named parameters. - */ - @Test - public void testCreateNamedInsertStrStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Bulbasaur", TYPES.get(4), TYPES.get(12)); - String stmt = config.get("db.statements.insert-pokemon-named-arg").asString().get(); - long result = dbClient.execute() - .createNamedInsert("insert-bulbasaur", stmt) - .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedInsert(String)} API method with named parameters. - */ - @Test - public void testCreateNamedInsertStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 2, "Ivysaur", TYPES.get(4), TYPES.get(12)); - long result = dbClient.execute() - .createNamedInsert("insert-pokemon-named-arg") - .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedInsert(String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedInsertStrOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 3, "Venusaur", TYPES.get(4), TYPES.get(12)); - long result = dbClient.execute() - .createNamedInsert("insert-pokemon-order-arg") - .addParam(pokemon.getId()).addParam(pokemon.getName()) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createInsert(String)} API method with named parameters. - */ - @Test - public void testCreateInsertNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 4, "Magby", TYPES.get(10)); - String stmt = config.get("db.statements.insert-pokemon-named-arg").asString().get(); - long result = dbClient.execute() - .createInsert(stmt) - .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createInsert(String)} API method with ordered parameters. - */ - @Test - public void testCreateInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 5, "Magmar", TYPES.get(10)); - String stmt = config.get("db.statements.insert-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .createInsert(stmt) - .addParam(pokemon.getId()).addParam(pokemon.getName()) - .execute(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code namedInsert(String)} API method with ordered parameters passed directly to the {@code insert} method. - */ - @Test - public void testNamedInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 6, "Rattata", TYPES.get(1)); - long result = dbClient.execute().namedInsert("insert-pokemon-order-arg", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code insert(String)} API method with ordered parameters passed directly to the {@code insert} method. - */ - @Test - public void testInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 7, "Raticate", TYPES.get(1)); - String stmt = config.get("db.statements.insert-pokemon-order-arg").asString().get(); - long result = dbClient.execute().insert(stmt, pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleQueriesIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleQueriesIT.java deleted file mode 100644 index 10d355205db..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleQueriesIT.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.util.stream.Stream; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyPokemon; - -/** - * Test set of basic JDBC queries. - */ -@ExtendWith(DbClientParameterResolver.class) -public class SimpleQueriesIT { - - private final DbClient dbClient; - private final Config config; - - public SimpleQueriesIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - /** - * Verify {@code createNamedQuery(String, String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedQueryStrStrOrderArgs() { - String stmt = config.get("db.statements.select-pokemon-order-arg").asString().get(); - Stream rows = dbClient.execute() - .createNamedQuery("select-pikachu", stmt) - .addParam(POKEMONS.get(1).getName()) - .execute(); - - verifyPokemon(rows, POKEMONS.get(1)); - } - - /** - * Verify {@code createNamedQuery(String)} API method with named parameters. - */ - @Test - public void testCreateNamedQueryStrNamedArgs() { - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(2).getName()) - .execute(); - verifyPokemon(rows, POKEMONS.get(2)); - } - - /** - * Verify {@code createNamedQuery(String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedQueryStrOrderArgs() { - Stream rows = dbClient.execute() - .createNamedQuery("select-pokemon-order-arg") - .addParam(POKEMONS.get(3).getName()) - .execute(); - verifyPokemon(rows, POKEMONS.get(3)); - } - - /** - * Verify {@code createQuery(String)} API method with named parameters. - */ - @Test - public void testCreateQueryNamedArgs() { - String stmt = config.get("db.statements.select-pokemon-named-arg").asString().get(); - Stream rows = dbClient.execute() - .createQuery(stmt) - .addParam("name", POKEMONS.get(4).getName()) - .execute(); - verifyPokemon(rows, POKEMONS.get(4)); - } - - /** - * Verify {@code createQuery(String)} API method with ordered parameters. - */ - @Test - public void testCreateQueryOrderArgs() { - String stmt = config.get("db.statements.select-pokemon-order-arg").asString().get(); - Stream rows = dbClient.execute() - .createQuery(stmt) - .addParam(POKEMONS.get(5).getName()) - .execute(); - verifyPokemon(rows, POKEMONS.get(5)); - } - - /** - * Verify {@code namedQuery(String)} API method with ordered parameters passed directly to the {@code namedQuery} method. - */ - @Test - public void testNamedQueryOrderArgs() { - Stream rows = dbClient.execute() - .namedQuery("select-pokemon-order-arg", POKEMONS.get(6).getName()); - verifyPokemon(rows, POKEMONS.get(6)); - } - - /** - * Verify {@code query(String)} API method with ordered parameters passed directly to the {@code query} method. - */ - @Test - public void testQueryOrderArgs() { - String stmt = config.get("db.statements.select-pokemon-order-arg").asString().get(); - Stream rows = dbClient.execute() - .query(stmt, POKEMONS.get(7).getName()); - verifyPokemon(rows, POKEMONS.get(7)); - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleUpdateIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleUpdateIT.java deleted file mode 100644 index 8e8f820a793..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleUpdateIT.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; -import java.util.HashMap; -import java.util.Map; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyInsertPokemon; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyUpdatePokemon; - -/** - * Test set of basic JDBC updates. - */ -@SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class SimpleUpdateIT { - - private static final System.Logger LOGGER = System.getLogger(SimpleUpdateIT.class.getName()); - private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 20; - private static final Map POKEMONS = new HashMap<>(); - - private final DbClient dbClient; - private final Config config; - - public SimpleUpdateIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { - POKEMONS.put(pokemon.getId(), pokemon); - long result = dbClient.execute() - .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Initialize tests of basic JDBC updates. - */ - @BeforeAll - public static void setup(DbClient dbClient) { - try { - int curId = BASE_ID; - addPokemon(dbClient, new Pokemon(++curId, "Spearow", TYPES.get(1), TYPES.get(3))); // BASE_ID+1 - addPokemon(dbClient, new Pokemon(++curId, "Fearow", TYPES.get(1), TYPES.get(3))); // BASE_ID+2 - addPokemon(dbClient, new Pokemon(++curId, "Ekans", TYPES.get(4))); // BASE_ID+3 - addPokemon(dbClient, new Pokemon(++curId, "Arbok", TYPES.get(4))); // BASE_ID+4 - addPokemon(dbClient, new Pokemon(++curId, "Sandshrew", TYPES.get(5))); // BASE_ID+5 - addPokemon(dbClient, new Pokemon(++curId, "Sandslash", TYPES.get(5))); // BASE_ID+6 - addPokemon(dbClient, new Pokemon(++curId, "Diglett", TYPES.get(5))); // BASE_ID+7 - } catch (Exception ex) { - LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex)); - throw ex; - } - } - - /** - * Verify {@code createNamedUpdate(String, String)} API method with named parameters. - */ - @Test - public void testCreateNamedUpdateStrStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 1); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 1, "Fearow", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-named-arg").asString().get(); - long result = dbClient.execute() - .createNamedUpdate("update-spearow", stmt) - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createNamedUpdate(String)} API method with named parameters. - */ - @Test - public void testCreateNamedUpdateStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 2); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 2, "Spearow", srcPokemon.getTypesArray()); - long result = dbClient.execute() - .createNamedUpdate("update-pokemon-named-arg") - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createNamedUpdate(String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedUpdateStrOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 3); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 3, "Arbok", srcPokemon.getTypesArray()); - long result = dbClient.execute() - .createNamedUpdate("update-pokemon-order-arg") - .addParam(updatedPokemon.getName()).addParam(updatedPokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createUpdate(String)} API method with named parameters. - */ - @Test - public void testCreateUpdateNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 4); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 4, "Ekans", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-named-arg").asString().get(); - long result = dbClient.execute() - .createUpdate(stmt) - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createUpdate(String)} API method with ordered parameters. - */ - @Test - public void testCreateUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 5); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 5, "Diglett", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .createUpdate(stmt) - .addParam(updatedPokemon.getName()).addParam(updatedPokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code namedUpdate(String)} API method with named parameters. - */ - @Test - public void testNamedUpdateNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 6); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 6, "Sandshrew", srcPokemon.getTypesArray()); - long result = dbClient.execute() - .namedUpdate("update-pokemon-order-arg", updatedPokemon.getName(), updatedPokemon.getId()); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code update(String)} API method with ordered parameters. - */ - @Test - public void testUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 7); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 7, "Sandslash", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-order-arg").asString().get(); - long result = dbClient.execute() - .update(stmt, updatedPokemon.getName(), updatedPokemon.getId()); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/StatementDmlIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/StatementDmlIT.java deleted file mode 100644 index d8cc1be2150..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/StatementDmlIT.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import io.helidon.dbclient.DbClient; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyInsertPokemon; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyUpdatePokemon; - -/** - * Test DbStatementDml methods. - */ -@SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class StatementDmlIT { - - private static final System.Logger LOGGER = System.getLogger(StatementDmlIT.class.getName()); - private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 100; - - private final DbClient dbClient; - - public StatementDmlIT(DbClient dbClient) { - this.dbClient = dbClient; - } - - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { - long result = dbClient.execute() - .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Initialize DbStatementDml methods tests. - */ - @BeforeAll - public static void setup(DbClient dbClient) { - try { - addPokemon(dbClient, new Pokemon(BASE_ID, "Shinx", TYPES.get(13))); // BASE_ID+0 - addPokemon(dbClient, new Pokemon(BASE_ID + 1, "Luxio", TYPES.get(13))); // BASE_ID+1 - addPokemon(dbClient, new Pokemon(BASE_ID + 2, "Luxray", TYPES.get(13))); // BASE_ID+2 - addPokemon(dbClient, new Pokemon(BASE_ID + 3, "Kricketot", TYPES.get(7))); // BASE_ID+3 - addPokemon(dbClient, new Pokemon(BASE_ID + 4, "Kricketune", TYPES.get(7))); // BASE_ID+4 - addPokemon(dbClient, new Pokemon(BASE_ID + 5, "Phione", TYPES.get(11))); // BASE_ID+5 - addPokemon(dbClient, new Pokemon(BASE_ID + 6, "Chatot", TYPES.get(1), TYPES.get(3))); // BASE_ID+6 - } catch (Exception ex) { - LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex), ex); - throw ex; - } - } - - /** - * Verify {@code params(Object... parameters)} parameters setting method. - */ - @Test - public void testDmlArrayParams() { - Pokemon pokemon = new Pokemon(BASE_ID, "Luxio", TYPES.get(13)); - long result = dbClient.execute() - .createNamedDmlStatement("update-pokemon-order-arg") - .params(pokemon.getName(), pokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code params(List)} parameters setting method. - */ - @Test - public void testDmlListParams() { - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Luxray", TYPES.get(13)); - List params = new ArrayList<>(2); - params.add(pokemon.getName()); - params.add(pokemon.getId()); - long result = dbClient.execute() - .createNamedDmlStatement("update-pokemon-order-arg") - .params(params) - .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code params(Map)} parameters setting method. - */ - @Test - public void testDmlMapParams() { - Pokemon pokemon = new Pokemon(BASE_ID + 2, "Shinx", TYPES.get(13)); - Map params = new HashMap<>(2); - params.put("name", pokemon.getName()); - params.put("id", pokemon.getId()); - long result = dbClient.execute() - .createNamedDmlStatement("update-pokemon-named-arg") - .params(params) - .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code addParam(Object parameter)} parameters setting method. - */ - @Test - public void testDmlOrderParam() { - Pokemon pokemon = new Pokemon(BASE_ID + 3, "Kricketune", TYPES.get(7)); - long result = dbClient.execute() - .createNamedDmlStatement("update-pokemon-order-arg") - .addParam(pokemon.getName()) - .addParam(pokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code addParam(String name, Object parameter)} parameters setting method. - */ - @Test - public void testDmlNamedParam() { - Pokemon pokemon = new Pokemon(BASE_ID + 4, "Kricketot", TYPES.get(7)); - long result = dbClient.execute() - .createNamedDmlStatement("update-pokemon-named-arg") - .addParam("name", pokemon.getName()) - .addParam("id", pokemon.getId()) - .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code namedParam(Object parameters)} mapped parameters setting method. - */ - @Test - public void testDmlMappedNamedParam() { - Pokemon pokemon = new Pokemon(BASE_ID + 5, "Chatot", TYPES.get(1), TYPES.get(3)); - long result = dbClient.execute() - .createNamedDmlStatement("update-pokemon-named-arg") - .namedParam(pokemon) - .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code indexedParam(Object parameters)} mapped parameters setting method. - */ - @Test - public void testDmlMappedOrderParam() { - Pokemon pokemon = new Pokemon(BASE_ID + 6, "Phione", TYPES.get(11)); - long result = dbClient.execute() - .createNamedDmlStatement("update-pokemon-order-arg") - .indexedParam(pokemon) - .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionDeleteIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionDeleteIT.java deleted file mode 100644 index 0a3203142ef..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionDeleteIT.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbTransaction; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyDeletePokemon; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyInsertPokemon; - -/** - * Test set of basic JDBC delete calls in transaction. - */ -@SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class TransactionDeleteIT { - - private static final System.Logger LOGGER = System.getLogger(TransactionDeleteIT.class.getName()); - private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 230; - private static final Map POKEMONS = new HashMap<>(); - - private final DbClient dbClient; - private final Config config; - - public TransactionDeleteIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { - POKEMONS.put(pokemon.getId(), pokemon); - long result = dbClient.execute() - .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - - @BeforeAll - public static void setup(DbClient dbClient) throws ExecutionException, InterruptedException { - try { - int curId = BASE_ID; - addPokemon(dbClient, new Pokemon(++curId, "Omanyte", TYPES.get(6), TYPES.get(11))); // BASE_ID+1 - addPokemon(dbClient, new Pokemon(++curId, "Omastar", TYPES.get(6), TYPES.get(11))); // BASE_ID+2 - addPokemon(dbClient, new Pokemon(++curId, "Kabuto", TYPES.get(6), TYPES.get(11))); // BASE_ID+3 - addPokemon(dbClient, new Pokemon(++curId, "Kabutops", TYPES.get(6), TYPES.get(11))); // BASE_ID+4 - addPokemon(dbClient, new Pokemon(++curId, "Chikorita", TYPES.get(12))); // BASE_ID+5 - addPokemon(dbClient, new Pokemon(++curId, "Bayleef", TYPES.get(12))); // BASE_ID+6 - addPokemon(dbClient, new Pokemon(++curId, "Meganium", TYPES.get(12))); // BASE_ID+7 - } catch (Exception ex) { - LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex)); - throw ex; - } - } - - /** - * Verify {@code createNamedDelete(String, String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedDeleteStrStrOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 1); - String stmt = config.get("db.statements.delete-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createNamedDelete("delete-rayquaza", stmt) - .addParam(pokemon.getId()) - .execute(); - tx.commit(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedDelete(String)} API method with named parameters. - */ - @Test - public void testCreateNamedDeleteStrNamedArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 2); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createNamedDelete("delete-pokemon-named-arg") - .addParam("id", pokemon.getId()) - .execute(); - tx.commit(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedDelete(String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedDeleteStrOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 3); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createNamedDelete("delete-pokemon-order-arg") - .addParam(pokemon.getId()) - .execute(); - tx.commit(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createDelete(String)} API method with named parameters. - */ - @Test - public void testCreateDeleteNamedArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 4); - String stmt = config.get("db.statements.delete-pokemon-named-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createDelete(stmt) - .addParam("id", pokemon.getId()) - .execute(); - tx.commit(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createDelete(String)} API method with ordered parameters. - */ - @Test - public void testCreateDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 5); - String stmt = config.get("db.statements.delete-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createDelete(stmt) - .addParam(pokemon.getId()) - .execute(); - tx.commit(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code namedDelete(String)} API method with ordered parameters. - */ - @Test - public void testNamedDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 6); - DbTransaction tx = dbClient.transaction(); - long result = tx - .namedDelete("delete-pokemon-order-arg", pokemon.getId()); - tx.commit(); - verifyDeletePokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code delete(String)} API method with ordered parameters. - */ - @Test - public void testDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 7); - String stmt = config.get("db.statements.delete-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .delete(stmt, pokemon.getId()); - tx.commit(); - verifyDeletePokemon(dbClient, result, pokemon); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionExceptionalStmtIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionExceptionalStmtIT.java deleted file mode 100644 index f32eac068e2..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionExceptionalStmtIT.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; -import java.util.concurrent.CompletionException; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbClientException; -import io.helidon.dbclient.DbTransaction; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; -import static org.junit.jupiter.api.Assertions.fail; - -/** - * Test exceptional states. - */ -@ExtendWith(DbClientParameterResolver.class) -public class TransactionExceptionalStmtIT { - - private static final System.Logger LOGGER = System.getLogger(TransactionExceptionalStmtIT.class.getName()); - - private final DbClient dbClient; - - public TransactionExceptionalStmtIT(DbClient dbClient) { - this.dbClient = dbClient; - } - - /** - * Verify that execution of query with non-existing named statement throws an exception. - */ - @Test - public void testCreateNamedQueryNonExistentStmt() { - try { - DbTransaction tx = dbClient.transaction(); - tx.createNamedQuery("select-pokemons-not-exists") - .execute() - .forEach(it -> {}); - tx.commit(); - fail("Execution of non existing statement shall cause an exception to be thrown."); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format("Expected exception: %s", ex.getMessage()), ex); - } - } - - /** - * Verify that execution of query with both named and ordered arguments throws an exception. - */ - @Test - public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { - try { - DbTransaction tx = dbClient.transaction(); - tx.createNamedQuery("select-pokemons-error-arg") - .execute() - .forEach(it -> {}); - tx.commit(); - fail("Execution of query with both named and ordered parameters without passing any shall fail."); - } catch (DbClientException | - CompletionException ex) { - LOGGER.log(Level.DEBUG, () -> String.format("Expected exception: %s", ex.getMessage()), ex); - } - } - - /** - * Verify that execution of query with both named and ordered arguments throws an exception. - */ - @Test - public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { - try { - DbTransaction tx = dbClient.transaction(); - tx.createNamedQuery("select-pokemons-error-arg") - .addParam("id", POKEMONS.get(5).getId()) - .addParam(POKEMONS.get(5).getName()) - .execute() - .forEach(it -> {}); - tx.commit(); - fail("Execution of query with both named and ordered parameters without passing them shall fail."); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format("Expected exception: %s", ex.getMessage()), ex); - } - } - - /** - * Verify that execution of query with named arguments throws an exception while trying to set ordered argument. - */ - @Test - public void testCreateNamedQueryNamedArgsSetOrderArg() { - try { - DbTransaction tx = dbClient.transaction(); - tx.createNamedQuery("select-pokemon-named-arg") - .addParam(POKEMONS.get(5).getName()) - .execute() - .forEach(it -> {}); - tx.commit(); - fail("Execution of query with named parameter with passing ordered parameter value shall fail."); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format("Expected exception: %s", ex.getMessage()), ex); - } - } - - /** - * Verify that execution of query with ordered arguments throws an exception while trying to set named argument. - */ - @Test - public void testCreateNamedQueryOrderArgsSetNamedArg() { - try { - DbTransaction tx = dbClient.transaction(); - tx.createNamedQuery("select-pokemon-order-arg") - .addParam("name", POKEMONS.get(6).getName()) - .execute() - .forEach(it -> {}); - tx.commit(); - fail("Execution of query with ordered parameter with passing named parameter value shall fail."); - } catch (DbClientException ex) { - LOGGER.log(Level.DEBUG, () -> String.format("Expected exception: %s", ex.getMessage()), ex); - } - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionGetIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionGetIT.java deleted file mode 100644 index 43e4e7ae108..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionGetIT.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.util.Optional; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.dbclient.DbTransaction; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyPokemon; - -/** - * Test set of basic JDBC get calls in transaction. - */ -@ExtendWith(DbClientParameterResolver.class) -public class TransactionGetIT { - - private final DbClient dbClient; - private final Config config; - - public TransactionGetIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - /** - * Verify {@code createNamedGet(String, String)} API method with named parameters. - */ - @Test - public void testCreateNamedGetStrStrNamedArgs() { - String stmt = config.get("db.statements.select-pokemon-named-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - Optional maybeRow = tx - .createNamedGet("select-pikachu", stmt) - .addParam("name", POKEMONS.get(1).getName()) - .execute(); - tx.commit(); - verifyPokemon(maybeRow, POKEMONS.get(1)); - } - - /** - * Verify {@code createNamedGet(String)} API method with named parameters. - */ - @Test - public void testCreateNamedGetStrNamedArgs() { - DbTransaction tx = dbClient.transaction(); - Optional maybeRow = tx - .createNamedGet("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(2).getName()) - .execute(); - tx.commit(); - - verifyPokemon(maybeRow, POKEMONS.get(2)); - } - - /** - * Verify {@code createNamedGet(String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedGetStrOrderArgs() { - DbTransaction tx = dbClient.transaction(); - Optional maybeRow = tx - .createNamedGet("select-pokemon-order-arg") - .addParam(POKEMONS.get(3).getName()) - .execute(); - tx.commit(); - - verifyPokemon(maybeRow, POKEMONS.get(3)); - } - - /** - * Verify {@code createGet(String)} API method with named parameters. - */ - @Test - public void testCreateGetNamedArgs() { - String stmt = config.get("db.statements.select-pokemon-named-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - Optional maybeRow = tx - .createGet(stmt) - .addParam("name", POKEMONS.get(4).getName()) - .execute(); - tx.commit(); - - verifyPokemon(maybeRow, POKEMONS.get(4)); - } - - /** - * Verify {@code createGet(String)} API method with ordered parameters. - */ - @Test - public void testCreateGetOrderArgs() { - String stmt = config.get("db.statements.select-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - Optional maybeRow = tx - .createGet(stmt) - .addParam(POKEMONS.get(5).getName()) - .execute(); - tx.commit(); - - verifyPokemon(maybeRow, POKEMONS.get(5)); - } - - /** - * Verify {@code namedGet(String)} API method with ordered parameters passed directly to the {@code query} method. - */ - @Test - public void testNamedGetStrOrderArgs() { - DbTransaction tx = dbClient.transaction(); - Optional maybeRow = tx - .namedGet("select-pokemon-order-arg", POKEMONS.get(6).getName()); - tx.commit(); - - verifyPokemon(maybeRow, POKEMONS.get(6)); - } - - /** - * Verify {@code get(String)} API method with ordered parameters passed directly to the {@code query} method. - */ - @Test - public void testGetStrOrderArgs() { - String stmt = config.get("db.statements.select-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - Optional maybeRow = tx - .get(stmt, POKEMONS.get(7).getName()); - tx.commit(); - - verifyPokemon(maybeRow, POKEMONS.get(7)); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionInsertIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionInsertIT.java deleted file mode 100644 index a8d19199f40..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionInsertIT.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbTransaction; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyInsertPokemon; - -/** - * Test set of basic JDBC inserts in transaction. - */ -@SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class TransactionInsertIT { - - private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 210; - - private final DbClient dbClient; - private final Config config; - - public TransactionInsertIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - /** - * Verify {@code createNamedInsert(String, String)} API method with named parameters. - */ - @Test - public void testCreateNamedInsertStrStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Sentret", TYPES.get(1)); - String stmt = config.get("db.statements.insert-pokemon-named-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createNamedInsert("insert-bulbasaur", stmt) - .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()).execute(); - tx.commit(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedInsert(String)} API method with named parameters. - */ - @Test - public void testCreateNamedInsertStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 2, "Furret", TYPES.get(1)); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createNamedInsert("insert-pokemon-named-arg") - .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()).execute(); - tx.commit(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createNamedInsert(String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedInsertStrOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 3, "Chinchou", TYPES.get(11), TYPES.get(13)); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createNamedInsert("insert-pokemon-order-arg") - .addParam(pokemon.getId()).addParam(pokemon.getName()).execute(); - tx.commit(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createInsert(String)} API method with named parameters. - */ - @Test - public void testCreateInsertNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 4, "Lanturn", TYPES.get(11), TYPES.get(13)); - String stmt = config.get("db.statements.insert-pokemon-named-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createInsert(stmt) - .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()).execute(); - tx.commit(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code createInsert(String)} API method with ordered parameters. - */ - @Test - public void testCreateInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 5, "Swinub", TYPES.get(5), TYPES.get(15)); - String stmt = config.get("db.statements.insert-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createInsert(stmt) - .addParam(pokemon.getId()).addParam(pokemon.getName()).execute(); - tx.commit(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code namedInsert(String)} API method with ordered parameters passed directly to the {@code insert} method. - */ - @Test - public void testNamedInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 6, "Piloswine", TYPES.get(5), TYPES.get(15)); - DbTransaction tx = dbClient.transaction(); - long result = tx - .namedInsert("insert-pokemon-order-arg", pokemon.getId(), pokemon.getName()); - tx.commit(); - verifyInsertPokemon(dbClient, result, pokemon); - } - - /** - * Verify {@code insert(String)} API method with ordered parameters passed directly to the {@code insert} method. - */ - @Test - public void testInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 7, "Mamoswine", TYPES.get(5), TYPES.get(15)); - String stmt = config.get("db.statements.insert-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .insert(stmt, pokemon.getId(), pokemon.getName()); - tx.commit(); - verifyInsertPokemon(dbClient, result, pokemon); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionQueriesIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionQueriesIT.java deleted file mode 100644 index aba3a98e987..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionQueriesIT.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.util.List; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.dbclient.DbTransaction; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyPokemon; - -/** - * Test set of basic JDBC queries in transaction. - */ -@ExtendWith(DbClientParameterResolver.class) -public class TransactionQueriesIT { - - private final DbClient dbClient; - private final Config config; - - public TransactionQueriesIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - /** - * Verify {@code createNamedQuery(String, String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedQueryStrStrOrderArgs() { - String stmt = config.get("db.statements.select-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - List rows = tx - .createNamedQuery("select-pikachu", stmt) - .addParam(POKEMONS.get(1).getName()) - .execute() - .toList(); - tx.commit(); - verifyPokemon(rows, POKEMONS.get(1)); - } - - /** - * Verify {@code createNamedQuery(String)} API method with named parameters. - */ - @Test - public void testCreateNamedQueryStrNamedArgs() { - DbTransaction tx = dbClient.transaction(); - List rows = tx - .createNamedQuery("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(2).getName()) - .execute() - .toList(); - tx.commit(); - verifyPokemon(rows, POKEMONS.get(2)); - } - - /** - * Verify {@code createNamedQuery(String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedQueryStrOrderArgs() { - DbTransaction tx = dbClient.transaction(); - List rows = tx - .createNamedQuery("select-pokemon-order-arg") - .addParam(POKEMONS.get(3).getName()) - .execute() - .toList(); - tx.commit(); - verifyPokemon(rows, POKEMONS.get(3)); - } - - /** - * Verify {@code createQuery(String)} API method with named parameters. - */ - @Test - public void testCreateQueryNamedArgs() { - String stmt = config.get("db.statements.select-pokemon-named-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - List rows = tx - .createQuery(stmt) - .addParam("name", POKEMONS.get(4).getName()) - .execute() - .toList(); - tx.commit(); - verifyPokemon(rows, POKEMONS.get(4)); - } - - /** - * Verify {@code createQuery(String)} API method with ordered parameters. - */ - @Test - public void testCreateQueryOrderArgs() { - String stmt = config.get("db.statements.select-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - List rows = tx - .createQuery(stmt) - .addParam(POKEMONS.get(5).getName()) - .execute() - .toList(); - tx.commit(); - verifyPokemon(rows, POKEMONS.get(5)); - } - - /** - * Verify {@code namedQuery(String)} API method with ordered parameters passed directly to the {@code namedQuery} method. - */ - @Test - public void testNamedQueryOrderArgs() { - DbTransaction tx = dbClient.transaction(); - List rows = tx - .namedQuery("select-pokemon-order-arg", POKEMONS.get(6).getName()) - .toList(); - tx.commit(); - verifyPokemon(rows, POKEMONS.get(6)); - } - - /** - * Verify {@code query(String)} API method with ordered parameters passed directly to the {@code query} method. - */ - @Test - public void testQueryOrderArgs() { - String stmt = config.get("db.statements.select-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - List rows = tx - .query(stmt, POKEMONS.get(7).getName()) - .toList(); - tx.commit(); - verifyPokemon(rows, POKEMONS.get(7)); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionUpdateIT.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionUpdateIT.java deleted file mode 100644 index c39f3a57910..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionUpdateIT.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.tests; - -import java.lang.System.Logger.Level; -import java.util.HashMap; -import java.util.Map; - -import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbTransaction; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyInsertPokemon; -import static io.helidon.tests.integration.dbclient.common.utils.VerifyData.verifyUpdatePokemon; - -/** - * Test set of basic JDBC updates in transaction. - */ -@SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class TransactionUpdateIT { - - private static final System.Logger LOGGER = System.getLogger(TransactionUpdateIT.class.getName()); - private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 220; - private static final Map POKEMONS = new HashMap<>(); - - private final DbClient dbClient; - private final Config config; - - public TransactionUpdateIT(DbClient dbClient, Config config) { - this.dbClient = dbClient; - this.config = config; - } - - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { - POKEMONS.put(pokemon.getId(), pokemon); - long result = dbClient.execute() - .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); - } - - @BeforeAll - public static void setup(DbClient dbClient) { - try { - int curId = BASE_ID; - addPokemon(dbClient, new Pokemon(++curId, "Teddiursa", TYPES.get(1))); // BASE_ID+1 - addPokemon(dbClient, new Pokemon(++curId, "Ursaring", TYPES.get(1))); // BASE_ID+2 - addPokemon(dbClient, new Pokemon(++curId, "Slugma", TYPES.get(10))); // BASE_ID+3 - addPokemon(dbClient, new Pokemon(++curId, "Magcargo", TYPES.get(6), TYPES.get(10))); // BASE_ID+4 - addPokemon(dbClient, new Pokemon(++curId, "Lotad", TYPES.get(11), TYPES.get(12))); // BASE_ID+5 - addPokemon(dbClient, new Pokemon(++curId, "Lombre", TYPES.get(11), TYPES.get(12))); // BASE_ID+6 - addPokemon(dbClient, new Pokemon(++curId, "Ludicolo", TYPES.get(11), TYPES.get(12))); // BASE_ID+7 - } catch (Exception ex) { - LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex)); - throw ex; - } - } - - /** - * Verify {@code createNamedUpdate(String, String)} API method with named parameters. - */ - @Test - public void testCreateNamedUpdateStrStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 1); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 1, "Ursaring", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-named-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createNamedUpdate("update-spearow", stmt) - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) - .execute(); - tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createNamedUpdate(String)} API method with named parameters. - */ - @Test - public void testCreateNamedUpdateStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 2); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 2, "Teddiursa", srcPokemon.getTypesArray()); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createNamedUpdate("update-pokemon-named-arg") - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) - .execute(); - tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createNamedUpdate(String)} API method with ordered parameters. - */ - @Test - public void testCreateNamedUpdateStrOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 3); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 3, "Magcargo", srcPokemon.getTypesArray()); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createNamedUpdate("update-pokemon-order-arg") - .addParam(updatedPokemon.getName()).addParam(updatedPokemon.getId()) - .execute(); - tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createUpdate(String)} API method with named parameters. - */ - @Test - public void testCreateUpdateNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 4); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 4, "Slugma", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-named-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createUpdate(stmt) - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) - .execute(); - tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code createUpdate(String)} API method with ordered parameters. - */ - @Test - public void testCreateUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 5); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 5, "Lombre", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .createUpdate(stmt) - .addParam(updatedPokemon.getName()).addParam(updatedPokemon.getId()) - .execute(); - tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code namedUpdate(String)} API method with named parameters. - */ - @Test - public void testNamedUpdateNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 6); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 6, "Ludicolo", srcPokemon.getTypesArray()); - DbTransaction tx = dbClient.transaction(); - long result = tx - .namedUpdate("update-pokemon-order-arg", updatedPokemon.getName(), updatedPokemon.getId()); - tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } - - /** - * Verify {@code update(String)} API method with ordered parameters. - */ - @Test - public void testUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 7); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 7, "Lotad", srcPokemon.getTypesArray()); - String stmt = config.get("db.statements.update-pokemon-order-arg").asString().get(); - DbTransaction tx = dbClient.transaction(); - long result = tx - .update(stmt, updatedPokemon.getName(), updatedPokemon.getId()); - tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/MapperProvider.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/MapperProvider.java deleted file mode 100644 index 53dd69928f9..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/MapperProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.utils; - -import java.util.Optional; - -import io.helidon.dbclient.DbMapper; -import io.helidon.dbclient.spi.DbMapperProvider; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.model.Pokemon.PokemonMapper; - -/** - * Mapper provider used in integration tests. - */ -public class MapperProvider implements DbMapperProvider { - - @Override - @SuppressWarnings("unchecked") - public Optional> mapper(Class type) { - if (type.equals(RangePoJo.class)) { - return Optional.of((DbMapper) RangePoJo.Mapper.INSTANCE); - } else if (type.equals(Pokemon.class)) { - return Optional.of((DbMapper) PokemonMapper.INSTANCE); - } - return Optional.empty(); - } -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/RangePoJo.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/RangePoJo.java deleted file mode 100644 index 9812440fef6..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/RangePoJo.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.utils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import io.helidon.dbclient.DbMapper; -import io.helidon.dbclient.DbRow; - -/** - * POJO used to define {@code Pokemon} IDs range in query statement tests. - */ -public class RangePoJo { - - public static final class Mapper implements DbMapper { - - public static final Mapper INSTANCE = new Mapper(); - - @Override - public RangePoJo read(DbRow row) { - throw new UnsupportedOperationException("Read operation is not implemented."); - } - - @Override - public Map toNamedParameters(RangePoJo value) { - Map params = new HashMap<>(2); - params.put("idmin", value.getIdMin()); - params.put("idmax", value.getIdMax()); - return params; - } - - @Override - public List toIndexedParameters(RangePoJo value) { - List params = new ArrayList<>(2); - params.add(value.getIdMin()); - params.add(value.getIdMax()); - return params; - } - - } - - /** Beginning of IDs range. */ - private final int idMin; - /** End of IDs range. */ - private final int idMax; - - /** - * Creates an instance of Range POJO. - * - * @param idMin beginning of IDs range - * @param idMax end of IDs range - */ - public RangePoJo(int idMin, int idMax) { - this.idMin = idMin; - this.idMax = idMax; - } - - /** - * Get beginning of IDs range. - * - * @return beginning of IDs range - */ - public int getIdMin() { - return idMin; - } - - /** - * Get end of IDs range. - * - * @return end of IDs range - */ - public int getIdMax() { - return idMax; - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/TestConfig.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/TestConfig.java deleted file mode 100644 index 55315375cbf..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/TestConfig.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.utils; - -import java.lang.System.Logger.Level; - -/** - * Configuration utilities. - */ -public class TestConfig { - - /** Last used id in {@code Pokemon} table. */ - public static final int LAST_POKEMON_ID = 1000; - - private static final System.Logger LOGGER = System.getLogger(TestConfig.class.getName()); - private static final String CONFIG_PROPERTY_NAME = "io.helidon.tests.integration.dbclient.config"; - private static final String DEFAULT_CONFIG_FILE = "test.yaml"; - - /** - * Retrieve configuration file from {@code io.helidon.tests.integration.dbclient.config} - * property if exists. - * Default {@code test.yaml} value is used when no property is set. - * - * @return tests configuration file name - */ - public static String configFile() { - String configFile = System.getProperty(CONFIG_PROPERTY_NAME, DEFAULT_CONFIG_FILE); - LOGGER.log(Level.DEBUG, () -> String.format("Configuration file: %s", configFile)); - return configFile; - } - -} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/VerifyData.java b/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/VerifyData.java deleted file mode 100644 index 31f0c19ec71..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/VerifyData.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.common.utils; - -import java.lang.System.Logger.Level; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Stream; - -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; - -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.notNullValue; - -/** - * Test utilities. - */ -public class VerifyData { - - private static final System.Logger LOGGER = System.getLogger(VerifyData.class.getName()); - - private VerifyData() { - } - - /** - * Verify that the given rows contain data 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(Stream rows, int idMin, int idMax) { - // Build Map of valid data - Map valid = range(idMin, idMax); - - // Compare result with valid data - assertThat(rows, notNullValue()); - List rowsList = rows.toList(); - assertThat(rowsList, hasSize(valid.size())); - for (DbRow row : rowsList) { - Integer id = row.column(1).get(Integer.class); - String name = row.column(2).get(String.class); - LOGGER.log(Level.INFO, () -> String.format("Pokemon id=%d, name=%s", id, name)); - assertThat(valid.containsKey(id), equalTo(true)); - assertThat(name, equalTo(valid.get(id).getName())); - } - } - - /** - * Verify that the given row contains single data matching specified IDs range. - * - * @param maybeRow database query result to verify - * @param idMin beginning of ID range - * @param idMax end of ID range - */ - public static void verifyPokemonsIdRange(Optional maybeRow, int idMin, int idMax) { - Map valid = range(idMin, idMax); - assertThat(maybeRow.isPresent(), equalTo(true)); - DbRow row = maybeRow.get(); - Integer id = row.column(1).get(Integer.class); - String name = row.column(2).get(String.class); - assertThat(valid.containsKey(id), equalTo(true)); - assertThat(name, equalTo(valid.get(id).getName())); - } - - /** - * Verify that the given rows contain single record with expected data. - * - * @param rows database query result to verify - * @param expected data to compare with - */ - public static void verifyPokemon(List rows, Pokemon expected) { - assertThat(rows, notNullValue()); - assertThat(rows, hasSize(1)); - DbRow row = rows.get(0); - Integer id = row.column(1).get(Integer.class); - String name = row.column(2).get(String.class); - assertThat(id, equalTo(expected.getId())); - assertThat(name, expected.getName().equals(name)); - } - - /** - * Verify that the given rows contain single record with expected data. - * - * @param rows database query result to verify - * @param pokemon data to compare with - */ - public static void verifyPokemon(Stream rows, Pokemon pokemon) { - assertThat(rows, notNullValue()); - verifyPokemon(rows.toList(), pokemon); - } - - /** - * Verify that the given row contains single record with expected data. - * - * @param maybeRow database query result to verify - * @param expected data to compare with - */ - public static void verifyPokemon(Optional maybeRow, Pokemon expected) { - assertThat(maybeRow.isPresent(), equalTo(true)); - DbRow row = maybeRow.get(); - Integer id = row.column(1).get(Integer.class); - String name = row.column(2).get(String.class); - assertThat(id, equalTo(expected.getId())); - assertThat(name, expected.getName().equals(name)); - } - - /** - * Verify that the given data contains single record with expected data. - * - * @param actual database query result - * @param expected data to compare with - */ - public static void verifyPokemon(Pokemon actual, Pokemon expected) { - assertThat(actual.getId(), equalTo(expected.getId())); - assertThat(actual.getName(), equalTo(expected.getName())); - } - - /** - * Verify that provided data was successfully inserted into the database. - * - * @param dbClient database client - * @param result DML statement result - * @param data data to compare with - */ - public static void verifyInsertPokemon(DbClient dbClient, long result, Pokemon data) { - assertThat(result, equalTo(1L)); - Optional maybeRow = dbClient.execute() - .namedGet("select-pokemon-by-id", data.getId()); - - assertThat(maybeRow.isPresent(), equalTo(true)); - DbRow row = maybeRow.get(); - Integer id = row.column("id").get(Integer.class); - String name = row.column("name").get(String.class); - assertThat(id, equalTo(data.getId())); - assertThat(name, data.getName().equals(name)); - } - - /** - * Verify that provided data was successfully updated in the database. - * - * @param dbClient database client - * @param result DML statement result - * @param data data to compare with - */ - public static void verifyUpdatePokemon(DbClient dbClient, long result, Pokemon data) { - assertThat(result, equalTo(1L)); - Optional maybeRow = dbClient.execute() - .namedGet("select-pokemon-by-id", data.getId()); - verifyPokemon(maybeRow, data); - } - - /** - * Verify that provided data was successfully deleted from the database. - * - * @param dbClient database client - * @param result DML statement result - * @param expected data to compare with - */ - public static void verifyDeletePokemon(DbClient dbClient, long result, Pokemon expected) { - assertThat(result, equalTo(1L)); - Optional maybeRow = dbClient.execute() - .namedGet("select-pokemon-by-id", expected.getId()); - assertThat(maybeRow.isPresent(), equalTo(false)); - } - - private static Map range(int idMin, int idMax) { - Map map = new HashMap<>(POKEMONS.size()); - for (Map.Entry entry : POKEMONS.entrySet()) { - int id = entry.getKey(); - Pokemon pokemon = entry.getValue(); - if (id > idMin && id < idMax) { - map.put(id, pokemon); - } - } - return map; - } -} diff --git a/tests/integration/dbclient/common/src/main/java/module-info.java b/tests/integration/dbclient/common/src/main/java/module-info.java deleted file mode 100644 index 23fca963da9..00000000000 --- a/tests/integration/dbclient/common/src/main/java/module-info.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Helidon Database Client Integration Tests. - */ -module io.helidon.tests.integration.dbclient.common { - - requires org.junit.jupiter.api; - requires java.net.http; - requires jakarta.json; - requires hamcrest.all; - - requires io.helidon.common; - requires io.helidon.config; - requires io.helidon.dbclient; - requires io.helidon.dbclient.metrics; - requires io.helidon.webserver; - requires io.helidon.webserver.observe; - requires io.helidon.dbclient.health; - requires io.helidon.health; - requires io.helidon.webserver.observe.health; - - exports io.helidon.tests.integration.dbclient.common.spi; - exports io.helidon.tests.integration.dbclient.common.tests; - exports io.helidon.tests.integration.dbclient.common.utils; - exports io.helidon.tests.integration.dbclient.common.model; - - uses io.helidon.tests.integration.dbclient.common.spi.SetupProvider; - - provides io.helidon.dbclient.spi.DbMapperProvider - with io.helidon.tests.integration.dbclient.common.utils.MapperProvider; -} \ No newline at end of file diff --git a/tests/integration/harness/src/main/resources/META-INF/services/org.junit.jupiter.api.extension.Extension b/tests/integration/dbclient/common/src/main/resources/META-INF/services/io.helidon.common.mapper.spi.MapperProvider similarity index 77% rename from tests/integration/harness/src/main/resources/META-INF/services/org.junit.jupiter.api.extension.Extension rename to tests/integration/dbclient/common/src/main/resources/META-INF/services/io.helidon.common.mapper.spi.MapperProvider index 7ab5e9f9c7a..c8d66006551 100644 --- a/tests/integration/harness/src/main/resources/META-INF/services/org.junit.jupiter.api.extension.Extension +++ b/tests/integration/dbclient/common/src/main/resources/META-INF/services/io.helidon.common.mapper.spi.MapperProvider @@ -1,5 +1,5 @@ # -# Copyright (c) 2023 Oracle and/or its affiliates. +# Copyright (c) 2024 Oracle and/or its affiliates. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,5 +14,4 @@ # limitations under the License. # -io.helidon.tests.integration.harness.SuiteLifeCycle -io.helidon.tests.integration.harness.SuiteParameterResolver +io.helidon.tests.integration.dbclient.common.MapperProviderImpl \ No newline at end of file diff --git a/tests/integration/dbclient/app/src/main/resources/META-INF/services/io.helidon.dbclient.spi.DbMapperProvider b/tests/integration/dbclient/common/src/main/resources/META-INF/services/io.helidon.dbclient.spi.DbMapperProvider similarity index 80% rename from tests/integration/dbclient/app/src/main/resources/META-INF/services/io.helidon.dbclient.spi.DbMapperProvider rename to tests/integration/dbclient/common/src/main/resources/META-INF/services/io.helidon.dbclient.spi.DbMapperProvider index a08ca6a9e1c..52cbfa84e0d 100644 --- a/tests/integration/dbclient/app/src/main/resources/META-INF/services/io.helidon.dbclient.spi.DbMapperProvider +++ b/tests/integration/dbclient/common/src/main/resources/META-INF/services/io.helidon.dbclient.spi.DbMapperProvider @@ -1,5 +1,5 @@ # -# Copyright (c) 2019, 2022 Oracle and/or its affiliates. +# Copyright (c) 2024 Oracle and/or its affiliates. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,4 +14,4 @@ # limitations under the License. # -io.helidon.tests.integration.dbclient.app.dbmapper.DbClientMapperProvider +io.helidon.tests.integration.dbclient.common.DbMapperProviderImpl diff --git a/tests/integration/dbclient/common/src/main/resources/db-common.yaml b/tests/integration/dbclient/common/src/main/resources/db-common.yaml new file mode 100644 index 00000000000..fffece98bde --- /dev/null +++ b/tests/integration/dbclient/common/src/main/resources/db-common.yaml @@ -0,0 +1,68 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +db: + create-schema: true + insert-dataset: true + missing-map-parameters-as-null: true + statements: + ping: "SELECT 0" + create-types: | + CREATE TABLE Types ( + id INTEGER NOT NULL PRIMARY KEY, + name VARCHAR(64) NOT NULL + ) + create-pokemons: | + CREATE TABLE Pokemons ( + id INTEGER NOT NULL PRIMARY KEY, + name VARCHAR(64) NOT NULL + ) + create-poketypes: | + CREATE TABLE PokemonTypes ( + id_pokemon INTEGER NOT NULL REFERENCES Pokemons(id) ON DELETE CASCADE, + id_type INTEGER NOT NULL REFERENCES Types(id) ON DELETE CASCADE + ) + drop-types: "DROP TABLE Types" + drop-pokemons: "DROP TABLE Pokemons" + drop-poketypes: "DROP TABLE PokemonTypes" + insert-type: "INSERT INTO Types(id, name) VALUES(?, ?)" + insert-pokemon: "INSERT INTO Pokemons(id, name) VALUES(?, ?)" + insert-poketype: "INSERT INTO PokemonTypes(id_pokemon, id_type) VALUES(?, ?)" + insert-pokemon-named-arg: "INSERT INTO Pokemons(id, name) VALUES(:id, :name)" + insert-pokemon-order-arg: "INSERT INTO Pokemons(id, name) VALUES(?, ?)" + insert-pokemon-order-arg-rev: "INSERT INTO Pokemons(name, id) VALUES(?, ?)" + update-pokemon-named-arg: "UPDATE Pokemons SET name=:name WHERE id=:id" + update-pokemon-order-arg: "UPDATE Pokemons SET name=? WHERE id=?" + delete-pokemon-named-arg: "DELETE FROM Pokemons WHERE id=:id" + delete-pokemon-order-arg: "DELETE FROM Pokemons WHERE id=?" + delete-pokemon-full-named-arg: "DELETE FROM Pokemons WHERE name=:name AND id=:id" + delete-pokemon-full-order-arg: "DELETE FROM Pokemons WHERE name=? AND id=?" + select-types: SELECT id as "id", name as "name" FROM Types + select-pokemons: SELECT id as "id", name as "name" FROM Pokemons + select-poketypes: SELECT id_pokemon as "id_pokemon", id_type as "id_type" FROM PokemonTypes p WHERE id_pokemon = ? + select-poketypes-all: SELECT id_pokemon as "id_pokemon", id_type as "id_type" FROM PokemonTypes + select-pokemon-named-arg: SELECT id as "id", name as "name" FROM Pokemons WHERE name=:name + select-pokemon-order-arg: SELECT id as "id", name as "name" FROM Pokemons WHERE name=? + select-pokemon-by-id: SELECT id as "id", name as "name" FROM Pokemons WHERE id=? + select-pokemons-idrng-named-arg: SELECT id as "id", name as "name" FROM Pokemons WHERE id > :idmin AND id < :idmax + select-pokemons-idrng-order-arg: SELECT id as "id", name as "name" FROM Pokemons WHERE id > ? AND id < ? + select-pokemons-idname-named-arg: SELECT id, name FROM Pokemons WHERE name=:name AND id=:id + select-pokemons-error-arg: SELECT id as "id", name as "name" FROM Pokemons WHERE id > :id AND name = ? + services: + metrics: + - type: TIMER + statement-types: [ "INSERT" ] + - type: COUNTER + statement-names: [ "select-pokemons", "insert-pokemon" ] diff --git a/tests/integration/dbclient/h2/README.md b/tests/integration/dbclient/h2/README.md new file mode 100644 index 00000000000..9b0ca0fe7b6 --- /dev/null +++ b/tests/integration/dbclient/h2/README.md @@ -0,0 +1,6 @@ +# DbClient Integration Test H2 + +To run this test: +```shell +mvn clean verify +``` diff --git a/tests/integration/dbclient/h2/pom.xml b/tests/integration/dbclient/h2/pom.xml index bae0df64c17..c5880b5c983 100644 --- a/tests/integration/dbclient/h2/pom.xml +++ b/tests/integration/dbclient/h2/pom.xml @@ -1,6 +1,6 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 io.helidon.tests.integration.dbclient - helidon-tests-integration-dbclient-project + helidon-tests-integration-dbclient-parent 4.1.0-SNAPSHOT - ../pom.xml + ../parent/pom.xml helidon-tests-integration-dbclient-h2 - Helidon Tests Integration Database Client H2 - - - true - + Helidon Tests Integration DbClient H2 - - io.helidon.tests.integration.dbclient - helidon-tests-integration-dbclient-common - ${project.version} - - - io.helidon.integrations.db - h2 - - - com.h2database - h2 - - - io.helidon.config - helidon-config - - - io.helidon.config - helidon-config-yaml - - - io.helidon.dbclient - helidon-dbclient - - - io.helidon.common - helidon-common-mapper - io.helidon.dbclient helidon-dbclient-jdbc - test io.helidon.dbclient - helidon-dbclient-hikari - test - - - org.slf4j - slf4j-jdk14 - test - - - org.junit.jupiter - junit-jupiter-api - test + helidon-dbclient-metrics-hikari - io.helidon.tests.integration - helidon-tests-integration-harness - ${project.version} - test + io.helidon.integrations.db + h2 - org.hamcrest - hamcrest-all - test + com.h2database + h2 - - - src/test/resources - true - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*IT - - + maven-dependency-plugin + + + copy-libs + + org.apache.maven.plugins maven-failsafe-plugin - - ${maven.test.redirectTestOutputToFile} - methods - 10 - - true - - - io.helidon.tests.integration.dbclient:helidon-tests-integration-dbclient-common - - - io.helidon.tests.integration.dbclient.common.tests.*IT - - - test - integration-test integration-test verify diff --git a/tests/integration/dbclient/h2/src/main/java/io/helidon/tests/integration/dbclient/jdbc/H2SetupProvider.java b/tests/integration/dbclient/h2/src/main/java/io/helidon/tests/integration/dbclient/jdbc/H2SetupProvider.java deleted file mode 100644 index ddb6508c451..00000000000 --- a/tests/integration/dbclient/h2/src/main/java/io/helidon/tests/integration/dbclient/jdbc/H2SetupProvider.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.jdbc; - -import java.nio.file.Paths; -import java.sql.SQLException; -import java.util.Map; - -import io.helidon.config.Config; -import io.helidon.config.ConfigSources; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbExecute; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.model.Type; -import io.helidon.tests.integration.dbclient.common.spi.SetupProvider; -import io.helidon.tests.integration.dbclient.common.tests.MapperIT; - -import org.h2.tools.Server; - -/** - * H2 database setup. - * Provides tests {@link Config} and {@link DbClient} instance for junit tests. - * Starts and initializes H2 database. - */ -public class H2SetupProvider implements SetupProvider { - - private static final System.Logger LOGGER = System.getLogger(MapperIT.class.getName()); - private static final Config CONFIG = initConfig(); - private static final int TIMEOUT = 60; - - // Start and initialize H2 database - static { - Config dbConfig = CONFIG.get("db"); - startH2(dbConfig); - DbClient dbClient = DbClient.builder(dbConfig).build(); - waitForStart(dbClient); - initSchema(dbClient); - initData(dbClient); - } - - private static Config initConfig() { - return Config.create(ConfigSources.classpath("h2.yaml")); - } - - private static void startH2(Config config) { - String password = config.get("password").asString().get(); - String port = config.get("port").asString().get(); - String database = config.get("database").asString().get(); - String baseDir = Paths.get("").toAbsolutePath().resolve("target").resolve(database).toString(); - try { - Server.main( - "-web", - "-webAllowOthers", - "-tcp", - "-tcpAllowOthers", - "-tcpAllowOthers", - "-tcpPassword", - password, - "-tcpPort", - port, - "-baseDir", - baseDir, - "-ifNotExists"); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - private static void waitForStart(DbClient dbClient) { - long endTm = 1000 * TIMEOUT + System.currentTimeMillis(); - while (true) { - try { - dbClient.execute().namedGet("ping"); - break; - } catch (Throwable th) { - if (System.currentTimeMillis() > endTm) { - throw new IllegalStateException("Database startup failed!", th); - } - LOGGER.log(System.Logger.Level.DEBUG, () -> String.format("Exception: %s", th.getMessage()), th); - try { - Thread.sleep(1000); - } catch (InterruptedException ignored) { - } - } - } - } - - private static void initSchema(DbClient dbClient) { - DbExecute exec = dbClient.execute(); - exec.namedDml("create-types"); - exec.namedDml("create-pokemons"); - exec.namedDml("create-poketypes"); - } - - private static void initData(DbClient dbClient) { - DbExecute exec = dbClient.execute(); - long count = 0; - for (Map.Entry entry : Type.TYPES.entrySet()) { - count += exec.namedInsert("insert-type", entry.getKey(), entry.getValue().name()); - } - - for (Map.Entry entry : Pokemon.POKEMONS.entrySet()) { - count += exec.namedInsert("insert-pokemon", entry.getKey(), entry.getValue().getName()); - } - - for (Map.Entry entry : Pokemon.POKEMONS.entrySet()) { - Pokemon pokemon = entry.getValue(); - for (Type type : pokemon.getTypes()) { - count += exec.namedInsert("insert-poketype", pokemon.getId(), type.id()); - } - } - LOGGER.log(System.Logger.Level.INFO, String.format("executed %s statements", count)); - } - - public H2SetupProvider() { - } - - @Override - public Config config() { - return CONFIG; - } - - @Override - public DbClient dbClient() { - return DbClient.builder(CONFIG.get("db")).build(); - } - -} diff --git a/etc/pods/pgsql.yaml b/tests/integration/dbclient/h2/src/main/resources/db.yaml similarity index 60% rename from etc/pods/pgsql.yaml rename to tests/integration/dbclient/h2/src/main/resources/db.yaml index 0c90f063a30..2ca138590f6 100644 --- a/etc/pods/pgsql.yaml +++ b/tests/integration/dbclient/h2/src/main/resources/db.yaml @@ -1,5 +1,5 @@ # -# Copyright (c) 2018, 2020 Oracle and/or its affiliates. +# Copyright (c) 2024 Oracle and/or its affiliates. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,20 +14,15 @@ # limitations under the License. # -apiVersion: v1 -kind: Pod -metadata: - name: pgsql -spec: - containers: - - name: pgsql - image: postgres - ports: - - containerPort: 5432 - env: - - name: POSTGRES_USER - value: "user" - - name: POSTGRES_PASSWORD - value: "password" - - name: POSTGRES_DB - value: "pokemon" +db: + source: jdbc + connection: + url: jdbc:h2:mem:test;DATABASE_TO_UPPER=FALSE;TRACE_LEVEL_FILE=4 + username: sa + password: + poolName: test + initializationFailTimeout: -1 + connectionTimeout: 2000 + health-check: + type: query + statement: "SELECT 0" diff --git a/tests/integration/dbclient/app/src/main/resources/common.yaml b/tests/integration/dbclient/h2/src/main/resources/logging.properties similarity index 83% rename from tests/integration/dbclient/app/src/main/resources/common.yaml rename to tests/integration/dbclient/h2/src/main/resources/logging.properties index a9d5230bb30..d590b197673 100644 --- a/tests/integration/dbclient/app/src/main/resources/common.yaml +++ b/tests/integration/dbclient/h2/src/main/resources/logging.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2023 Oracle and/or its affiliates. +# Copyright (c) 2024 Oracle and/or its affiliates. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,6 +14,5 @@ # limitations under the License. # -server: - port: 0 - host: 0.0.0.0 +handlers=org.slf4j.bridge.SLF4JBridgeHandler +.level=INFO diff --git a/tests/integration/dbclient/h2/src/main/resources/simplelogger.properties b/tests/integration/dbclient/h2/src/main/resources/simplelogger.properties new file mode 100644 index 00000000000..fcc605df165 --- /dev/null +++ b/tests/integration/dbclient/h2/src/main/resources/simplelogger.properties @@ -0,0 +1,22 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +org.slf4j.simpleLogger.defaultLogLevel=warn +org.slf4j.simpleLogger.showThreadName=false +org.slf4j.simpleLogger.log.org.testcontainers=info +org.slf4j.simpleLogger.log.org.testcontainers.utility=error +org.slf4j.simpleLogger.log.io.helidon=info +org.slf4j.simpleLogger.log.org.hibernate=info +org.slf4j.simpleLogger.log.com.zaxxer=info diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2LocalTest.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2LocalTest.java new file mode 100644 index 00000000000..e94c24e87f2 --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2LocalTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import java.util.Map; +import java.util.function.BiFunction; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.tests.integration.dbclient.common.LocalTextContext; + +/** + * Base class for the local tests. + */ +abstract class H2LocalTest { + + static LocalTextContext context(BiFunction factory) { + return LocalTextContext.create(factory, Map.of(), true); + } + + static void shutdown(LocalTextContext ctx) { + try { + ctx.db().execute().dml("SHUTDOWN"); + } catch (Throwable ignored) { + } + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2MiscLocalTestIT.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2MiscLocalTestIT.java new file mode 100644 index 00000000000..8ac7b7d9426 --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2MiscLocalTestIT.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.MiscTest; +import io.helidon.tests.integration.dbclient.common.MiscTestImpl; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local misc test. + */ +final class H2MiscLocalTestIT extends H2LocalTest implements MiscTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(MiscTestImpl::new); + } + + @AfterAll + static void tearDown() { + shutdown(ctx); + } + + @Test + @Override + public void testFlowControl() { + ctx.delegate().testFlowControl(); + } + + @Test + @Override + public void testStatementInterceptor() { + ctx.delegate().testStatementInterceptor(); + } + + @Test + @Override + public void testInsertWithOrderMapping() { + ctx.delegate().testInsertWithOrderMapping(); + } + + @Test + @Override + public void testInsertWithNamedMapping() { + ctx.delegate().testInsertWithNamedMapping(); + } + + @Test + @Override + public void testUpdateWithOrderMapping() { + ctx.delegate().testUpdateWithOrderMapping(); + } + + @Test + @Override + public void testUpdateWithNamedMapping() { + ctx.delegate().testUpdateWithNamedMapping(); + } + + @Test + @Override + public void testDeleteWithOrderMapping() { + ctx.delegate().testDeleteWithOrderMapping(); + } + + @Test + @Override + public void testDeleteWithNamedMapping() { + ctx.delegate().testDeleteWithNamedMapping(); + } + + @Test + @Override + public void testQueryWithMapping() { + ctx.delegate().testQueryWithMapping(); + } + + @Test + @Override + public void testGetWithMapping() { + ctx.delegate().testGetWithMapping(); + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2MiscRemoteTestIT.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2MiscRemoteTestIT.java new file mode 100644 index 00000000000..186eea903dd --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2MiscRemoteTestIT.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import io.helidon.tests.integration.dbclient.common.MiscTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote misc test. + */ +final class H2MiscRemoteTestIT extends H2RemoteTest implements MiscTest { + + H2MiscRemoteTestIT() { + super("/test/misc"); + } + + @Test + @Override + public void testFlowControl() { + remoteTest(); + } + + @Test + @Override + public void testStatementInterceptor() { + remoteTest(); + } + + @Test + @Override + public void testInsertWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testInsertWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testUpdateWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testUpdateWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testDeleteWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testDeleteWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testQueryWithMapping() { + remoteTest(); + } + + @Test + @Override + public void testGetWithMapping() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2ObservabilityLocalTestIT.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2ObservabilityLocalTestIT.java new file mode 100644 index 00000000000..dc1b5048e0e --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2ObservabilityLocalTestIT.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import io.helidon.tests.integration.dbclient.common.DbClientITMain; +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.ObservabilityTest; +import io.helidon.tests.integration.dbclient.common.ObservabilityTestImpl; +import io.helidon.webclient.http1.Http1Client; +import io.helidon.webserver.WebServerConfig; +import io.helidon.webserver.testing.junit5.ServerTest; +import io.helidon.webserver.testing.junit5.SetUpServer; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local observability test. + */ +@ServerTest +final class H2ObservabilityLocalTestIT extends H2LocalTest implements ObservabilityTest { + + private static LocalTextContext ctx; + private static Http1Client client; + + @BeforeAll + static void beforeAll(Http1Client aClient) { + client = aClient; + } + + @SetUpServer + static void setUp(WebServerConfig.Builder builder) { + ctx = context((db, c) -> new ObservabilityTestImpl(db, c, () -> client)); + DbClientITMain.setup(ctx.db(), ctx.config(), builder); + } + + @AfterAll + static void tearDown() { + shutdown(ctx); + } + + @Test + @Override + public void testHttpHealthNoDetails() { + ctx.delegate().testHttpHealthNoDetails(); + } + + @Test + @Override + public void testHttpHealthDetails() { + ctx.delegate().testHttpHealthDetails(); + } + + @Test + @Override + public void testHttpMetrics() { + ctx.delegate().testHttpMetrics(); + } + + @Test + @Override + public void testHealthCheck() { + ctx.delegate().testHealthCheck(); + } + + @Test + @Override + public void testHealthCheckWithName() { + ctx.delegate().testHealthCheckWithName(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomNamedDML() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomDML() { + throw new UnsupportedOperationException(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedQuery() { + ctx.delegate().testHealthCheckWithCustomNamedQuery(); + } + + @Test + @Override + public void testHealthCheckWithCustomQuery() { + ctx.delegate().testHealthCheckWithCustomQuery(); + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2ObservabilityRemoteTestIT.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2ObservabilityRemoteTestIT.java new file mode 100644 index 00000000000..2a33a6f8536 --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2ObservabilityRemoteTestIT.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import io.helidon.tests.integration.dbclient.common.ObservabilityTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote observability test. + */ +final class H2ObservabilityRemoteTestIT extends H2RemoteTest implements ObservabilityTest { + + H2ObservabilityRemoteTestIT() { + super("/test/observability"); + } + + @Test + @Override + public void testHttpHealthNoDetails() { + remoteTest(); + } + + @Test + @Override + public void testHttpHealthDetails() { + remoteTest(); + } + + @Test + @Override + public void testHttpMetrics() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheck() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithName() { + remoteTest(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomNamedDML() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomDML() { + throw new UnsupportedOperationException(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedQuery() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithCustomQuery() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2RemoteTest.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2RemoteTest.java new file mode 100644 index 00000000000..c1eefb87c44 --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2RemoteTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import java.nio.file.Path; +import java.util.Map; + +import io.helidon.tests.integration.dbclient.common.RemoteTest; +import io.helidon.tests.integration.harness.ProcessRunner; +import io.helidon.tests.integration.harness.ProcessRunner.ExecMode; +import io.helidon.tests.integration.harness.WaitStrategy; +import io.helidon.tests.integration.harness.TestProcess; +import io.helidon.tests.integration.harness.TestProcesses; + +/** + * Base class for the remote tests. + */ +@TestProcesses +abstract class H2RemoteTest extends RemoteTest { + + @TestProcess + static final ProcessRunner PROCESS_RUNNER = ProcessRunner.of(ExecMode.CLASS_PATH) + .finalName("helidon-tests-integration-dbclient-h2") + .properties(Map.of("java.util.logging.config.file", Path.of("target/classes/logging.properties").toAbsolutePath())) + .waitingFor(WaitStrategy.waitForPort()); + + /** + * Create a new instance. + * + * @param path base path + */ + @SuppressWarnings("resource") + H2RemoteTest(String path) { + super(path, PROCESS_RUNNER.process().port()); + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2SimpleLocalTestIT.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2SimpleLocalTestIT.java new file mode 100644 index 00000000000..c11f2c8b9e5 --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2SimpleLocalTestIT.java @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.SimpleTest; +import io.helidon.tests.integration.dbclient.common.SimpleTestImpl; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local simple test. + */ +final class H2SimpleLocalTestIT extends H2LocalTest implements SimpleTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(SimpleTestImpl::new); + } + + @AfterAll + static void tearDown() { + shutdown(ctx); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + ctx.delegate().testCreateDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + ctx.delegate().testCreateDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + ctx.delegate().testNamedDeleteOrderArgs(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + ctx.delegate().testDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithInsertNamedArgs() { + ctx.delegate().testCreateDmlWithInsertNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithInsertOrderArgs() { + ctx.delegate().testCreateDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithInsertOrderArgs() { + ctx.delegate().testNamedDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testDmlWithInsertOrderArgs() { + ctx.delegate().testDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithUpdateNamedArgs() { + ctx.delegate().testCreateDmlWithUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithUpdateOrderArgs() { + ctx.delegate().testCreateDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithUpdateOrderArgs() { + ctx.delegate().testNamedDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testDmlWithUpdateOrderArgs() { + ctx.delegate().testDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithDeleteNamedArgs() { + ctx.delegate().testCreateDmlWithDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithDeleteOrderArgs() { + ctx.delegate().testCreateDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithDeleteOrderArgs() { + ctx.delegate().testNamedDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testDmlWithDeleteOrderArgs() { + ctx.delegate().testDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + ctx.delegate().testCreateNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + ctx.delegate().testCreateGetNamedArgs(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + ctx.delegate().testCreateGetOrderArgs(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + ctx.delegate().testNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + ctx.delegate().testGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + ctx.delegate().testCreateNamedInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + ctx.delegate().testCreateInsertNamedArgs(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + ctx.delegate().testCreateInsertOrderArgs(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + ctx.delegate().testNamedInsertOrderArgs(); + } + + @Test + @Override + public void testInsertOrderArgs() { + ctx.delegate().testInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + ctx.delegate().testCreateNamedQueryStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrOrderArgs(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + ctx.delegate().testCreateQueryNamedArgs(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + ctx.delegate().testCreateQueryOrderArgs(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + ctx.delegate().testNamedQueryOrderArgs(); + } + + @Test + @Override + public void testQueryOrderArgs() { + ctx.delegate().testQueryOrderArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + ctx.delegate().testCreateUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + ctx.delegate().testCreateUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + ctx.delegate().testNamedUpdateNamedArgs(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + ctx.delegate().testUpdateOrderArgs(); + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2SimpleRemoteTestIT.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2SimpleRemoteTestIT.java new file mode 100644 index 00000000000..17073783943 --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2SimpleRemoteTestIT.java @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import io.helidon.tests.integration.dbclient.common.SimpleTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote simple test. + */ +final class H2SimpleRemoteTestIT extends H2RemoteTest implements SimpleTest { + + H2SimpleRemoteTestIT() { + super("/test/simple"); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2StatementLocalTestIT.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2StatementLocalTestIT.java new file mode 100644 index 00000000000..e99d7e380b5 --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2StatementLocalTestIT.java @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.StatementTest; +import io.helidon.tests.integration.dbclient.common.StatementTestImpl; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local statement test. + */ +final class H2StatementLocalTestIT extends H2LocalTest implements StatementTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(StatementTestImpl::new); + } + + @AfterAll + static void tearDown() { + shutdown(ctx); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + ctx.delegate().testCreateNamedQueryNonExistentStmt(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + ctx.delegate().testCreateNamedQueryNamedArgsSetOrderArg(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + ctx.delegate().testCreateNamedQueryOrderArgsSetNamedArg(); + } + + @Test + @Override + public void testGetArrayParams() { + ctx.delegate().testGetArrayParams(); + } + + @Test + @Override + public void testGetListParams() { + ctx.delegate().testGetListParams(); + } + + @Test + @Override + public void testGetMapParams() { + ctx.delegate().testGetMapParams(); + } + + @Test + @Override + public void testGetOrderParam() { + ctx.delegate().testGetOrderParam(); + } + + @Test + @Override + public void testGetNamedParam() { + ctx.delegate().testGetNamedParam(); + } + + @Test + @Override + public void testGetMappedNamedParam() { + ctx.delegate().testGetMappedNamedParam(); + } + + @Test + @Override + public void testGetMappedOrderParam() { + ctx.delegate().testGetMappedOrderParam(); + } + + @Test + @Override + public void testQueryArrayParams() { + ctx.delegate().testQueryArrayParams(); + } + + @Test + @Override + public void testQueryListParams() { + ctx.delegate().testQueryListParams(); + } + + @Test + @Override + public void testQueryMapParams() { + ctx.delegate().testQueryMapParams(); + } + + @Test + @Override + public void testQueryMapMissingParams() { + ctx.delegate().testQueryMapMissingParams(); + } + + @Test + @Override + public void testQueryOrderParam() { + ctx.delegate().testQueryOrderParam(); + } + + @Test + @Override + public void testQueryNamedParam() { + ctx.delegate().testQueryNamedParam(); + } + + @Test + @Override + public void testQueryMappedNamedParam() { + ctx.delegate().testQueryMappedNamedParam(); + } + + @Test + @Override + public void testQueryMappedOrderParam() { + ctx.delegate().testQueryMappedOrderParam(); + } + + @Test + @Override + public void testDmlArrayParams() { + ctx.delegate().testDmlArrayParams(); + } + + @Test + @Override + public void testDmlListParams() { + ctx.delegate().testDmlListParams(); + } + + @Test + @Override + public void testDmlMapParams() { + ctx.delegate().testDmlMapParams(); + } + + @Test + @Override + public void testDmlOrderParam() { + ctx.delegate().testDmlOrderParam(); + } + + @Test + @Override + public void testDmlNamedParam() { + ctx.delegate().testDmlNamedParam(); + } + + @Test + @Override + public void testDmlMappedNamedParam() { + ctx.delegate().testDmlMappedNamedParam(); + } + + @Test + @Override + public void testDmlMappedOrderParam() { + ctx.delegate().testDmlMappedOrderParam(); + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2StatementRemoteTestIT.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2StatementRemoteTestIT.java new file mode 100644 index 00000000000..f18997d2650 --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2StatementRemoteTestIT.java @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import io.helidon.tests.integration.dbclient.common.StatementTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote statement test. + */ +final class H2StatementRemoteTestIT extends H2RemoteTest implements StatementTest { + + H2StatementRemoteTestIT() { + super("/test/statement"); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + remoteTest(); + } + + @Test + @Override + public void testGetArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testGetListParams() { + remoteTest(); + } + + @Test + @Override + public void testGetMapParams() { + remoteTest(); + } + + @Test + @Override + public void testGetOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testGetNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testGetMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testGetMappedOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryListParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryMapParams() { + remoteTest(); + } + + @Override + public void testQueryMapMissingParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryMappedOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlListParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlMapParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlMappedOrderParam() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2TransactionLocalTestIT.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2TransactionLocalTestIT.java new file mode 100644 index 00000000000..92e36d1cafe --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2TransactionLocalTestIT.java @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.TransactionTest; +import io.helidon.tests.integration.dbclient.common.TransactionTestImpl; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local transaction test. + */ +final class H2TransactionLocalTestIT extends H2LocalTest implements TransactionTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(TransactionTestImpl::new); + } + + @AfterAll + static void tearDown() { + shutdown(ctx); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + ctx.delegate().testCreateDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + ctx.delegate().testCreateDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + ctx.delegate().testNamedDeleteOrderArgs(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + ctx.delegate().testDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + ctx.delegate().testCreateNamedQueryNonExistentStmt(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + ctx.delegate().testCreateNamedQueryNamedArgsSetOrderArg(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + ctx.delegate().testCreateNamedQueryOrderArgsSetNamedArg(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + ctx.delegate().testCreateNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + ctx.delegate().testCreateGetNamedArgs(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + ctx.delegate().testCreateGetOrderArgs(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + ctx.delegate().testNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + ctx.delegate().testGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + ctx.delegate().testCreateNamedInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + ctx.delegate().testCreateInsertNamedArgs(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + ctx.delegate().testCreateInsertOrderArgs(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + ctx.delegate().testNamedInsertOrderArgs(); + } + + @Test + @Override + public void testInsertOrderArgs() { + ctx.delegate().testInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + ctx.delegate().testCreateNamedQueryStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrOrderArgs(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + ctx.delegate().testCreateQueryNamedArgs(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + ctx.delegate().testCreateQueryOrderArgs(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + ctx.delegate().testNamedQueryOrderArgs(); + } + + @Test + @Override + public void testQueryOrderArgs() { + ctx.delegate().testQueryOrderArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + ctx.delegate().testCreateUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + ctx.delegate().testCreateUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + ctx.delegate().testNamedUpdateNamedArgs(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + ctx.delegate().testUpdateOrderArgs(); + } +} diff --git a/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2TransactionRemoteTestIT.java b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2TransactionRemoteTestIT.java new file mode 100644 index 00000000000..be12d2c9692 --- /dev/null +++ b/tests/integration/dbclient/h2/src/test/java/io/helidon/tests/integration/dbclient/h2/H2TransactionRemoteTestIT.java @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.h2; + +import io.helidon.tests.integration.dbclient.common.TransactionTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote transaction test. + */ +final class H2TransactionRemoteTestIT extends H2RemoteTest implements TransactionTest { + + H2TransactionRemoteTestIT() { + super("/test/transaction"); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/h2/src/test/resources/h2.yaml b/tests/integration/dbclient/h2/src/test/resources/h2.yaml deleted file mode 100644 index 8e8ab7dc122..00000000000 --- a/tests/integration/dbclient/h2/src/test/resources/h2.yaml +++ /dev/null @@ -1,63 +0,0 @@ -# -# Copyright (c) 2019, 2024 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -db: - source: jdbc - host: "localhost" - port: 9092 - password: "password" - database: "test" - missing-map-parameters-as-null: true - connection: - url: jdbc:h2:tcp://${db.host}:${db.port}/${db.database};DATABASE_TO_UPPER=FALSE - health-check: - type: query - statement: "SELECT 0" - statements: - ping: "SELECT 0" - ping-query: "SELECT 0" - create-types: "CREATE TABLE Types (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(64) NOT NULL)" - create-pokemons: "CREATE TABLE Pokemons (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(64) NOT NULL)" - create-poketypes: "CREATE TABLE PokemonTypes (id_pokemon INTEGER NOT NULL REFERENCES Pokemons(id), id_type INTEGER NOT NULL REFERENCES Types(id))" - drop-types: "DROP TABLE Types" - drop-pokemons: "DROP TABLE Pokemons" - drop-poketypes: "DROP TABLE PokemonTypes" - insert-type: "INSERT INTO Types(id, name) VALUES(?, ?)" - insert-pokemon: "INSERT INTO Pokemons(id, name) VALUES(?, ?)" - insert-poketype: "INSERT INTO PokemonTypes(id_pokemon, id_type) VALUES(?, ?)" - select-types: "SELECT id, name FROM Types" - select-pokemons: "SELECT id, name FROM Pokemons" - select-poketypes: "SELECT id_pokemon, id_type FROM PokemonTypes p WHERE id_pokemon = ?" - select-poketypes-all: "SELECT id_pokemon, id_type FROM PokemonTypes" - select-max-id: "SELECT MAX(id) FROM Pokemons" - select-pokemon-named-arg: "SELECT id, name FROM Pokemons WHERE name=:name" - select-pokemon-order-arg: "SELECT id, name FROM Pokemons WHERE name=?" - insert-pokemon-named-arg: "INSERT INTO Pokemons(id, name) VALUES(:id, :name)" - insert-pokemon-order-arg: "INSERT INTO Pokemons(id, name) VALUES(?, ?)" - insert-pokemon-order-arg-rev: "INSERT INTO Pokemons(name, id) VALUES(?, ?)" - select-pokemon-by-id: "SELECT id, name FROM Pokemons WHERE id=?" - update-pokemon-named-arg: "UPDATE Pokemons SET name=:name WHERE id=:id" - update-pokemon-order-arg: "UPDATE Pokemons SET name=? WHERE id=?" - delete-pokemon-named-arg: "DELETE FROM Pokemons WHERE id=:id" - delete-pokemon-order-arg: "DELETE FROM Pokemons WHERE id=?" - delete-pokemon-full-named-arg: "DELETE FROM Pokemons WHERE name=:name AND id=:id" - delete-pokemon-full-order-arg: "DELETE FROM Pokemons WHERE name=? AND id=?" - select-pokemons-idrng-named-arg: "SELECT id, name FROM Pokemons WHERE id > :idmin AND id < :idmax" - select-pokemons-idrng-order-arg: "SELECT id, name FROM Pokemons WHERE id > ? AND id < ?" - select-pokemons-error-arg: "SELECT id, name FROM Pokemons WHERE id > :id AND name = ?" - select-pokemons-idname-named-arg: "SELECT id, name FROM Pokemons WHERE name=:name AND id=:id" - -test: - ping-dml: false diff --git a/tests/integration/dbclient/mongodb/README.md b/tests/integration/dbclient/mongodb/README.md new file mode 100644 index 00000000000..cbc29d04ab9 --- /dev/null +++ b/tests/integration/dbclient/mongodb/README.md @@ -0,0 +1,22 @@ +# DbClient Integration Test MongoDB + +To run this test: +```shell +mvn clean verify +``` + +Build the Docker image: +```shell +docker build etc/docker -t mongodb +``` + +Start the database: +```shell +docker run -d \ + --name mongodb \ + -e MONGO_DB=pokemon \ + -e MONGO_USER=test \ + -e MONGO_PASSWORD=mongo123 \ + -p 27017:27017 \ + mongodb +``` diff --git a/tests/integration/dbclient/mongodb/etc/docker/Dockerfile b/tests/integration/dbclient/mongodb/etc/docker/Dockerfile new file mode 100644 index 00000000000..0068a00ad6d --- /dev/null +++ b/tests/integration/dbclient/mongodb/etc/docker/Dockerfile @@ -0,0 +1,26 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +FROM oraclelinux:9-slim + +ADD mongodb-org-7.0.repo /etc/yum.repos.d/ +RUN microdnf install mongodb-org -y && microdnf clean all +ADD entrypoint.sh /usr/local/bin/ + +ENTRYPOINT ["entrypoint.sh"] +STOPSIGNAL SIGINT +EXPOSE 27017 +CMD ["mongod"] diff --git a/tests/integration/dbclient/mongodb/etc/docker/entrypoint.sh b/tests/integration/dbclient/mongodb/etc/docker/entrypoint.sh new file mode 100755 index 00000000000..25f2c935fea --- /dev/null +++ b/tests/integration/dbclient/mongodb/etc/docker/entrypoint.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +set -Eeom pipefail + +mkdir -p /data/db + +# redirect stdout and stderr and stderr to log file +: > /var/log/mongodb/mongod.log +exec 2> >(tee -a /var/log/mongodb/mongod.log >&2) > >(tee -a /var/log/mongodb/mongod.log) + +# Add argument +args=("${@}") +args+=("--bind_ip_all") + +# start in the background +exec "${args[@]}" & + +# wait for started +while true ; do + grep "mongod startup complete" /var/log/mongodb/mongod.log > /dev/null && break + sleep 2 +done + +echo "Initializing database..." +mongosh --host 127.0.0.1 --port 27017 --quiet admin <<-EOJS + use ${MONGO_DB:-test} + db.createUser({ + user: "${MONGO_USER:-test}", + pwd: "${MONGO_PASSWORD:-test123}", + roles: [{role: "readWrite", db: "${MONGO_DB:-test}"}] + }) +EOJS + +echo "Container ready!" +fg diff --git a/tests/integration/dbclient/mongodb/etc/docker/mongodb-org-7.0.repo b/tests/integration/dbclient/mongodb/etc/docker/mongodb-org-7.0.repo new file mode 100644 index 00000000000..388ee53c357 --- /dev/null +++ b/tests/integration/dbclient/mongodb/etc/docker/mongodb-org-7.0.repo @@ -0,0 +1,6 @@ +[mongodb-org-7.0] +name=MongoDB Repository +baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/7.0/x86_64/ +gpgcheck=1 +enabled=1 +gpgkey=https://pgp.mongodb.com/server-7.0.asc diff --git a/tests/integration/dbclient/mongodb/pom.xml b/tests/integration/dbclient/mongodb/pom.xml index 9ece9d7fe3b..676b1d57dc2 100644 --- a/tests/integration/dbclient/mongodb/pom.xml +++ b/tests/integration/dbclient/mongodb/pom.xml @@ -16,113 +16,48 @@ --> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 io.helidon.tests.integration.dbclient - helidon-tests-integration-dbclient-project + helidon-tests-integration-dbclient-parent 4.1.0-SNAPSHOT - ../pom.xml + ../parent/pom.xml helidon-tests-integration-dbclient-mongodb - Helidon Tests Integration Database Client MongoDB - - - 27017 - 127.0.0.1 - test - helidon - h3l1d0n - root - I4mGr00t - true - + Helidon Tests Integration DbClient MongoDB - - io.helidon.tests.integration.dbclient - helidon-tests-integration-dbclient-common - ${project.version} - test - - - io.helidon.config - helidon-config - test - - - io.helidon.config - helidon-config-yaml - test - io.helidon.dbclient helidon-dbclient-mongodb - test - - - org.junit.jupiter - junit-jupiter-api - test - - - io.helidon.tests.integration - helidon-tests-integration-harness - ${project.version} - test - - - org.hamcrest - hamcrest-all - test - - - src/test/resources - true - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*IT - - + maven-dependency-plugin + + + copy-libs + + org.apache.maven.plugins maven-failsafe-plugin - - ${maven.test.redirectTestOutputToFile} - methods - 10 - - true - - - test - integration-test integration-test verify - - - **/*SuiteIT - - - + \ No newline at end of file diff --git a/tests/integration/dbclient/mongodb/src/main/resources/db.yaml b/tests/integration/dbclient/mongodb/src/main/resources/db.yaml new file mode 100644 index 00000000000..003f8d9306b --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/main/resources/db.yaml @@ -0,0 +1,202 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +db: + create-schema: false + source: mongoDb + connection: + url: mongodb://localhost:27017/pokemon + username: test + password: mongo123 + health-check: + type: query + statement: | + { + "operation": "command", + "query": { "ping": 1 } + } + statements: + ping: | + { + "operation": "command", + "query": { ping: 1 } + } + delete-types: | + { + "collection": "types", + "operation": "delete", + "query": { } + } + delete-pokemons: | + { + "collection": "pokemons", + "operation": "delete", + "query": { } + } + delete-poketypes: | + { + "collection": "pokemon_types", + "operation": "delete", + "query": { } + } + insert-type: | + { + "collection": "types", + "value": { + "id": ?, + "type": ? + } + } + insert-pokemon: | + { + "collection": "pokemons", + "value": { + "id": ?, + "name": ? + } + } + insert-poketype: | + { + "collection": "pokemon_types", + "value": { + "id_pokemon": ?, + "id_type": ? + } + } + select-types: | + { + "collection": "types", + "projection": { id: 1, type: 1, _id: 0 }, + "query": {} + } + select-pokemons: | + { + "collection": "pokemons", + "projection": { id: 1, name: 1, _id: 0 }, + "query": {} + } + select-poketypes: | + { + "collection": "pokemon_types", + "projection": { id_pokemon: 1, id_type: 1, _id: 0 }, + "query": { id_pokemon: ? } + } + select-poketypes-all: | + { + "collection": "pokemon_types", + "projection": { id_pokemon: 1, id_type: 1, _id: 0 }, + "query": {} + } + select-pokemon-named-arg: | + { + "collection": "pokemons", + "operation": "query", + "projection": { id: 1, name: 1, _id: 0 }, + "query": { name: $name } + } + select-pokemon-order-arg: | + { + "collection": "pokemons", + "operation": "query", + "projection": { id: 1, name: 1, _id: 0 }, + "query": { name: ? } + } + insert-pokemon-named-arg: | + { + "collection": "pokemons", + "operation": "insert", + "value": { + "id": $id, + "name": $name + } + } + insert-pokemon-order-arg: | + { + "collection": "pokemons", + "operation": "insert", + "value": { + "id": ?, + "name": ? + } + } + insert-pokemon-order-arg-rev: | + { + "collection": "pokemons", + "operation": "insert", + "value": { + "name": ?, + "id": ? + } + } + select-pokemon-by-id: | + { + "collection": "pokemons", + "operation": "query", + "projection": { id: 1, name: 1, _id: 0 }, + "query": { id: ? } + } + update-pokemon-named-arg: | + { + "collection": "pokemons", + "operation": "update", + "value":{ $set: { "name": $name } }, + "query": { id: $id } + } + update-pokemon-order-arg: | + { + "collection": "pokemons", + "operation": "update", + "value":{ $set: { "name": ? } }, + "query": { id: ? } + } + delete-pokemon-named-arg: | + { + "collection": "pokemons", + "operation": "delete", + "query": { id: $id } + } + delete-pokemon-order-arg: | + { + "collection": "pokemons", + "operation": "delete", + "query": { id: ? } + } + delete-pokemon-full-named-arg: | + { + "collection": "pokemons", + "operation": "delete", + "query": { $and: [ {name: $name }, { id: $id } ] } + } + delete-pokemon-full-order-arg: | + { + "collection": "pokemons", + "operation": "delete", + "query": { $and: [ {name: ? }, { id: ? } ] } + } + select-pokemons-idrng-named-arg: | + { + "collection": "pokemons", + "operation": "query", + "projection": { id: 1, name: 1, _id: 0 }, + "query": { $and: [ { id: { $gt: $idmin } }, { id: { $lt: $idmax } } ] } + } + select-pokemons-idrng-order-arg: | + { + "collection": "pokemons", + "operation": "query", + "projection": { id: 1, name: 1, _id: 0 }, + "query": { $and: [ { id: { $gt: ? } }, { id: { $lt: ? } } ] } + } diff --git a/tests/integration/harness/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener b/tests/integration/dbclient/mongodb/src/main/resources/logging.properties similarity index 83% rename from tests/integration/harness/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener rename to tests/integration/dbclient/mongodb/src/main/resources/logging.properties index a0b19044e6f..d590b197673 100644 --- a/tests/integration/harness/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener +++ b/tests/integration/dbclient/mongodb/src/main/resources/logging.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2023 Oracle and/or its affiliates. +# Copyright (c) 2024 Oracle and/or its affiliates. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,4 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -io.helidon.tests.integration.harness.SuiteFinder + +handlers=org.slf4j.bridge.SLF4JBridgeHandler +.level=INFO diff --git a/tests/integration/dbclient/mongodb/src/main/resources/simplelogger.properties b/tests/integration/dbclient/mongodb/src/main/resources/simplelogger.properties new file mode 100644 index 00000000000..fcc605df165 --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/main/resources/simplelogger.properties @@ -0,0 +1,22 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +org.slf4j.simpleLogger.defaultLogLevel=warn +org.slf4j.simpleLogger.showThreadName=false +org.slf4j.simpleLogger.log.org.testcontainers=info +org.slf4j.simpleLogger.log.org.testcontainers.utility=error +org.slf4j.simpleLogger.log.io.helidon=info +org.slf4j.simpleLogger.log.org.hibernate=info +org.slf4j.simpleLogger.log.com.zaxxer=info diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBLocalTest.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBLocalTest.java new file mode 100644 index 00000000000..4e15519ade5 --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBLocalTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import java.util.function.BiFunction; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.tests.integration.dbclient.common.LocalTextContext; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Base class for the local tests. + */ +@Testcontainers(disabledWithoutDocker = true) +abstract class MongoDBLocalTest { + + @Container + static final GenericContainer CONTAINER = MongoDBTestContainer.CONTAINER; + + static LocalTextContext context(BiFunction factory) { + return LocalTextContext.create(factory, MongoDBTestContainer.config(), false); + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBMiscLocalTestIT.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBMiscLocalTestIT.java new file mode 100644 index 00000000000..a24521e7eef --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBMiscLocalTestIT.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.MiscTest; +import io.helidon.tests.integration.dbclient.common.MiscTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local misc test. + */ +final class MongoDBMiscLocalTestIT extends MongoDBLocalTest implements MiscTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(MiscTestImpl::new); + } + + @Test + @Override + public void testFlowControl() { + ctx.delegate().testFlowControl(); + } + + @Test + @Override + public void testStatementInterceptor() { + ctx.delegate().testStatementInterceptor(); + } + + @Test + @Override + public void testInsertWithOrderMapping() { + ctx.delegate().testInsertWithOrderMapping(); + } + + @Test + @Override + public void testInsertWithNamedMapping() { + ctx.delegate().testInsertWithNamedMapping(); + } + + @Test + @Override + public void testUpdateWithOrderMapping() { + ctx.delegate().testUpdateWithOrderMapping(); + } + + @Test + @Override + public void testUpdateWithNamedMapping() { + ctx.delegate().testUpdateWithNamedMapping(); + } + + @Test + @Override + public void testDeleteWithOrderMapping() { + ctx.delegate().testDeleteWithOrderMapping(); + } + + @Test + @Override + public void testDeleteWithNamedMapping() { + ctx.delegate().testDeleteWithNamedMapping(); + } + + @Test + @Override + public void testQueryWithMapping() { + ctx.delegate().testQueryWithMapping(); + } + + @Test + @Override + public void testGetWithMapping() { + ctx.delegate().testGetWithMapping(); + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBMiscRemoteTestIT.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBMiscRemoteTestIT.java new file mode 100644 index 00000000000..4381fe71cc3 --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBMiscRemoteTestIT.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import io.helidon.tests.integration.dbclient.common.MiscTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote misc test. + */ +final class MongoDBMiscRemoteTestIT extends MongoDBRemoteTest implements MiscTest { + + MongoDBMiscRemoteTestIT() { + super("/test/misc"); + } + + @Test + @Override + public void testFlowControl() { + remoteTest(); + } + + @Test + @Override + public void testStatementInterceptor() { + remoteTest(); + } + + @Test + @Override + public void testInsertWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testInsertWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testUpdateWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testUpdateWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testDeleteWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testDeleteWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testQueryWithMapping() { + remoteTest(); + } + + @Test + @Override + public void testGetWithMapping() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBObservabilityLocalTestIT.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBObservabilityLocalTestIT.java new file mode 100644 index 00000000000..1e4ab53cd9c --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBObservabilityLocalTestIT.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import io.helidon.tests.integration.dbclient.common.DbClientITMain; +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.ObservabilityTest; +import io.helidon.tests.integration.dbclient.common.ObservabilityTestImpl; +import io.helidon.webclient.http1.Http1Client; +import io.helidon.webserver.WebServerConfig; +import io.helidon.webserver.testing.junit5.ServerTest; +import io.helidon.webserver.testing.junit5.SetUpServer; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local observability test. + */ +@ServerTest +final class MongoDBObservabilityLocalTestIT extends MongoDBLocalTest implements ObservabilityTest { + + private static Http1Client client; + private static LocalTextContext ctx; + + @BeforeAll + static void beforeAll(Http1Client aClient) { + client = aClient; + } + + @SetUpServer + static void setUp(WebServerConfig.Builder builder) { + ctx = context((db, c) -> new ObservabilityTestImpl(db, c, () -> client)); + DbClientITMain.setup(ctx.db(), ctx.config(), builder); + } + + @Test + @Override + public void testHttpHealthNoDetails() { + ctx.delegate().testHttpHealthNoDetails(); + } + + @Test + @Override + public void testHttpHealthDetails() { + ctx.delegate().testHttpHealthDetails(); + } + + @Test + @Override + public void testHttpMetrics() { + ctx.delegate().testHttpMetrics(); + } + + @Test + @Override + public void testHealthCheck() { + ctx.delegate().testHealthCheck(); + } + + @Test + @Override + public void testHealthCheckWithName() { + ctx.delegate().testHealthCheckWithName(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomNamedDML() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomDML() { + throw new UnsupportedOperationException(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedQuery() { + ctx.delegate().testHealthCheckWithCustomNamedQuery(); + } + + @Test + @Override + public void testHealthCheckWithCustomQuery() { + ctx.delegate().testHealthCheckWithCustomQuery(); + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBObservabilityRemoteTestIT.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBObservabilityRemoteTestIT.java new file mode 100644 index 00000000000..60de5ff2b46 --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBObservabilityRemoteTestIT.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import io.helidon.tests.integration.dbclient.common.ObservabilityTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote observability test. + */ +final class MongoDBObservabilityRemoteTestIT extends MongoDBRemoteTest implements ObservabilityTest { + + MongoDBObservabilityRemoteTestIT() { + super("/test/observability"); + } + + @Test + @Override + public void testHttpHealthNoDetails() { + remoteTest(); + } + + @Test + @Override + public void testHttpHealthDetails() { + remoteTest(); + } + + @Test + @Override + public void testHttpMetrics() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheck() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithName() { + remoteTest(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomNamedDML() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomDML() { + throw new UnsupportedOperationException(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedQuery() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithCustomQuery() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBRemoteTest.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBRemoteTest.java new file mode 100644 index 00000000000..edee87776c3 --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBRemoteTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import java.nio.file.Path; +import java.util.Map; + +import io.helidon.tests.integration.dbclient.common.RemoteTest; +import io.helidon.tests.integration.harness.ProcessRunner; +import io.helidon.tests.integration.harness.ProcessRunner.ExecMode; +import io.helidon.tests.integration.harness.WaitStrategy; +import io.helidon.tests.integration.harness.TestProcess; +import io.helidon.tests.integration.harness.TestProcesses; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Base class for the remote tests. + */ +@Testcontainers(disabledWithoutDocker = true) +@TestProcesses +abstract class MongoDBRemoteTest extends RemoteTest { + + @Container + static final GenericContainer CONTAINER = MongoDBTestContainer.CONTAINER; + + @TestProcess + static final ProcessRunner PROCESS_RUNNER = ProcessRunner.of(ExecMode.CLASS_PATH) + .finalName("helidon-tests-integration-dbclient-mongodb") + .properties(Map.of("java.util.logging.config.file", Path.of("target/classes/logging.properties").toAbsolutePath())) + .properties(MongoDBTestContainer::config) + .waitingFor(WaitStrategy.waitForPort()); + + /** + * Create a new instance. + * + * @param path base path + */ + @SuppressWarnings("resource") + MongoDBRemoteTest(String path) { + super(path, PROCESS_RUNNER.process().port()); + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBSimpleLocalTestIT.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBSimpleLocalTestIT.java new file mode 100644 index 00000000000..03f9e69f4c7 --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBSimpleLocalTestIT.java @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.SimpleTest; +import io.helidon.tests.integration.dbclient.common.SimpleTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local simple test. + */ +final class MongoDBSimpleLocalTestIT extends MongoDBLocalTest implements SimpleTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(SimpleTestImpl::new); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + ctx.delegate().testCreateDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + ctx.delegate().testCreateDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + ctx.delegate().testNamedDeleteOrderArgs(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + ctx.delegate().testDeleteOrderArgs(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithInsertStrNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithInsertStrOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithInsertNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithInsertOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testNamedDmlWithInsertOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlWithInsertOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithUpdateNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithUpdateOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testNamedDmlWithUpdateOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlWithUpdateOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithDeleteNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithDeleteOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testNamedDmlWithDeleteOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlWithDeleteOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + ctx.delegate().testCreateNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + ctx.delegate().testCreateGetNamedArgs(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + ctx.delegate().testCreateGetOrderArgs(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + ctx.delegate().testNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + ctx.delegate().testGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + ctx.delegate().testCreateNamedInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + ctx.delegate().testCreateInsertNamedArgs(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + ctx.delegate().testCreateInsertOrderArgs(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + ctx.delegate().testNamedInsertOrderArgs(); + } + + @Test + @Override + public void testInsertOrderArgs() { + ctx.delegate().testInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + ctx.delegate().testCreateNamedQueryStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrOrderArgs(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + ctx.delegate().testCreateQueryNamedArgs(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + ctx.delegate().testCreateQueryOrderArgs(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + ctx.delegate().testNamedQueryOrderArgs(); + } + + @Test + @Override + public void testQueryOrderArgs() { + ctx.delegate().testQueryOrderArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + ctx.delegate().testCreateUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + ctx.delegate().testCreateUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + ctx.delegate().testNamedUpdateNamedArgs(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + ctx.delegate().testUpdateOrderArgs(); + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBSimpleRemoteTestIT.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBSimpleRemoteTestIT.java new file mode 100644 index 00000000000..5f6528cff1a --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBSimpleRemoteTestIT.java @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import io.helidon.tests.integration.dbclient.common.SimpleTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote simple test. + */ +final class MongoDBSimpleRemoteTestIT extends MongoDBRemoteTest implements SimpleTest { + + MongoDBSimpleRemoteTestIT() { + super("/test/simple"); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + remoteTest(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithInsertStrNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithInsertStrOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithInsertNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithInsertOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testNamedDmlWithInsertOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlWithInsertOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithUpdateNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithUpdateOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testNamedDmlWithUpdateOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlWithUpdateOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithDeleteNamedArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testCreateDmlWithDeleteOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testNamedDmlWithDeleteOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlWithDeleteOrderArgs() { + throw new UnsupportedOperationException(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBStatementLocalTestIT.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBStatementLocalTestIT.java new file mode 100644 index 00000000000..21eed9ea716 --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBStatementLocalTestIT.java @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.StatementTest; +import io.helidon.tests.integration.dbclient.common.StatementTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local statement test. + */ +final class MongoDBStatementLocalTestIT extends MongoDBLocalTest implements StatementTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(StatementTestImpl::new); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + ctx.delegate().testCreateNamedQueryNonExistentStmt(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + ctx.delegate().testCreateNamedQueryNamedArgsSetOrderArg(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + ctx.delegate().testCreateNamedQueryOrderArgsSetNamedArg(); + } + + @Test + @Override + public void testGetArrayParams() { + ctx.delegate().testGetArrayParams(); + } + + @Test + @Override + public void testGetListParams() { + ctx.delegate().testGetListParams(); + } + + @Test + @Override + public void testGetMapParams() { + ctx.delegate().testGetMapParams(); + } + + @Test + @Override + public void testGetOrderParam() { + ctx.delegate().testGetOrderParam(); + } + + @Test + @Override + public void testGetNamedParam() { + ctx.delegate().testGetNamedParam(); + } + + @Test + @Override + public void testGetMappedNamedParam() { + ctx.delegate().testGetMappedNamedParam(); + } + + @Test + @Override + public void testGetMappedOrderParam() { + ctx.delegate().testGetMappedOrderParam(); + } + + @Test + @Override + public void testQueryArrayParams() { + ctx.delegate().testQueryArrayParams(); + } + + @Test + @Override + public void testQueryListParams() { + ctx.delegate().testQueryListParams(); + } + + @Test + @Override + public void testQueryMapParams() { + ctx.delegate().testQueryMapParams(); + } + + @Test + @Override + public void testQueryOrderParam() { + ctx.delegate().testQueryOrderParam(); + } + + @Test + @Override + public void testQueryNamedParam() { + ctx.delegate().testQueryNamedParam(); + } + + @Test + @Override + public void testQueryMappedNamedParam() { + ctx.delegate().testQueryMappedNamedParam(); + } + + @Test + @Override + public void testQueryMappedOrderParam() { + ctx.delegate().testQueryMappedOrderParam(); + } + + @Override + @SuppressWarnings("ALL") + public void testQueryMapMissingParams() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlArrayParams() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlListParams() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlMapParams() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlOrderParam() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlNamedParam() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlMappedNamedParam() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlMappedOrderParam() { + throw new UnsupportedOperationException(); + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBStatementRemoteTestIT.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBStatementRemoteTestIT.java new file mode 100644 index 00000000000..3d5b68d1b4c --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBStatementRemoteTestIT.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import io.helidon.tests.integration.dbclient.common.StatementTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote statement test. + */ +final class MongoDBStatementRemoteTestIT extends MongoDBRemoteTest implements StatementTest { + + MongoDBStatementRemoteTestIT() { + super("/test/statement"); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + remoteTest(); + } + + @Test + @Override + public void testGetArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testGetListParams() { + remoteTest(); + } + + @Test + @Override + public void testGetMapParams() { + remoteTest(); + } + + @Test + @Override + public void testGetOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testGetNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testGetMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testGetMappedOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryListParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryMapParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryMappedOrderParam() { + remoteTest(); + } + + @Override + @SuppressWarnings("ALL") + public void testQueryMapMissingParams() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlArrayParams() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlListParams() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlMapParams() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlOrderParam() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlNamedParam() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlMappedNamedParam() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testDmlMappedOrderParam() { + throw new UnsupportedOperationException(); + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBSuiteIT.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBSuiteIT.java deleted file mode 100644 index de2c0467341..00000000000 --- a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBSuiteIT.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.dbclient.mongodb; - -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Stream; - -import io.helidon.config.Config; -import io.helidon.config.ConfigSources; -import io.helidon.dbclient.DbClient; -import io.helidon.dbclient.DbExecute; -import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; -import io.helidon.tests.integration.dbclient.common.model.Type; -import io.helidon.tests.integration.dbclient.common.utils.TestConfig; -import io.helidon.tests.integration.dbclient.common.tests.MapperIT; - -import io.helidon.tests.integration.harness.AfterSuite; -import io.helidon.tests.integration.harness.BeforeSuite; -import org.junit.platform.suite.api.ExcludeClassNamePatterns; -import org.junit.platform.suite.api.IncludeClassNamePatterns; -import org.junit.platform.suite.api.SelectPackages; -import org.junit.platform.suite.api.Suite; - -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; -import static io.helidon.tests.integration.dbclient.common.model.Type.TYPES; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; - -/** - * Test Database Client MongoDB. - */ -@Suite -@SelectPackages("io.helidon.tests.integration.dbclient.common.tests") -@ExcludeClassNamePatterns(".*Transaction.*") -@IncludeClassNamePatterns(".*IT") -class MongoDBSuiteIT { - - private static final System.Logger LOGGER = System.getLogger(MapperIT.class.getName()); - private static final int TIMEOUT = 60; - - @BeforeSuite - static Map setup() { - Config config = Config.create(ConfigSources.classpath(TestConfig.configFile())); - DbClient dbClient = DbClient.builder(config.get("db")).build(); - waitForStart(dbClient); - ping(dbClient); - initSchema(dbClient); - initData(dbClient); - testListTypes(dbClient); - testListPokemons(dbClient); - testListPokemonTypes(dbClient); - return Map.of("dbClient", dbClient); - } - - @AfterSuite - static void tearDown(DbClient dbClient) { - deleteSchema(dbClient); - testDeletedSchema(dbClient); - } - - private static void ping(DbClient dbClient) { - DbExecute exec = dbClient.execute(); - DbRow row = exec.namedQuery("ping-query").findFirst().orElseThrow(); - Double ok = row.column("ok").as(Double.class); - assertThat(ok, equalTo(1.0)); - LOGGER.log(System.Logger.Level.DEBUG, () -> String.format("Command ping row: %s", row)); - } - - private static void initSchema(DbClient dbClient) { - DbExecute exec = dbClient.execute(); - exec.namedDml("create-types"); - exec.namedDml("create-pokemons"); - exec.namedDml("create-poketypes"); - } - - private static void initData(DbClient dbClient) { - DbExecute exec = dbClient.execute(); - long count = 0; - for (Map.Entry entry : TYPES.entrySet()) { - count += exec.namedInsert("insert-type", entry.getKey(), entry.getValue().name()); - } - - for (Map.Entry entry : POKEMONS.entrySet()) { - count += exec.namedInsert("insert-pokemon", entry.getKey(), entry.getValue().getName()); - } - - for (Map.Entry entry : POKEMONS.entrySet()) { - Pokemon pokemon = entry.getValue(); - for (Type type : pokemon.getTypes()) { - count += exec.namedInsert("insert-poketype", pokemon.getId(), type.id()); - } - } - LOGGER.log(System.Logger.Level.INFO, String.format("executed %s statements", count)); - } - - private static void testListTypes(DbClient dbClient) { - DbExecute exec = dbClient.execute(); - - List rows = exec.namedQuery("select-types").toList(); - assertThat(rows, not(empty())); - - Set ids = new HashSet<>(TYPES.keySet()); - for (DbRow row : rows) { - Integer id = row.column(1).as(Integer.class); - String name = row.column(2).as(String.class); - assertThat(ids, hasItem(id)); - assertThat(name, TYPES.get(id).name().equals(name)); - } - } - - private static void testListPokemons(DbClient dbClient) { - DbExecute exec = dbClient.execute(); - - List rowsList = exec.namedQuery("select-pokemons").toList(); - assertThat(rowsList, not(empty())); - - Set ids = new HashSet<>(POKEMONS.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)); - assertThat(name, POKEMONS.get(id).getName().equals(name)); - } - } - - private static void testListPokemonTypes(DbClient dbClient) { - DbExecute exec = dbClient.execute(); - - List rows = exec.namedQuery("select-pokemons").toList(); - assertThat(rows, not(empty())); - - for (DbRow row : rows) { - Integer pokemonId = row.column(1).as(Integer.class); - String pokemonName = row.column(2).as(String.class); - Pokemon pokemon = POKEMONS.get(pokemonId); - assertThat(pokemonName, POKEMONS.get(pokemonId).getName().equals(pokemonName)); - Stream typeRows = exec.namedQuery("select-poketypes", pokemonId); - - List typeRowsList = typeRows.toList(); - assertThat(typeRowsList.size(), equalTo(pokemon.getTypes().size())); - for (DbRow typeRow : typeRowsList) { - Integer typeId = typeRow.column(2).as(Integer.class); - assertThat(pokemon.getTypes(), hasItem(TYPES.get(typeId))); - } - } - } - - private static void deleteSchema(DbClient dbClient) { - DbExecute exec = dbClient.execute(); - exec.namedDelete("delete-poketypes"); - exec.namedDelete("delete-pokemons"); - exec.namedDelete("delete-types"); - } - - private static void testDeletedSchema(DbClient dbClient) { - DbExecute exec = dbClient.execute(); - assertThat(exec.namedQuery("select-types").count(), is(0)); - assertThat(exec.namedQuery("select-pokemons").count(), is(0)); - assertThat(exec.namedQuery("select-pokemons-all").count(), is(0)); - } - - @SuppressWarnings("BusyWait") - private static void waitForStart(DbClient dbClient) { - long endTm = 1000 * TIMEOUT + System.currentTimeMillis(); - while (true) { - try { - dbClient.execute().namedGet("ping"); - break; - } catch (Throwable th) { - if (System.currentTimeMillis() > endTm) { - throw new IllegalStateException("Database startup failed!", th); - } - LOGGER.log(System.Logger.Level.DEBUG, () -> String.format("Exception: %s", th.getMessage()), th); - try { - Thread.sleep(1000); - } catch (InterruptedException ignored) { - } - } - } - } -} diff --git a/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBTestContainer.java b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBTestContainer.java new file mode 100644 index 00000000000..c5418d11d4a --- /dev/null +++ b/tests/integration/dbclient/mongodb/src/test/java/io/helidon/tests/integration/dbclient/mongodb/MongoDBTestContainer.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mongodb; + +import java.nio.file.Path; +import java.time.Duration; +import java.util.Map; +import java.util.function.Supplier; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.images.builder.ImageFromDockerfile; + +/** + * Database container utility. + */ +abstract class MongoDBTestContainer { + + private static final ImageFromDockerfile IMAGE = new ImageFromDockerfile("mongodb", false) + .withFileFromPath(".", Path.of("etc/docker")); + + static final GenericContainer CONTAINER = new GenericContainer<>(IMAGE) + .withEnv("MONGO_DB", "pokemon") + .withEnv("MONGO_USER", "test") + .withEnv("MONGO_PASSWORD", "mongo123") + .withExposedPorts(27017) + .waitingFor(Wait.forLogMessage("\\s*Container ready!\\s*", 1) + .withStartupTimeout(Duration.ofMinutes(1))); + + static Map> config() { + return Map.of("db.connection.url", MongoDBTestContainer::connectionString); + } + + static String connectionString() { + return "mongodb://localhost:%s/pokemon".formatted(CONTAINER.getMappedPort(27017)); + } + + private MongoDBTestContainer() { + } +} diff --git a/tests/integration/dbclient/mongodb/src/test/resources/test.yaml b/tests/integration/dbclient/mongodb/src/test/resources/test.yaml deleted file mode 100644 index 14e502fa6c1..00000000000 --- a/tests/integration/dbclient/mongodb/src/test/resources/test.yaml +++ /dev/null @@ -1,206 +0,0 @@ -# -# Copyright (c) 2019, 2023 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -dbadmin: - source: mongoDb - connection: - url: mongodb://${mongo.host}:${mongo.port}/admin - username: ${mongo.root-user} - password: ${mongo.root-password} - statements: - ping: '{ - "operation": "command", - "query": { ping: 1 } - }' - use: '{ - "operation": "command", - "query": { use: "${mongo.database}" } - }' - create-user: '{ - "operation": "command", - "query": { - "createUser": "${mongo.user}", - "pwd": "${mongo.password}", - "roles": [ - { role: "readWrite", db: "${mongo.database}" } - ] - } - }' - -db: - source: mongoDb - connection: - url: mongodb://${mongo.host}:${mongo.port}/${mongo.database} - username: ${mongo.user} - password: ${mongo.password} - - health-check: - type: query - statement: '{ - "operation": "command", - "query": { ping: 1 } - }' - - statements: - ping-query: '{ - "operation": "command", - "query": { ping: 1 } - }' - delete-types: '{ - "collection": "types", - "operation": "delete", - "query": { } - }' - delete-pokemons: '{ - "collection": "pokemons", - "operation": "delete", - "query": { } - }' - delete-poketypes: '{ - "collection": "pokemon_types", - "operation": "delete", - "query": { } - }' - insert-type: '{ - "collection": "types", - "value": { - "id": ?, - "type": ? - } - }' - insert-pokemon: '{ - "collection": "pokemons", - "value": { - "id": ?, - "name": ? - } - }' - insert-poketype: '{ - "collection": "pokemon_types", - "value": { - "id_pokemon": ?, - "id_type": ? - } - }' - select-types: '{ - "collection": "types", - "projection": { id: 1, type: 1, _id: 0 }, - "query": {} - }' - select-pokemons: '{ - "collection": "pokemons", - "projection": { id: 1, name: 1, _id: 0 }, - "query": {} - }' - select-poketypes: '{ - "collection": "pokemon_types", - "projection": { id_pokemon: 1, id_type: 1, _id: 0 }, - "query": { id_pokemon: ? } - }' - select-poketypes-all: '{ - "collection": "pokemon_types", - "projection": { id_pokemon: 1, id_type: 1, _id: 0 }, - "query": {} - }' - select-pokemon-named-arg: '{ - "collection": "pokemons", - "operation": "query", - "projection": { id: 1, name: 1, _id: 0 }, - "query": { name: $name } - }' - select-pokemon-order-arg: '{ - "collection": "pokemons", - "operation": "query", - "projection": { id: 1, name: 1, _id: 0 }, - "query": { name: ? } - }' - insert-pokemon-named-arg: '{ - "collection": "pokemons", - "operation": "insert", - "value": { - "id": $id, - "name": $name - } - }' - insert-pokemon-order-arg: '{ - "collection": "pokemons", - "operation": "insert", - "value": { - "id": ?, - "name": ? - } - }' - insert-pokemon-order-arg-rev: '{ - "collection": "pokemons", - "operation": "insert", - "value": { - "name": ?, - "id": ? - } - }' - select-pokemon-by-id: '{ - "collection": "pokemons", - "operation": "query", - "projection": { id: 1, name: 1, _id: 0 }, - "query": { id: ? } - }' - update-pokemon-named-arg: '{ - "collection": "pokemons", - "operation": "update", - "value":{ $set: { "name": $name } }, - "query": { id: $id } - }' - update-pokemon-order-arg: '{ - "collection": "pokemons", - "operation": "update", - "value":{ $set: { "name": ? } }, - "query": { id: ? } - }' - delete-pokemon-named-arg: '{ - "collection": "pokemons", - "operation": "delete", - "query": { id: $id } - }' - delete-pokemon-order-arg: '{ - "collection": "pokemons", - "operation": "delete", - "query": { id: ? } - }' - delete-pokemon-full-named-arg: '{ - "collection": "pokemons", - "operation": "delete", - "query": { $and: [ {name: $name }, { id: $id } ] } - }' - delete-pokemon-full-order-arg: '{ - "collection": "pokemons", - "operation": "delete", - "query": { $and: [ {name: ? }, { id: ? } ] } - }' - select-pokemons-idrng-named-arg: '{ - "collection": "pokemons", - "operation": "query", - "projection": { id: 1, name: 1, _id: 0 }, - "query": { $and: [ { id: { $gt: $idmin } }, { id: { $lt: $idmax } } ] } - }' - select-pokemons-idrng-order-arg: '{ - "collection": "pokemons", - "operation": "query", - "projection": { id: 1, name: 1, _id: 0 }, - "query": { $and: [ { id: { $gt: ? } }, { id: { $lt: ? } } ] } - }' - -test: - ping-dml: false diff --git a/tests/integration/dbclient/mysql/README.md b/tests/integration/dbclient/mysql/README.md new file mode 100644 index 00000000000..5f5f4e26e80 --- /dev/null +++ b/tests/integration/dbclient/mysql/README.md @@ -0,0 +1,17 @@ +# DbClient Integration Test MySQL + +To run this test: +```shell +mvn clean verify +``` + +Start the database: +```shell +docker run -d \ + --name mysql \ + -e MYSQL_DATABASE=test \ + -e MYSQL_USER=test \ + -e MYSQL_PASSWORD=mysql123 \ + -p 3306:3306 \ + container-registry.oracle.com/mysql/community-server:latest +``` diff --git a/tests/integration/dbclient/mysql/pom.xml b/tests/integration/dbclient/mysql/pom.xml new file mode 100644 index 00000000000..de3440248ae --- /dev/null +++ b/tests/integration/dbclient/mysql/pom.xml @@ -0,0 +1,80 @@ + + + + + 4.0.0 + + io.helidon.tests.integration.dbclient + helidon-tests-integration-dbclient-parent + 4.1.0-SNAPSHOT + ../parent/pom.xml + + helidon-tests-integration-dbclient-mysql + Helidon Tests Integration DbClient MySQL + + + + io.helidon.dbclient + helidon-dbclient-jdbc + + + io.helidon.dbclient + helidon-dbclient-metrics-hikari + + + io.helidon.integrations.db + helidon-integrations-db-mysql + + + com.mysql + mysql-connector-j + + + org.testcontainers + mysql + test + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-libs + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + diff --git a/tests/integration/dbclient/mysql/src/main/resources/db.yaml b/tests/integration/dbclient/mysql/src/main/resources/db.yaml new file mode 100644 index 00000000000..68f85b365e8 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/main/resources/db.yaml @@ -0,0 +1,30 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +db: + source: jdbc + connection: + url: jdbc:mysql://localhost:3306/test?useSSL=false&allowPublicKeyRetrieval=true + username: test + password: mysql123 + poolName: test + initializationFailTimeout: -1 + connectionTimeout: 2000 + health-check: + type: query + statement: "SELECT 0" + statements: + ping-dml: "DO 0" diff --git a/tests/integration/dbclient/mysql/src/main/resources/logging.properties b/tests/integration/dbclient/mysql/src/main/resources/logging.properties new file mode 100644 index 00000000000..d590b197673 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/main/resources/logging.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +handlers=org.slf4j.bridge.SLF4JBridgeHandler +.level=INFO diff --git a/tests/integration/dbclient/mysql/src/main/resources/simplelogger.properties b/tests/integration/dbclient/mysql/src/main/resources/simplelogger.properties new file mode 100644 index 00000000000..fcc605df165 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/main/resources/simplelogger.properties @@ -0,0 +1,22 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +org.slf4j.simpleLogger.defaultLogLevel=warn +org.slf4j.simpleLogger.showThreadName=false +org.slf4j.simpleLogger.log.org.testcontainers=info +org.slf4j.simpleLogger.log.org.testcontainers.utility=error +org.slf4j.simpleLogger.log.io.helidon=info +org.slf4j.simpleLogger.log.org.hibernate=info +org.slf4j.simpleLogger.log.com.zaxxer=info diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLLocalTest.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLLocalTest.java new file mode 100644 index 00000000000..1a18268b159 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLLocalTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import java.util.function.BiFunction; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.tests.integration.dbclient.common.LocalTextContext; + +import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Base class for the local tests. + */ +@Testcontainers(disabledWithoutDocker = true) +abstract class MySQLLocalTest { + + @Container + static final MySQLContainer CONTAINER = MySQLTestContainer.CONTAINER; + + static LocalTextContext context(BiFunction factory) { + return LocalTextContext.create(factory, MySQLTestContainer.config(), true); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLMiscLocalTestIT.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLMiscLocalTestIT.java new file mode 100644 index 00000000000..18cabc1c554 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLMiscLocalTestIT.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.MiscTest; +import io.helidon.tests.integration.dbclient.common.MiscTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local misc test. + */ +final class MySQLMiscLocalTestIT extends MySQLLocalTest implements MiscTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(MiscTestImpl::new); + } + + @Test + @Override + public void testFlowControl() { + ctx.delegate().testFlowControl(); + } + + @Test + @Override + public void testStatementInterceptor() { + ctx.delegate().testStatementInterceptor(); + } + + @Test + @Override + public void testInsertWithOrderMapping() { + ctx.delegate().testInsertWithOrderMapping(); + } + + @Test + @Override + public void testInsertWithNamedMapping() { + ctx.delegate().testInsertWithNamedMapping(); + } + + @Test + @Override + public void testUpdateWithOrderMapping() { + ctx.delegate().testUpdateWithOrderMapping(); + } + + @Test + @Override + public void testUpdateWithNamedMapping() { + ctx.delegate().testUpdateWithNamedMapping(); + } + + @Test + @Override + public void testDeleteWithOrderMapping() { + ctx.delegate().testDeleteWithOrderMapping(); + } + + @Test + @Override + public void testDeleteWithNamedMapping() { + ctx.delegate().testDeleteWithNamedMapping(); + } + + @Test + @Override + public void testQueryWithMapping() { + ctx.delegate().testQueryWithMapping(); + } + + @Test + @Override + public void testGetWithMapping() { + ctx.delegate().testGetWithMapping(); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLMiscRemoteTestIT.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLMiscRemoteTestIT.java new file mode 100644 index 00000000000..9b249af97b3 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLMiscRemoteTestIT.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import io.helidon.tests.integration.dbclient.common.MiscTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote misc test. + */ +final class MySQLMiscRemoteTestIT extends MySQLRemoteTest implements MiscTest { + + MySQLMiscRemoteTestIT() { + super("/test/misc"); + } + + @Test + @Override + public void testFlowControl() { + remoteTest(); + } + + @Test + @Override + public void testStatementInterceptor() { + remoteTest(); + } + + @Test + @Override + public void testInsertWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testInsertWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testUpdateWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testUpdateWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testDeleteWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testDeleteWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testQueryWithMapping() { + remoteTest(); + } + + @Test + @Override + public void testGetWithMapping() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLObservabilityLocalTestIT.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLObservabilityLocalTestIT.java new file mode 100644 index 00000000000..64ec9582e8e --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLObservabilityLocalTestIT.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import io.helidon.tests.integration.dbclient.common.DbClientITMain; +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.ObservabilityTest; +import io.helidon.tests.integration.dbclient.common.ObservabilityTestImpl; +import io.helidon.webclient.http1.Http1Client; +import io.helidon.webserver.WebServerConfig; +import io.helidon.webserver.testing.junit5.ServerTest; +import io.helidon.webserver.testing.junit5.SetUpServer; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local observability test. + */ +@ServerTest +final class MySQLObservabilityLocalTestIT extends MySQLLocalTest implements ObservabilityTest { + + private static Http1Client client; + private static LocalTextContext ctx; + + @BeforeAll + static void beforeAll(Http1Client aClient) { + client = aClient; + } + + @SetUpServer + static void setUp(WebServerConfig.Builder builder) { + ctx = context((db, c) -> new ObservabilityTestImpl(db, c, () -> client)); + DbClientITMain.setup(ctx.db(), ctx.config(), builder); + } + + @Test + @Override + public void testHttpHealthNoDetails() { + ctx.delegate().testHttpHealthNoDetails(); + } + + @Test + @Override + public void testHttpHealthDetails() { + ctx.delegate().testHttpHealthDetails(); + } + + @Test + @Override + public void testHttpMetrics() { + ctx.delegate().testHttpMetrics(); + } + + @Test + @Override + public void testHealthCheck() { + ctx.delegate().testHealthCheck(); + } + + @Test + @Override + public void testHealthCheckWithName() { + ctx.delegate().testHealthCheckWithName(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedDML() { + ctx.delegate().testHealthCheckWithCustomNamedDML(); + } + + @Test + @Override + public void testHealthCheckWithCustomDML() { + ctx.delegate().testHealthCheckWithCustomDML(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedQuery() { + ctx.delegate().testHealthCheckWithCustomNamedQuery(); + } + + @Test + @Override + public void testHealthCheckWithCustomQuery() { + ctx.delegate().testHealthCheckWithCustomQuery(); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLObservabilityRemoteTestIT.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLObservabilityRemoteTestIT.java new file mode 100644 index 00000000000..92465e9ac79 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLObservabilityRemoteTestIT.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import io.helidon.tests.integration.dbclient.common.ObservabilityTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote observability test. + */ +final class MySQLObservabilityRemoteTestIT extends MySQLRemoteTest implements ObservabilityTest { + + MySQLObservabilityRemoteTestIT() { + super("/test/observability"); + } + + @Test + @Override + public void testHttpHealthNoDetails() { + remoteTest(); + } + + @Test + @Override + public void testHttpHealthDetails() { + remoteTest(); + } + + @Test + @Override + public void testHttpMetrics() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheck() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithName() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedDML() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithCustomDML() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedQuery() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithCustomQuery() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLRemoteTest.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLRemoteTest.java new file mode 100644 index 00000000000..0efb21ffc8e --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLRemoteTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import java.nio.file.Path; +import java.util.Map; + +import io.helidon.tests.integration.dbclient.common.RemoteTest; +import io.helidon.tests.integration.harness.ProcessRunner; +import io.helidon.tests.integration.harness.ProcessRunner.ExecMode; +import io.helidon.tests.integration.harness.WaitStrategy; +import io.helidon.tests.integration.harness.TestProcess; +import io.helidon.tests.integration.harness.TestProcesses; + +import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Base class for the remote tests. + */ +@Testcontainers(disabledWithoutDocker = true) +@TestProcesses +abstract class MySQLRemoteTest extends RemoteTest { + + @Container + static final MySQLContainer CONTAINER = MySQLTestContainer.CONTAINER; + + @TestProcess + static final ProcessRunner PROCESS_RUNNER = ProcessRunner.of(ExecMode.CLASS_PATH) + .finalName("helidon-tests-integration-dbclient-mysql") + .properties(Map.of("java.util.logging.config.file", Path.of("target/classes/logging.properties").toAbsolutePath())) + .properties(MySQLTestContainer::config) + .waitingFor(WaitStrategy.waitForPort()); + + /** + * Create a new instance. + * + * @param path base path + */ + @SuppressWarnings("resource") + MySQLRemoteTest(String path) { + super(path, PROCESS_RUNNER.process().port()); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLSimpleLocalTestIT.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLSimpleLocalTestIT.java new file mode 100644 index 00000000000..c720de50a7b --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLSimpleLocalTestIT.java @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.SimpleTest; +import io.helidon.tests.integration.dbclient.common.SimpleTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local simple test. + */ +final class MySQLSimpleLocalTestIT extends MySQLLocalTest implements SimpleTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(SimpleTestImpl::new); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + ctx.delegate().testCreateDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + ctx.delegate().testCreateDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + ctx.delegate().testNamedDeleteOrderArgs(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + ctx.delegate().testDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithInsertNamedArgs() { + ctx.delegate().testCreateDmlWithInsertNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithInsertOrderArgs() { + ctx.delegate().testCreateDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithInsertOrderArgs() { + ctx.delegate().testNamedDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testDmlWithInsertOrderArgs() { + ctx.delegate().testDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithUpdateNamedArgs() { + ctx.delegate().testCreateDmlWithUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithUpdateOrderArgs() { + ctx.delegate().testCreateDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithUpdateOrderArgs() { + ctx.delegate().testNamedDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testDmlWithUpdateOrderArgs() { + ctx.delegate().testDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithDeleteNamedArgs() { + ctx.delegate().testCreateDmlWithDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithDeleteOrderArgs() { + ctx.delegate().testCreateDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithDeleteOrderArgs() { + ctx.delegate().testNamedDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testDmlWithDeleteOrderArgs() { + ctx.delegate().testDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + ctx.delegate().testCreateNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + ctx.delegate().testCreateGetNamedArgs(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + ctx.delegate().testCreateGetOrderArgs(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + ctx.delegate().testNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + ctx.delegate().testGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + ctx.delegate().testCreateNamedInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + ctx.delegate().testCreateInsertNamedArgs(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + ctx.delegate().testCreateInsertOrderArgs(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + ctx.delegate().testNamedInsertOrderArgs(); + } + + @Test + @Override + public void testInsertOrderArgs() { + ctx.delegate().testInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + ctx.delegate().testCreateNamedQueryStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrOrderArgs(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + ctx.delegate().testCreateQueryNamedArgs(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + ctx.delegate().testCreateQueryOrderArgs(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + ctx.delegate().testNamedQueryOrderArgs(); + } + + @Test + @Override + public void testQueryOrderArgs() { + ctx.delegate().testQueryOrderArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + ctx.delegate().testCreateUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + ctx.delegate().testCreateUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + ctx.delegate().testNamedUpdateNamedArgs(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + ctx.delegate().testUpdateOrderArgs(); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLSimpleRemoteTestIT.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLSimpleRemoteTestIT.java new file mode 100644 index 00000000000..050a0418c28 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLSimpleRemoteTestIT.java @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import io.helidon.tests.integration.dbclient.common.SimpleTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote simple test. + */ +final class MySQLSimpleRemoteTestIT extends MySQLRemoteTest implements SimpleTest { + + MySQLSimpleRemoteTestIT() { + super("/test/simple"); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLStatementLocalTestIT.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLStatementLocalTestIT.java new file mode 100644 index 00000000000..b277284da2b --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLStatementLocalTestIT.java @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.StatementTest; +import io.helidon.tests.integration.dbclient.common.StatementTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local statement test. + */ +final class MySQLStatementLocalTestIT extends MySQLLocalTest implements StatementTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(StatementTestImpl::new); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + ctx.delegate().testCreateNamedQueryNonExistentStmt(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + ctx.delegate().testCreateNamedQueryNamedArgsSetOrderArg(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + ctx.delegate().testCreateNamedQueryOrderArgsSetNamedArg(); + } + + @Test + @Override + public void testGetArrayParams() { + ctx.delegate().testGetArrayParams(); + } + + @Test + @Override + public void testGetListParams() { + ctx.delegate().testGetListParams(); + } + + @Test + @Override + public void testGetMapParams() { + ctx.delegate().testGetMapParams(); + } + + @Test + @Override + public void testGetOrderParam() { + ctx.delegate().testGetOrderParam(); + } + + @Test + @Override + public void testGetNamedParam() { + ctx.delegate().testGetNamedParam(); + } + + @Test + @Override + public void testGetMappedNamedParam() { + ctx.delegate().testGetMappedNamedParam(); + } + + @Test + @Override + public void testGetMappedOrderParam() { + ctx.delegate().testGetMappedOrderParam(); + } + + @Test + @Override + public void testQueryArrayParams() { + ctx.delegate().testQueryArrayParams(); + } + + @Test + @Override + public void testQueryListParams() { + ctx.delegate().testQueryListParams(); + } + + @Test + @Override + public void testQueryMapParams() { + ctx.delegate().testQueryMapParams(); + } + + @Test + @Override + public void testQueryMapMissingParams() { + ctx.delegate().testQueryMapMissingParams(); + } + + @Test + @Override + public void testQueryOrderParam() { + ctx.delegate().testQueryOrderParam(); + } + + @Test + @Override + public void testQueryNamedParam() { + ctx.delegate().testQueryNamedParam(); + } + + @Test + @Override + public void testQueryMappedNamedParam() { + ctx.delegate().testQueryMappedNamedParam(); + } + + @Test + @Override + public void testQueryMappedOrderParam() { + ctx.delegate().testQueryMappedOrderParam(); + } + + @Test + @Override + public void testDmlArrayParams() { + ctx.delegate().testDmlArrayParams(); + } + + @Test + @Override + public void testDmlListParams() { + ctx.delegate().testDmlListParams(); + } + + @Test + @Override + public void testDmlMapParams() { + ctx.delegate().testDmlMapParams(); + } + + @Test + @Override + public void testDmlOrderParam() { + ctx.delegate().testDmlOrderParam(); + } + + @Test + @Override + public void testDmlNamedParam() { + ctx.delegate().testDmlNamedParam(); + } + + @Test + @Override + public void testDmlMappedNamedParam() { + ctx.delegate().testDmlMappedNamedParam(); + } + + @Test + @Override + public void testDmlMappedOrderParam() { + ctx.delegate().testDmlMappedOrderParam(); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLStatementRemoteTestIT.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLStatementRemoteTestIT.java new file mode 100644 index 00000000000..d53ee457e42 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLStatementRemoteTestIT.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import io.helidon.tests.integration.dbclient.common.StatementTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote statement test. + */ +final class MySQLStatementRemoteTestIT extends MySQLRemoteTest implements StatementTest { + + MySQLStatementRemoteTestIT() { + super("/test/statement"); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + remoteTest(); + } + + @Test + @Override + public void testGetArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testGetListParams() { + remoteTest(); + } + + @Test + @Override + public void testGetMapParams() { + remoteTest(); + } + + @Test + @Override + public void testGetOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testGetNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testGetMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testGetMappedOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryListParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryMapParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryMapMissingParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryMappedOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlListParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlMapParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlMappedOrderParam() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLTestContainer.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLTestContainer.java new file mode 100644 index 00000000000..fdda39063b6 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLTestContainer.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import java.util.Map; +import java.util.function.Supplier; + +import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.utility.DockerImageName; + +/** + * Database container utility. + */ +abstract class MySQLTestContainer { + + private static final DockerImageName IMAGE = DockerImageName.parse("container-registry.oracle.com/mysql/community-server") + .asCompatibleSubstituteFor("mysql"); + + static final MySQLContainer CONTAINER = new MySQLContainer<>(IMAGE) + .withUsername("test") + .withPassword("mysql123") + .withDatabaseName("test"); + + static Map> config() { + return Map.of("db.connection.url", CONTAINER::getJdbcUrl); + } + + private MySQLTestContainer() { + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLTransactionLocalTestIT.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLTransactionLocalTestIT.java new file mode 100644 index 00000000000..445ed8d30a3 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLTransactionLocalTestIT.java @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.TransactionTest; +import io.helidon.tests.integration.dbclient.common.TransactionTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local transaction test. + */ +final class MySQLTransactionLocalTestIT extends MySQLLocalTest implements TransactionTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(TransactionTestImpl::new); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + ctx.delegate().testCreateDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + ctx.delegate().testCreateDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + ctx.delegate().testNamedDeleteOrderArgs(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + ctx.delegate().testDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + ctx.delegate().testCreateNamedQueryNonExistentStmt(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + ctx.delegate().testCreateNamedQueryNamedArgsSetOrderArg(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + ctx.delegate().testCreateNamedQueryOrderArgsSetNamedArg(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + ctx.delegate().testCreateNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + ctx.delegate().testCreateGetNamedArgs(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + ctx.delegate().testCreateGetOrderArgs(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + ctx.delegate().testNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + ctx.delegate().testGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + ctx.delegate().testCreateNamedInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + ctx.delegate().testCreateInsertNamedArgs(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + ctx.delegate().testCreateInsertOrderArgs(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + ctx.delegate().testNamedInsertOrderArgs(); + } + + @Test + @Override + public void testInsertOrderArgs() { + ctx.delegate().testInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + ctx.delegate().testCreateNamedQueryStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrOrderArgs(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + ctx.delegate().testCreateQueryNamedArgs(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + ctx.delegate().testCreateQueryOrderArgs(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + ctx.delegate().testNamedQueryOrderArgs(); + } + + @Test + @Override + public void testQueryOrderArgs() { + ctx.delegate().testQueryOrderArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + ctx.delegate().testCreateUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + ctx.delegate().testCreateUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + ctx.delegate().testNamedUpdateNamedArgs(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + ctx.delegate().testUpdateOrderArgs(); + } +} diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLTransactionRemoteTestIT.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLTransactionRemoteTestIT.java new file mode 100644 index 00000000000..7e9d495df94 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySQLTransactionRemoteTestIT.java @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.mysql; + +import io.helidon.tests.integration.dbclient.common.TransactionTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote transaction test. + */ +final class MySQLTransactionRemoteTestIT extends MySQLRemoteTest implements TransactionTest { + + MySQLTransactionRemoteTestIT() { + super("/test/transaction"); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/oracle/README.md b/tests/integration/dbclient/oracle/README.md new file mode 100644 index 00000000000..b56ff16cc2d --- /dev/null +++ b/tests/integration/dbclient/oracle/README.md @@ -0,0 +1,15 @@ +# DbClient Integration Test Oracle + +To run this test: +```shell +mvn clean verify +``` + +Start the database: +```shell +docker run -d \ + --name oracledb \ + -e ORACLE_PWD=oracle123 \ + -p 1521:1521 \ + container-registry.oracle.com/database/express:latest +``` diff --git a/tests/integration/dbclient/oracle/pom.xml b/tests/integration/dbclient/oracle/pom.xml new file mode 100644 index 00000000000..114e15d4097 --- /dev/null +++ b/tests/integration/dbclient/oracle/pom.xml @@ -0,0 +1,71 @@ + + + + + 4.0.0 + + io.helidon.tests.integration.dbclient + helidon-tests-integration-dbclient-parent + 4.1.0-SNAPSHOT + ../parent/pom.xml + + helidon-tests-integration-dbclient-oracle + Helidon Tests Integration DbClient Oracle + + + + io.helidon.dbclient + helidon-dbclient-jdbc + + + io.helidon.dbclient + helidon-dbclient-metrics-hikari + + + io.helidon.integrations.db + ojdbc + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-libs + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + diff --git a/tests/integration/dbclient/oracle/src/main/resources/db.yaml b/tests/integration/dbclient/oracle/src/main/resources/db.yaml new file mode 100644 index 00000000000..f1daebdfa6c --- /dev/null +++ b/tests/integration/dbclient/oracle/src/main/resources/db.yaml @@ -0,0 +1,29 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +db: + source: jdbc + connection: + url: jdbc:oracle:thin:@localhost:1521/XE + username: system + password: oracle123 + poolName: test + initializationFailTimeout: -1 + connectionTimeout: 2000 + health-check: + statement: "SELECT 1 FROM DUAL" + statements: + ping: "SELECT 1 FROM DUAL" diff --git a/tests/integration/dbclient/oracle/src/main/resources/logging.properties b/tests/integration/dbclient/oracle/src/main/resources/logging.properties new file mode 100644 index 00000000000..d590b197673 --- /dev/null +++ b/tests/integration/dbclient/oracle/src/main/resources/logging.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +handlers=org.slf4j.bridge.SLF4JBridgeHandler +.level=INFO diff --git a/tests/integration/dbclient/oracle/src/main/resources/simplelogger.properties b/tests/integration/dbclient/oracle/src/main/resources/simplelogger.properties new file mode 100644 index 00000000000..fcc605df165 --- /dev/null +++ b/tests/integration/dbclient/oracle/src/main/resources/simplelogger.properties @@ -0,0 +1,22 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +org.slf4j.simpleLogger.defaultLogLevel=warn +org.slf4j.simpleLogger.showThreadName=false +org.slf4j.simpleLogger.log.org.testcontainers=info +org.slf4j.simpleLogger.log.org.testcontainers.utility=error +org.slf4j.simpleLogger.log.io.helidon=info +org.slf4j.simpleLogger.log.org.hibernate=info +org.slf4j.simpleLogger.log.com.zaxxer=info diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleLocalTest.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleLocalTest.java new file mode 100644 index 00000000000..eca6525b69e --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleLocalTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import java.util.function.BiFunction; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.tests.integration.dbclient.common.LocalTextContext; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Base class for the local tests. + */ +@Testcontainers(disabledWithoutDocker = true) +abstract class OracleLocalTest { + + @Container + static final GenericContainer CONTAINER = OracleTestContainer.CONTAINER; + + static LocalTextContext context(BiFunction factory) { + return LocalTextContext.create(factory, OracleTestContainer.config(), true); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleMiscLocalTestIT.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleMiscLocalTestIT.java new file mode 100644 index 00000000000..0f300055622 --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleMiscLocalTestIT.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.MiscTest; +import io.helidon.tests.integration.dbclient.common.MiscTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local misc test. + */ +final class OracleMiscLocalTestIT extends OracleLocalTest implements MiscTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(MiscTestImpl::new); + } + + @Test + @Override + public void testFlowControl() { + ctx.delegate().testFlowControl(); + } + + @Test + @Override + public void testStatementInterceptor() { + ctx.delegate().testStatementInterceptor(); + } + + @Test + @Override + public void testInsertWithOrderMapping() { + ctx.delegate().testInsertWithOrderMapping(); + } + + @Test + @Override + public void testInsertWithNamedMapping() { + ctx.delegate().testInsertWithNamedMapping(); + } + + @Test + @Override + public void testUpdateWithOrderMapping() { + ctx.delegate().testUpdateWithOrderMapping(); + } + + @Test + @Override + public void testUpdateWithNamedMapping() { + ctx.delegate().testUpdateWithNamedMapping(); + } + + @Test + @Override + public void testDeleteWithOrderMapping() { + ctx.delegate().testDeleteWithOrderMapping(); + } + + @Test + @Override + public void testDeleteWithNamedMapping() { + ctx.delegate().testDeleteWithNamedMapping(); + } + + @Test + @Override + public void testQueryWithMapping() { + ctx.delegate().testQueryWithMapping(); + } + + @Test + @Override + public void testGetWithMapping() { + ctx.delegate().testGetWithMapping(); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleMiscRemoteTestIT.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleMiscRemoteTestIT.java new file mode 100644 index 00000000000..f92984a71ab --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleMiscRemoteTestIT.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import io.helidon.tests.integration.dbclient.common.MiscTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote misc test. + */ +final class OracleMiscRemoteTestIT extends OracleRemoteTest implements MiscTest { + + OracleMiscRemoteTestIT() { + super("/test/misc"); + } + + @Test + @Override + public void testFlowControl() { + remoteTest(); + } + + @Test + @Override + public void testStatementInterceptor() { + remoteTest(); + } + + @Test + @Override + public void testInsertWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testInsertWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testUpdateWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testUpdateWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testDeleteWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testDeleteWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testQueryWithMapping() { + remoteTest(); + } + + @Test + @Override + public void testGetWithMapping() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleObservabilityLocalTestIT.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleObservabilityLocalTestIT.java new file mode 100644 index 00000000000..e9288b0895f --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleObservabilityLocalTestIT.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import io.helidon.tests.integration.dbclient.common.DbClientITMain; +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.ObservabilityTest; +import io.helidon.tests.integration.dbclient.common.ObservabilityTestImpl; +import io.helidon.webclient.http1.Http1Client; +import io.helidon.webserver.WebServerConfig; +import io.helidon.webserver.testing.junit5.ServerTest; +import io.helidon.webserver.testing.junit5.SetUpServer; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local observability test. + */ +@ServerTest +final class OracleObservabilityLocalTestIT extends OracleLocalTest implements ObservabilityTest { + + private static Http1Client client; + private static LocalTextContext ctx; + + @BeforeAll + static void beforeAll(Http1Client aClient) { + client = aClient; + } + + @SetUpServer + static void setUp(WebServerConfig.Builder builder) { + ctx = context((db, c) -> new ObservabilityTestImpl(db, c, () -> client)); + DbClientITMain.setup(ctx.db(), ctx.config(), builder); + } + + @Test + @Override + public void testHttpHealthNoDetails() { + ctx.delegate().testHttpHealthNoDetails(); + } + + @Test + @Override + public void testHttpHealthDetails() { + ctx.delegate().testHttpHealthDetails(); + } + + @Test + @Override + public void testHttpMetrics() { + ctx.delegate().testHttpMetrics(); + } + + @Test + @Override + public void testHealthCheck() { + ctx.delegate().testHealthCheck(); + } + + @Test + @Override + public void testHealthCheckWithName() { + ctx.delegate().testHealthCheckWithName(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomNamedDML() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomDML() { + throw new UnsupportedOperationException(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedQuery() { + ctx.delegate().testHealthCheckWithCustomNamedQuery(); + } + + @Test + @Override + public void testHealthCheckWithCustomQuery() { + ctx.delegate().testHealthCheckWithCustomQuery(); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleObservabilityRemoteTestIT.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleObservabilityRemoteTestIT.java new file mode 100644 index 00000000000..0332fa332f1 --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleObservabilityRemoteTestIT.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import io.helidon.tests.integration.dbclient.common.ObservabilityTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote observability test. + */ +final class OracleObservabilityRemoteTestIT extends OracleRemoteTest implements ObservabilityTest { + + OracleObservabilityRemoteTestIT() { + super("/test/observability"); + } + + @Test + @Override + public void testHttpHealthNoDetails() { + remoteTest(); + } + + @Test + @Override + public void testHttpHealthDetails() { + remoteTest(); + } + + @Test + @Override + public void testHttpMetrics() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheck() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithName() { + remoteTest(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomNamedDML() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomDML() { + throw new UnsupportedOperationException(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedQuery() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithCustomQuery() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleRemoteTest.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleRemoteTest.java new file mode 100644 index 00000000000..8938f039a7e --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleRemoteTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import java.nio.file.Path; +import java.util.Map; + +import io.helidon.tests.integration.dbclient.common.RemoteTest; +import io.helidon.tests.integration.harness.ProcessRunner; +import io.helidon.tests.integration.harness.ProcessRunner.ExecMode; +import io.helidon.tests.integration.harness.WaitStrategy; +import io.helidon.tests.integration.harness.TestProcess; +import io.helidon.tests.integration.harness.TestProcesses; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Base class for the remote tests. + */ +@Testcontainers(disabledWithoutDocker = true) +@TestProcesses +abstract class OracleRemoteTest extends RemoteTest { + + @Container + static final GenericContainer CONTAINER = OracleTestContainer.CONTAINER; + + @TestProcess + static final ProcessRunner PROCESS_RUNNER = ProcessRunner.of(ExecMode.CLASS_PATH) + .finalName("helidon-tests-integration-dbclient-oracle") + .properties(Map.of("java.util.logging.config.file", Path.of("target/classes/logging.properties").toAbsolutePath())) + .properties(OracleTestContainer::config) + .waitingFor(WaitStrategy.waitForPort()); + + /** + * Create a new instance. + * + * @param path base path + */ + @SuppressWarnings("resource") + OracleRemoteTest(String path) { + super(path, PROCESS_RUNNER.process().port()); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleSimpleLocalTestIT.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleSimpleLocalTestIT.java new file mode 100644 index 00000000000..89f1883022a --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleSimpleLocalTestIT.java @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.SimpleTest; +import io.helidon.tests.integration.dbclient.common.SimpleTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local simple test. + */ +final class OracleSimpleLocalTestIT extends OracleLocalTest implements SimpleTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(SimpleTestImpl::new); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + ctx.delegate().testCreateDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + ctx.delegate().testCreateDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + ctx.delegate().testNamedDeleteOrderArgs(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + ctx.delegate().testDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithInsertNamedArgs() { + ctx.delegate().testCreateDmlWithInsertNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithInsertOrderArgs() { + ctx.delegate().testCreateDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithInsertOrderArgs() { + ctx.delegate().testNamedDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testDmlWithInsertOrderArgs() { + ctx.delegate().testDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithUpdateNamedArgs() { + ctx.delegate().testCreateDmlWithUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithUpdateOrderArgs() { + ctx.delegate().testCreateDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithUpdateOrderArgs() { + ctx.delegate().testNamedDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testDmlWithUpdateOrderArgs() { + ctx.delegate().testDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithDeleteNamedArgs() { + ctx.delegate().testCreateDmlWithDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithDeleteOrderArgs() { + ctx.delegate().testCreateDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithDeleteOrderArgs() { + ctx.delegate().testNamedDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testDmlWithDeleteOrderArgs() { + ctx.delegate().testDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + ctx.delegate().testCreateNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + ctx.delegate().testCreateGetNamedArgs(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + ctx.delegate().testCreateGetOrderArgs(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + ctx.delegate().testNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + ctx.delegate().testGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + ctx.delegate().testCreateNamedInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + ctx.delegate().testCreateInsertNamedArgs(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + ctx.delegate().testCreateInsertOrderArgs(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + ctx.delegate().testNamedInsertOrderArgs(); + } + + @Test + @Override + public void testInsertOrderArgs() { + ctx.delegate().testInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + ctx.delegate().testCreateNamedQueryStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrOrderArgs(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + ctx.delegate().testCreateQueryNamedArgs(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + ctx.delegate().testCreateQueryOrderArgs(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + ctx.delegate().testNamedQueryOrderArgs(); + } + + @Test + @Override + public void testQueryOrderArgs() { + ctx.delegate().testQueryOrderArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + ctx.delegate().testCreateUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + ctx.delegate().testCreateUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + ctx.delegate().testNamedUpdateNamedArgs(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + ctx.delegate().testUpdateOrderArgs(); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleSimpleRemoteTestIT.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleSimpleRemoteTestIT.java new file mode 100644 index 00000000000..92db52011dd --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleSimpleRemoteTestIT.java @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import io.helidon.tests.integration.dbclient.common.SimpleTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote simple test. + */ +final class OracleSimpleRemoteTestIT extends OracleRemoteTest implements SimpleTest { + + OracleSimpleRemoteTestIT() { + super("/test/simple"); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleStatementLocalTestIT.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleStatementLocalTestIT.java new file mode 100644 index 00000000000..bdb4564a458 --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleStatementLocalTestIT.java @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.StatementTest; +import io.helidon.tests.integration.dbclient.common.StatementTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local statement test. + */ +final class OracleStatementLocalTestIT extends OracleLocalTest implements StatementTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(StatementTestImpl::new); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + ctx.delegate().testCreateNamedQueryNonExistentStmt(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + ctx.delegate().testCreateNamedQueryNamedArgsSetOrderArg(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + ctx.delegate().testCreateNamedQueryOrderArgsSetNamedArg(); + } + + @Test + @Override + public void testGetArrayParams() { + ctx.delegate().testGetArrayParams(); + } + + @Test + @Override + public void testGetListParams() { + ctx.delegate().testGetListParams(); + } + + @Test + @Override + public void testGetMapParams() { + ctx.delegate().testGetMapParams(); + } + + @Test + @Override + public void testGetOrderParam() { + ctx.delegate().testGetOrderParam(); + } + + @Test + @Override + public void testGetNamedParam() { + ctx.delegate().testGetNamedParam(); + } + + @Test + @Override + public void testGetMappedNamedParam() { + ctx.delegate().testGetMappedNamedParam(); + } + + @Test + @Override + public void testGetMappedOrderParam() { + ctx.delegate().testGetMappedOrderParam(); + } + + @Test + @Override + public void testQueryArrayParams() { + ctx.delegate().testQueryArrayParams(); + } + + @Test + @Override + public void testQueryListParams() { + ctx.delegate().testQueryListParams(); + } + + @Test + @Override + public void testQueryMapParams() { + ctx.delegate().testQueryMapParams(); + } + + @Test + @Override + public void testQueryMapMissingParams() { + ctx.delegate().testQueryMapMissingParams(); + } + + @Test + @Override + public void testQueryOrderParam() { + ctx.delegate().testQueryOrderParam(); + } + + @Test + @Override + public void testQueryNamedParam() { + ctx.delegate().testQueryNamedParam(); + } + + @Test + @Override + public void testQueryMappedNamedParam() { + ctx.delegate().testQueryMappedNamedParam(); + } + + @Test + @Override + public void testQueryMappedOrderParam() { + ctx.delegate().testQueryMappedOrderParam(); + } + + @Test + @Override + public void testDmlArrayParams() { + ctx.delegate().testDmlArrayParams(); + } + + @Test + @Override + public void testDmlListParams() { + ctx.delegate().testDmlListParams(); + } + + @Test + @Override + public void testDmlMapParams() { + ctx.delegate().testDmlMapParams(); + } + + @Test + @Override + public void testDmlOrderParam() { + ctx.delegate().testDmlOrderParam(); + } + + @Test + @Override + public void testDmlNamedParam() { + ctx.delegate().testDmlNamedParam(); + } + + @Test + @Override + public void testDmlMappedNamedParam() { + ctx.delegate().testDmlMappedNamedParam(); + } + + @Test + @Override + public void testDmlMappedOrderParam() { + ctx.delegate().testDmlMappedOrderParam(); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleStatementRemoteTestIT.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleStatementRemoteTestIT.java new file mode 100644 index 00000000000..87583f9dc73 --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleStatementRemoteTestIT.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import io.helidon.tests.integration.dbclient.common.StatementTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote statement test. + */ +final class OracleStatementRemoteTestIT extends OracleRemoteTest implements StatementTest { + + OracleStatementRemoteTestIT() { + super("/test/statement"); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + remoteTest(); + } + + @Test + @Override + public void testGetArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testGetListParams() { + remoteTest(); + } + + @Test + @Override + public void testGetMapParams() { + remoteTest(); + } + + @Test + @Override + public void testGetOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testGetNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testGetMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testGetMappedOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryListParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryMapParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryMapMissingParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryMappedOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlListParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlMapParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlMappedOrderParam() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleTestContainer.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleTestContainer.java new file mode 100644 index 00000000000..1fc744dc48f --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleTestContainer.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import java.time.Duration; +import java.util.Map; +import java.util.function.Supplier; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; + +/** + * Database container utility. + */ +abstract class OracleTestContainer { + + private static final DockerImageName IMAGE = DockerImageName.parse("container-registry.oracle.com/database/express"); + + static final GenericContainer CONTAINER = new GenericContainer<>(IMAGE) + .withEnv("ORACLE_PWD", "oracle123") + .withExposedPorts(1521) + .waitingFor(Wait.forHealthcheck() + .withStartupTimeout(Duration.ofMinutes(5))); + + static Map> config() { + return Map.of("db.connection.url", OracleTestContainer::jdbcUrl); + } + + private static String jdbcUrl() { + return "jdbc:oracle:thin:@localhost:%s/XE".formatted(CONTAINER.getMappedPort(1521)); + } + + private OracleTestContainer() { + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleTransactionLocalTestIT.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleTransactionLocalTestIT.java new file mode 100644 index 00000000000..53a7a668521 --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleTransactionLocalTestIT.java @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.TransactionTest; +import io.helidon.tests.integration.dbclient.common.TransactionTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local transaction test. + */ +final class OracleTransactionLocalTestIT extends OracleLocalTest implements TransactionTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(TransactionTestImpl::new); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + ctx.delegate().testCreateDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + ctx.delegate().testCreateDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + ctx.delegate().testNamedDeleteOrderArgs(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + ctx.delegate().testDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + ctx.delegate().testCreateNamedQueryNonExistentStmt(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + ctx.delegate().testCreateNamedQueryNamedArgsSetOrderArg(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + ctx.delegate().testCreateNamedQueryOrderArgsSetNamedArg(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + ctx.delegate().testCreateNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + ctx.delegate().testCreateGetNamedArgs(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + ctx.delegate().testCreateGetOrderArgs(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + ctx.delegate().testNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + ctx.delegate().testGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + ctx.delegate().testCreateNamedInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + ctx.delegate().testCreateInsertNamedArgs(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + ctx.delegate().testCreateInsertOrderArgs(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + ctx.delegate().testNamedInsertOrderArgs(); + } + + @Test + @Override + public void testInsertOrderArgs() { + ctx.delegate().testInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + ctx.delegate().testCreateNamedQueryStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrOrderArgs(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + ctx.delegate().testCreateQueryNamedArgs(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + ctx.delegate().testCreateQueryOrderArgs(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + ctx.delegate().testNamedQueryOrderArgs(); + } + + @Test + @Override + public void testQueryOrderArgs() { + ctx.delegate().testQueryOrderArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + ctx.delegate().testCreateUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + ctx.delegate().testCreateUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + ctx.delegate().testNamedUpdateNamedArgs(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + ctx.delegate().testUpdateOrderArgs(); + } +} diff --git a/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleTransactionRemoteTestIT.java b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleTransactionRemoteTestIT.java new file mode 100644 index 00000000000..c23b5caf5ff --- /dev/null +++ b/tests/integration/dbclient/oracle/src/test/java/io/helidon/tests/integration/dbclient/oracle/OracleTransactionRemoteTestIT.java @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.oracle; + +import io.helidon.tests.integration.dbclient.common.TransactionTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote transaction test. + */ +final class OracleTransactionRemoteTestIT extends OracleRemoteTest implements TransactionTest { + + OracleTransactionRemoteTestIT() { + super("/test/transaction"); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/parent/pom.xml b/tests/integration/dbclient/parent/pom.xml new file mode 100644 index 00000000000..2acb24b05ed --- /dev/null +++ b/tests/integration/dbclient/parent/pom.xml @@ -0,0 +1,151 @@ + + + + + 4.0.0 + + io.helidon.applications + helidon-se + 4.1.0-SNAPSHOT + ../../../../applications/se/pom.xml + + io.helidon.tests.integration.dbclient + helidon-tests-integration-dbclient-parent + Helidon Tests Integration DbClient Parent + pom + + + io.helidon.tests.integration.dbclient.common.DbClientITMain + true + + + + + io.helidon.dbclient + helidon-dbclient-metrics + + + io.helidon.tests.integration.dbclient + helidon-tests-integration-dbclient-common + ${project.version} + + + io.helidon.logging + helidon-logging-slf4j + + + org.slf4j + jul-to-slf4j + + + org.slf4j + slf4j-simple + + + org.junit.jupiter + junit-jupiter-api + test + + + + org.testcontainers + junit-jupiter + test + + + io.helidon.tests.integration + helidon-tests-integration-harness + ${project.version} + test + + + io.helidon.webserver.testing.junit5 + helidon-webserver-testing-junit5 + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IT + + + + ${project.build.outputDirectory}/logging.properties + + + ${redirectTestOutputToFile} + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + ${project.build.testOutputDirectory}/logging.properties + + + ${redirectTestOutputToFile} + ${project.build.outputDirectory} + + + + + + + + remote + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + **/*RemoteTestIT + + + + + + + + local + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + **/*LocalTestIT + + + + + + + + diff --git a/tests/integration/dbclient/pgsql/README.md b/tests/integration/dbclient/pgsql/README.md new file mode 100644 index 00000000000..73896ea8974 --- /dev/null +++ b/tests/integration/dbclient/pgsql/README.md @@ -0,0 +1,22 @@ +# DbClient Integration Test PostgreSQL + +To run this test: +```shell +mvn clean verify +``` + +Build the Docker image: +```shell +docker build etc/docker -t pgsql +``` + +Start the database: +```shell +docker run -d \ + --name pgsql \ + -e POSTGRES_USER=test \ + -e POSTGRES_PASSWORD=pgsql123 \ + -e POSTGRES_DB=test \ + -p 5432:5432 \ + pgsql +``` diff --git a/tests/integration/dbclient/pgsql/etc/docker/Dockerfile b/tests/integration/dbclient/pgsql/etc/docker/Dockerfile new file mode 100644 index 00000000000..f0778bb6852 --- /dev/null +++ b/tests/integration/dbclient/pgsql/etc/docker/Dockerfile @@ -0,0 +1,27 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +FROM oraclelinux:9-slim + +RUN microdnf install postgresql-server && microdnf clean all +ADD entrypoint.sh /usr/local/bin/ + +ENV PGDATA /var/lib/pgsql/data +USER postgres +ENTRYPOINT ["entrypoint.sh"] +STOPSIGNAL SIGINT +EXPOSE 5432 +CMD ["postgres"] diff --git a/tests/integration/dbclient/pgsql/etc/docker/entrypoint.sh b/tests/integration/dbclient/pgsql/etc/docker/entrypoint.sh new file mode 100755 index 00000000000..701e1e3a4e1 --- /dev/null +++ b/tests/integration/dbclient/pgsql/etc/docker/entrypoint.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +set -Eeo pipefail + +PGDATA="${PGDATA:-/var/lib/pgsql/data}" + +# initialize the data directory +initdb \ + --username="${POSTGRES_USER:-test}" \ + --pwfile=<(printf "%s" "${POSTGRES_PASSWORD:-test}") \ + -D "${PGDATA}" + +# update config file +# - listen on all network interfaces +# - turn off logging collector to log to the console +sed -e "s/^#listen_addresses = 'localhost'/listen_addresses = '*'/g" \ + -e "s/logging_collector = on/logging_collector = off/g" \ + -e "s/^#session_replication_role = 'origin'/session_replication_role = '${POSTGRES_SRR:-origin}'/g" \ + -i "${PGDATA}/postgresql.conf" + +# enabling trust for all connections +printf 'host all all all %s\n' "$(postgres -C password_encryption)" >> "${PGDATA}/pg_hba.conf" + +# temporary start to create the database +pg_ctl -D "${PGDATA}" -w start +psql \ + --username "${POSTGRES_USER:-test}" \ + --no-password \ + --dbname postgres \ + --set db="${POSTGRES_DB:-test}" <<-'EOSQL' + create database :"db"; + set session_replication_role = replica; +EOSQL +pg_ctl -D "${PGDATA}" -m fast -w stop + +exec "${@}" diff --git a/tests/integration/dbclient/pgsql/pom.xml b/tests/integration/dbclient/pgsql/pom.xml new file mode 100644 index 00000000000..63f11281e70 --- /dev/null +++ b/tests/integration/dbclient/pgsql/pom.xml @@ -0,0 +1,80 @@ + + + + + 4.0.0 + + io.helidon.tests.integration.dbclient + helidon-tests-integration-dbclient-parent + 4.1.0-SNAPSHOT + ../parent/pom.xml + + helidon-tests-integration-dbclient-pgsql + Helidon Tests Integration DbClient PostGreSQL + + + + io.helidon.dbclient + helidon-dbclient-jdbc + + + io.helidon.dbclient + helidon-dbclient-metrics-hikari + + + io.helidon.integrations.db + helidon-integrations-db-pgsql + + + org.postgresql + postgresql + + + org.testcontainers + jdbc + test + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-libs + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + diff --git a/tests/integration/dbclient/pgsql/src/main/resources/db.yaml b/tests/integration/dbclient/pgsql/src/main/resources/db.yaml new file mode 100644 index 00000000000..25d524ca4d8 --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/main/resources/db.yaml @@ -0,0 +1,28 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +db: + source: jdbc + connection: + url: jdbc:postgresql://localhost:5432/test + username: test + password: pgsql123 + poolName: test + initializationFailTimeout: -1 + connectionTimeout: 2000 + health-check: + type: query + statement: "SELECT 0" diff --git a/tests/integration/dbclient/pgsql/src/main/resources/logging.properties b/tests/integration/dbclient/pgsql/src/main/resources/logging.properties new file mode 100644 index 00000000000..d590b197673 --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/main/resources/logging.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +handlers=org.slf4j.bridge.SLF4JBridgeHandler +.level=INFO diff --git a/tests/integration/dbclient/pgsql/src/main/resources/simplelogger.properties b/tests/integration/dbclient/pgsql/src/main/resources/simplelogger.properties new file mode 100644 index 00000000000..fcc605df165 --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/main/resources/simplelogger.properties @@ -0,0 +1,22 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +org.slf4j.simpleLogger.defaultLogLevel=warn +org.slf4j.simpleLogger.showThreadName=false +org.slf4j.simpleLogger.log.org.testcontainers=info +org.slf4j.simpleLogger.log.org.testcontainers.utility=error +org.slf4j.simpleLogger.log.io.helidon=info +org.slf4j.simpleLogger.log.org.hibernate=info +org.slf4j.simpleLogger.log.com.zaxxer=info diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLLocalTest.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLLocalTest.java new file mode 100644 index 00000000000..501182d2f9b --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLLocalTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import java.util.function.BiFunction; + +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.tests.integration.dbclient.common.LocalTextContext; + +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Base class for the local tests. + */ +@Testcontainers(disabledWithoutDocker = true) +abstract class PostgreSQLLocalTest { + + @Container + static final JdbcDatabaseContainer CONTAINER = PostgreSQLTestContainer.CONTAINER; + + static LocalTextContext context(BiFunction factory) { + return LocalTextContext.create(factory, PostgreSQLTestContainer.config(), true); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLMiscLocalTestIT.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLMiscLocalTestIT.java new file mode 100644 index 00000000000..8a36c02b69c --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLMiscLocalTestIT.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.MiscTest; +import io.helidon.tests.integration.dbclient.common.MiscTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local misc test. + */ +final class PostgreSQLMiscLocalTestIT extends PostgreSQLLocalTest implements MiscTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(MiscTestImpl::new); + } + + @Test + @Override + public void testFlowControl() { + ctx.delegate().testFlowControl(); + } + + @Test + @Override + public void testStatementInterceptor() { + ctx.delegate().testStatementInterceptor(); + } + + @Test + @Override + public void testInsertWithOrderMapping() { + ctx.delegate().testInsertWithOrderMapping(); + } + + @Test + @Override + public void testInsertWithNamedMapping() { + ctx.delegate().testInsertWithNamedMapping(); + } + + @Test + @Override + public void testUpdateWithOrderMapping() { + ctx.delegate().testUpdateWithOrderMapping(); + } + + @Test + @Override + public void testUpdateWithNamedMapping() { + ctx.delegate().testUpdateWithNamedMapping(); + } + + @Test + @Override + public void testDeleteWithOrderMapping() { + ctx.delegate().testDeleteWithOrderMapping(); + } + + @Test + @Override + public void testDeleteWithNamedMapping() { + ctx.delegate().testDeleteWithNamedMapping(); + } + + @Test + @Override + public void testQueryWithMapping() { + ctx.delegate().testQueryWithMapping(); + } + + @Test + @Override + public void testGetWithMapping() { + ctx.delegate().testGetWithMapping(); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLMiscRemoteTestIT.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLMiscRemoteTestIT.java new file mode 100644 index 00000000000..3dacb53dbd2 --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLMiscRemoteTestIT.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import io.helidon.tests.integration.dbclient.common.MiscTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote misc test. + */ +final class PostgreSQLMiscRemoteTestIT extends PostgreSQLRemoteTest implements MiscTest { + + PostgreSQLMiscRemoteTestIT() { + super("/test/misc"); + } + + @Test + @Override + public void testFlowControl() { + remoteTest(); + } + + @Test + @Override + public void testStatementInterceptor() { + remoteTest(); + } + + @Test + @Override + public void testInsertWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testInsertWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testUpdateWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testUpdateWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testDeleteWithOrderMapping() { + remoteTest(); + } + + @Test + @Override + public void testDeleteWithNamedMapping() { + remoteTest(); + } + + @Test + @Override + public void testQueryWithMapping() { + remoteTest(); + } + + @Test + @Override + public void testGetWithMapping() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLObservabilityLocalTestIT.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLObservabilityLocalTestIT.java new file mode 100644 index 00000000000..7bd68bf171b --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLObservabilityLocalTestIT.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import io.helidon.tests.integration.dbclient.common.DbClientITMain; +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.ObservabilityTest; +import io.helidon.tests.integration.dbclient.common.ObservabilityTestImpl; +import io.helidon.webclient.http1.Http1Client; +import io.helidon.webserver.WebServerConfig; +import io.helidon.webserver.testing.junit5.ServerTest; +import io.helidon.webserver.testing.junit5.SetUpServer; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local observability test. + */ +@ServerTest +final class PostgreSQLObservabilityLocalTestIT extends PostgreSQLLocalTest implements ObservabilityTest { + + private static Http1Client client; + private static LocalTextContext ctx; + + @BeforeAll + static void beforeAll(Http1Client aClient) { + client = aClient; + } + + @SetUpServer + static void setUp(WebServerConfig.Builder builder) { + ctx = context((db, c) -> new ObservabilityTestImpl(db, c, () -> client)); + DbClientITMain.setup(ctx.db(), ctx.config(), builder); + } + + @Test + @Override + public void testHttpHealthNoDetails() { + ctx.delegate().testHttpHealthNoDetails(); + } + + @Test + @Override + public void testHttpHealthDetails() { + ctx.delegate().testHttpHealthDetails(); + } + + @Test + @Override + public void testHttpMetrics() { + ctx.delegate().testHttpMetrics(); + } + + @Test + @Override + public void testHealthCheck() { + ctx.delegate().testHealthCheck(); + } + + @Test + @Override + public void testHealthCheckWithName() { + ctx.delegate().testHealthCheckWithName(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomNamedDML() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomDML() { + throw new UnsupportedOperationException(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedQuery() { + ctx.delegate().testHealthCheckWithCustomNamedQuery(); + } + + @Test + @Override + public void testHealthCheckWithCustomQuery() { + ctx.delegate().testHealthCheckWithCustomQuery(); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLObservabilityRemoteTestIT.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLObservabilityRemoteTestIT.java new file mode 100644 index 00000000000..3a9a8fddf3b --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLObservabilityRemoteTestIT.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import io.helidon.tests.integration.dbclient.common.ObservabilityTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote observability test. + */ +final class PostgreSQLObservabilityRemoteTestIT extends PostgreSQLRemoteTest implements ObservabilityTest { + + PostgreSQLObservabilityRemoteTestIT() { + super("/test/observability"); + } + + @Test + @Override + public void testHttpHealthNoDetails() { + remoteTest(); + } + + @Test + @Override + public void testHttpHealthDetails() { + remoteTest(); + } + + @Test + @Override + public void testHttpMetrics() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheck() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithName() { + remoteTest(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomNamedDML() { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings("ALL") + public void testHealthCheckWithCustomDML() { + throw new UnsupportedOperationException(); + } + + @Test + @Override + public void testHealthCheckWithCustomNamedQuery() { + remoteTest(); + } + + @Test + @Override + public void testHealthCheckWithCustomQuery() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLRemoteTest.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLRemoteTest.java new file mode 100644 index 00000000000..1f6bb5fc038 --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLRemoteTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import java.nio.file.Path; +import java.util.Map; + +import io.helidon.tests.integration.dbclient.common.RemoteTest; +import io.helidon.tests.integration.harness.ProcessRunner; +import io.helidon.tests.integration.harness.ProcessRunner.ExecMode; +import io.helidon.tests.integration.harness.WaitStrategy; +import io.helidon.tests.integration.harness.TestProcess; +import io.helidon.tests.integration.harness.TestProcesses; + +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Base class for the remote tests. + */ +@Testcontainers(disabledWithoutDocker = true) +@TestProcesses +abstract class PostgreSQLRemoteTest extends RemoteTest { + + @Container + static final JdbcDatabaseContainer CONTAINER = PostgreSQLTestContainer.CONTAINER; + + @TestProcess + static final ProcessRunner PROCESS_RUNNER = ProcessRunner.of(ExecMode.CLASS_PATH) + .finalName("helidon-tests-integration-dbclient-pgsql") + .properties(Map.of("java.util.logging.config.file", Path.of("target/classes/logging.properties").toAbsolutePath())) + .properties(PostgreSQLTestContainer::config) + .waitingFor(WaitStrategy.waitForPort()); + + /** + * Create a new instance. + * + * @param path base path + */ + @SuppressWarnings("resource") + PostgreSQLRemoteTest(String path) { + super(path, PROCESS_RUNNER.process().port()); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLSimpleLocalTestIT.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLSimpleLocalTestIT.java new file mode 100644 index 00000000000..a8fdbfd5380 --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLSimpleLocalTestIT.java @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.SimpleTest; +import io.helidon.tests.integration.dbclient.common.SimpleTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local simple test. + */ +final class PostgreSQLSimpleLocalTestIT extends PostgreSQLLocalTest implements SimpleTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(SimpleTestImpl::new); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + ctx.delegate().testCreateDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + ctx.delegate().testCreateDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + ctx.delegate().testNamedDeleteOrderArgs(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + ctx.delegate().testDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithInsertNamedArgs() { + ctx.delegate().testCreateDmlWithInsertNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithInsertOrderArgs() { + ctx.delegate().testCreateDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithInsertOrderArgs() { + ctx.delegate().testNamedDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testDmlWithInsertOrderArgs() { + ctx.delegate().testDmlWithInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithUpdateNamedArgs() { + ctx.delegate().testCreateDmlWithUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithUpdateOrderArgs() { + ctx.delegate().testCreateDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithUpdateOrderArgs() { + ctx.delegate().testNamedDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testDmlWithUpdateOrderArgs() { + ctx.delegate().testDmlWithUpdateOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDmlWithDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDmlWithDeleteNamedArgs() { + ctx.delegate().testCreateDmlWithDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDmlWithDeleteOrderArgs() { + ctx.delegate().testCreateDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDmlWithDeleteOrderArgs() { + ctx.delegate().testNamedDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testDmlWithDeleteOrderArgs() { + ctx.delegate().testDmlWithDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + ctx.delegate().testCreateNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + ctx.delegate().testCreateGetNamedArgs(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + ctx.delegate().testCreateGetOrderArgs(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + ctx.delegate().testNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + ctx.delegate().testGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + ctx.delegate().testCreateNamedInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + ctx.delegate().testCreateInsertNamedArgs(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + ctx.delegate().testCreateInsertOrderArgs(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + ctx.delegate().testNamedInsertOrderArgs(); + } + + @Test + @Override + public void testInsertOrderArgs() { + ctx.delegate().testInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + ctx.delegate().testCreateNamedQueryStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrOrderArgs(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + ctx.delegate().testCreateQueryNamedArgs(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + ctx.delegate().testCreateQueryOrderArgs(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + ctx.delegate().testNamedQueryOrderArgs(); + } + + @Test + @Override + public void testQueryOrderArgs() { + ctx.delegate().testQueryOrderArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + ctx.delegate().testCreateUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + ctx.delegate().testCreateUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + ctx.delegate().testNamedUpdateNamedArgs(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + ctx.delegate().testUpdateOrderArgs(); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLSimpleRemoteTestIT.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLSimpleRemoteTestIT.java new file mode 100644 index 00000000000..d0607b5d7ab --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLSimpleRemoteTestIT.java @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import io.helidon.tests.integration.dbclient.common.SimpleTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote simple test. + */ +final class PostgreSQLSimpleRemoteTestIT extends PostgreSQLRemoteTest implements SimpleTest { + + PostgreSQLSimpleRemoteTestIT() { + super("/test/simple"); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDmlWithDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDmlWithDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLStatementLocalTestIT.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLStatementLocalTestIT.java new file mode 100644 index 00000000000..1b1abc46164 --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLStatementLocalTestIT.java @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.StatementTest; +import io.helidon.tests.integration.dbclient.common.StatementTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local statement test. + */ +final class PostgreSQLStatementLocalTestIT extends PostgreSQLLocalTest implements StatementTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(StatementTestImpl::new); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + ctx.delegate().testCreateNamedQueryNonExistentStmt(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + ctx.delegate().testCreateNamedQueryNamedArgsSetOrderArg(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + ctx.delegate().testCreateNamedQueryOrderArgsSetNamedArg(); + } + + @Test + @Override + public void testGetArrayParams() { + ctx.delegate().testGetArrayParams(); + } + + @Test + @Override + public void testGetListParams() { + ctx.delegate().testGetListParams(); + } + + @Test + @Override + public void testGetMapParams() { + ctx.delegate().testGetMapParams(); + } + + @Test + @Override + public void testGetOrderParam() { + ctx.delegate().testGetOrderParam(); + } + + @Test + @Override + public void testGetNamedParam() { + ctx.delegate().testGetNamedParam(); + } + + @Test + @Override + public void testGetMappedNamedParam() { + ctx.delegate().testGetMappedNamedParam(); + } + + @Test + @Override + public void testGetMappedOrderParam() { + ctx.delegate().testGetMappedOrderParam(); + } + + @Test + @Override + public void testQueryArrayParams() { + ctx.delegate().testQueryArrayParams(); + } + + @Test + @Override + public void testQueryListParams() { + ctx.delegate().testQueryListParams(); + } + + @Test + @Override + public void testQueryMapParams() { + ctx.delegate().testQueryMapParams(); + } + + @Test + @Override + public void testQueryMapMissingParams() { + ctx.delegate().testQueryMapMissingParams(); + } + + @Test + @Override + public void testQueryOrderParam() { + ctx.delegate().testQueryOrderParam(); + } + + @Test + @Override + public void testQueryNamedParam() { + ctx.delegate().testQueryNamedParam(); + } + + @Test + @Override + public void testQueryMappedNamedParam() { + ctx.delegate().testQueryMappedNamedParam(); + } + + @Test + @Override + public void testQueryMappedOrderParam() { + ctx.delegate().testQueryMappedOrderParam(); + } + + @Test + @Override + public void testDmlArrayParams() { + ctx.delegate().testDmlArrayParams(); + } + + @Test + @Override + public void testDmlListParams() { + ctx.delegate().testDmlListParams(); + } + + @Test + @Override + public void testDmlMapParams() { + ctx.delegate().testDmlMapParams(); + } + + @Test + @Override + public void testDmlOrderParam() { + ctx.delegate().testDmlOrderParam(); + } + + @Test + @Override + public void testDmlNamedParam() { + ctx.delegate().testDmlNamedParam(); + } + + @Test + @Override + public void testDmlMappedNamedParam() { + ctx.delegate().testDmlMappedNamedParam(); + } + + @Test + @Override + public void testDmlMappedOrderParam() { + ctx.delegate().testDmlMappedOrderParam(); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLStatementRemoteTestIT.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLStatementRemoteTestIT.java new file mode 100644 index 00000000000..88b5a5c6c7a --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLStatementRemoteTestIT.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import io.helidon.tests.integration.dbclient.common.StatementTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote statement test. + */ +final class PostgreSQLStatementRemoteTestIT extends PostgreSQLRemoteTest implements StatementTest { + + PostgreSQLStatementRemoteTestIT() { + super("/test/statement"); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + remoteTest(); + } + + @Test + @Override + public void testGetArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testGetListParams() { + remoteTest(); + } + + @Test + @Override + public void testGetMapParams() { + remoteTest(); + } + + @Test + @Override + public void testGetOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testGetNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testGetMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testGetMappedOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryListParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryMapParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryMapMissingParams() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testQueryMappedOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlArrayParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlListParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlMapParams() { + remoteTest(); + } + + @Test + @Override + public void testDmlOrderParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlMappedNamedParam() { + remoteTest(); + } + + @Test + @Override + public void testDmlMappedOrderParam() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLTestContainer.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLTestContainer.java new file mode 100644 index 00000000000..35e0b295032 --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLTestContainer.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import java.nio.file.Path; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Map; +import java.util.concurrent.Future; +import java.util.function.Supplier; + +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; +import org.testcontainers.images.builder.ImageFromDockerfile; + +/** + * Database container utility. + */ +abstract class PostgreSQLTestContainer { + + private static final ImageFromDockerfile IMAGE = new ImageFromDockerfile("pgsql", false) + .withFileFromPath(".", Path.of("etc/docker")); + + static final JdbcDatabaseContainer CONTAINER = new PostgreSQLContainer(IMAGE) + .withPassword("pgsql123"); + + static Map> config() { + return Map.of("db.connection.url", CONTAINER::getJdbcUrl); + } + + private PostgreSQLTestContainer() { + } + + private static final class PostgreSQLContainer extends JdbcDatabaseContainer { + + private String dbName = "test"; + private String username = "test"; + private String password = "test"; + + PostgreSQLContainer(Future image) { + super(image); + waitStrategy = new LogMessageWaitStrategy() + .withRegEx(".*database system is ready to accept connections.*\\s") + .withTimes(2) + .withStartupTimeout(Duration.of(60, ChronoUnit.SECONDS)); + addExposedPort(5432); + } + + @Override + protected void configure() { + // Disable Postgres driver use of java.util.logging to reduce noise at startup time + withUrlParam("loggerLevel", "OFF"); + addEnv("POSTGRES_DB", dbName); + addEnv("POSTGRES_USER", username); + addEnv("POSTGRES_PASSWORD", password); + } + + @Override + public PostgreSQLContainer withUsername(String username) { + this.username = username; + return this; + } + + @Override + public PostgreSQLContainer withPassword(String password) { + this.password = password; + return this; + } + + @Override + public PostgreSQLContainer withDatabaseName(String dbName) { + this.dbName = dbName; + return this; + } + + @Override + public String getDriverClassName() { + return "org.postgresql.Driver"; + } + + @Override + public String getJdbcUrl() { + return "jdbc:postgresql://localhost:%d/%s".formatted(getMappedPort(5432), dbName); + } + + @Override + public String getUsername() { + return username; + } + + @Override + public String getPassword() { + return password; + } + + @Override + protected String getTestQueryString() { + return "SELECT 1"; + } + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLTransactionLocalTestIT.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLTransactionLocalTestIT.java new file mode 100644 index 00000000000..9258f730340 --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLTransactionLocalTestIT.java @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import io.helidon.tests.integration.dbclient.common.LocalTextContext; +import io.helidon.tests.integration.dbclient.common.TransactionTest; +import io.helidon.tests.integration.dbclient.common.TransactionTestImpl; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Local transaction test. + */ +final class PostgreSQLTransactionLocalTestIT extends PostgreSQLLocalTest implements TransactionTest { + + static LocalTextContext ctx; + + @BeforeAll + static void setUp() { + ctx = context(TransactionTestImpl::new); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + ctx.delegate().testCreateNamedDeleteStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + ctx.delegate().testCreateNamedDeleteStrOrderArgs(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + ctx.delegate().testCreateDeleteNamedArgs(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + ctx.delegate().testCreateDeleteOrderArgs(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + ctx.delegate().testNamedDeleteOrderArgs(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + ctx.delegate().testDeleteOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + ctx.delegate().testCreateNamedQueryNonExistentStmt(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithoutArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + ctx.delegate().testCreateNamedQueryNamedAndOrderArgsWithArgs(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + ctx.delegate().testCreateNamedQueryNamedArgsSetOrderArg(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + ctx.delegate().testCreateNamedQueryOrderArgsSetNamedArg(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + ctx.delegate().testCreateNamedGetStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + ctx.delegate().testCreateNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + ctx.delegate().testCreateGetNamedArgs(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + ctx.delegate().testCreateGetOrderArgs(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + ctx.delegate().testNamedGetStrOrderArgs(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + ctx.delegate().testGetStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + ctx.delegate().testCreateNamedInsertStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + ctx.delegate().testCreateNamedInsertStrOrderArgs(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + ctx.delegate().testCreateInsertNamedArgs(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + ctx.delegate().testCreateInsertOrderArgs(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + ctx.delegate().testNamedInsertOrderArgs(); + } + + @Test + @Override + public void testInsertOrderArgs() { + ctx.delegate().testInsertOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrStrOrderArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + ctx.delegate().testCreateNamedQueryStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + ctx.delegate().testCreateNamedQueryStrOrderArgs(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + ctx.delegate().testCreateQueryNamedArgs(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + ctx.delegate().testCreateQueryOrderArgs(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + ctx.delegate().testNamedQueryOrderArgs(); + } + + @Test + @Override + public void testQueryOrderArgs() { + ctx.delegate().testQueryOrderArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + ctx.delegate().testCreateNamedUpdateStrNamedArgs(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + ctx.delegate().testCreateNamedUpdateStrOrderArgs(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + ctx.delegate().testCreateUpdateNamedArgs(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + ctx.delegate().testCreateUpdateOrderArgs(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + ctx.delegate().testNamedUpdateNamedArgs(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + ctx.delegate().testUpdateOrderArgs(); + } +} diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLTransactionRemoteTestIT.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLTransactionRemoteTestIT.java new file mode 100644 index 00000000000..9341b4a26ec --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PostgreSQLTransactionRemoteTestIT.java @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.dbclient.pgsql; + +import io.helidon.tests.integration.dbclient.common.TransactionTest; + +import org.junit.jupiter.api.Test; + +/** + * Remote transaction test. + */ +final class PostgreSQLTransactionRemoteTestIT extends PostgreSQLRemoteTest implements TransactionTest { + + PostgreSQLTransactionRemoteTestIT() { + super("/test/transaction"); + } + + @Test + @Override + public void testCreateNamedDeleteStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedDeleteStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testDeleteOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNonExistentStmt() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithoutArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedAndOrderArgsWithArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryNamedArgsSetOrderArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryOrderArgsSetNamedArg() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateGetOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testGetStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedInsertStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testInsertOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedQueryStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testQueryOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateNamedUpdateStrOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testCreateUpdateOrderArgs() { + remoteTest(); + } + + @Test + @Override + public void testNamedUpdateNamedArgs() { + remoteTest(); + } + + @Test + @Override + public void testUpdateOrderArgs() { + remoteTest(); + } +} diff --git a/tests/integration/dbclient/pom.xml b/tests/integration/dbclient/pom.xml index 651b8247354..421cdb35b37 100644 --- a/tests/integration/dbclient/pom.xml +++ b/tests/integration/dbclient/pom.xml @@ -19,7 +19,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - io.helidon.tests.integration helidon-tests-integration @@ -29,34 +28,15 @@ io.helidon.tests.integration.dbclient helidon-tests-integration-dbclient-project pom - Helidon Tests Integration Database Client - A set of tests that validate Database Client + Helidon Tests Integration DbClient Project common + parent h2 - app + mysql + pgsql + oracle + mongodb - - - - - io.helidon.build-tools - helidon-services-plugin - - false - - - - - - - - testcontainers - - - - - - diff --git a/tests/integration/harness/pom.xml b/tests/integration/harness/pom.xml index 39f4843e2ad..48f75ddd04d 100644 --- a/tests/integration/harness/pom.xml +++ b/tests/integration/harness/pom.xml @@ -17,39 +17,23 @@ + 4.0.0 io.helidon.tests.integration helidon-tests-integration 4.1.0-SNAPSHOT - 4.0.0 helidon-tests-integration-harness Helidon Tests Integration Harness - - io.helidon.webclient - helidon-webclient - - - io.helidon.http.media - helidon-http-media-jsonp - - - jakarta.json - jakarta.json-api - org.junit.jupiter junit-jupiter-api - org.junit.platform - junit-platform-suite-engine - - - org.junit.platform - junit-platform-launcher + io.helidon.common + helidon-common diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/AfterSuite.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/AfterSuite.java deleted file mode 100644 index e174dfb552f..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/AfterSuite.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -import org.junit.platform.suite.api.Suite; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Hook for static methods invoked after a {@link Suite}. - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface AfterSuite { - - /** - * Priority, higher value has higher priority. - * - * @return priority - */ - int priority() default 100; -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/AppResponse.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/AppResponse.java deleted file mode 100644 index 7b4f8897a3e..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/AppResponse.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -import jakarta.json.Json; -import jakarta.json.JsonArrayBuilder; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; -import jakarta.json.JsonValue; - -/** - * Response helper methods. - */ -public class AppResponse { - - /** - * Build JSON response with {@code OK} status. - *

Returned JSON object has the following structure:
- *

 {
-     *      "status": "OK",
-     *      "data": <data>
-     * }
- * - * @param data attached data JSON value. - * @return JSON response with OK status and attached data. - */ - public static JsonObject okStatus(JsonValue data) { - JsonObjectBuilder job = Json.createObjectBuilder(); - job.add("status", "OK"); - job.add("data", data != null ? data : JsonValue.NULL); - return job.build(); - } - - /** - * Build JSON response with {@code exception} status. - *

Returned JSON object has the following structure:
- *

 {
-     *      "status": "exception",
-     *      "stacktrace": [
-     *          {
-     *              "class": "class.of.Exception",
-     *              "message": "Exception message",
-     *              "trace": [
-     *                  {
-     *                      "file": "Java class file",
-     *                      line": <exception line number in Java class file>,
-     *                      "module": "module name",
-     *                      "modVersion": "module version",
-     *                      "loader": "classloader name",
-     *                      "class": "class name",
-     *                      "method": "method name"
-     *                  },
-     *                  {...},...
-     *              ]
-     *          },
-     *          {...},...
-     *      ]
-     * }
- * - * @param th {@link Throwable} to be stored in JSON response - * @return JSON response with exception status and attached stack trace. - */ - public static JsonObject exceptionStatus(Throwable th) { - JsonObjectBuilder job = Json.createObjectBuilder(); - job.add("status", "exception"); - JsonArrayBuilder jabSt = Json.createArrayBuilder(); - Throwable current = th; - while (current != null) { - jabSt.add(buildStackTrace(current)); - current = current.getCause(); - } - job.add("stacktrace", jabSt.build()); - return job.build(); - } - - private static JsonObject buildStackTrace(Throwable t) { - JsonObjectBuilder jobSt = Json.createObjectBuilder(); - jobSt.add("class", t.getClass().getName()); - jobSt.add("message", t.getMessage()); - JsonArrayBuilder jab = Json.createArrayBuilder(); - StackTraceElement[] elements = t.getStackTrace(); - if (elements != null) { - for (StackTraceElement element : elements) { - JsonObjectBuilder jobElement = Json.createObjectBuilder(); - jobElement.add("file", element.getFileName() != null ? Json.createValue(element.getFileName()) : JsonValue.NULL); - jobElement.add("line", element.getLineNumber()); - jobElement.add("module", element.getModuleName() != null ? Json.createValue(element.getModuleName()) : JsonValue.NULL); - jobElement.add("modVersion", element.getModuleVersion() != null ? Json.createValue(element.getModuleVersion()) : JsonValue.NULL); - jobElement.add("loader", element.getClassLoaderName() != null ? Json.createValue(element.getClassLoaderName()) : JsonValue.NULL); - jobElement.add("class", Json.createValue(element.getClassName())); - jobElement.add("method", Json.createValue(element.getMethodName())); - jab.add(jobElement.build()); - } - } - jobSt.add("trace", jab.build()); - return jobSt.build(); - } - -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/HelidonProcessRunner.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/HelidonProcessRunner.java deleted file mode 100644 index 0e528df8668..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/HelidonProcessRunner.java +++ /dev/null @@ -1,480 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.lang.System.Logger.Level; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketAddress; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * Process runner to start Helidon application. - * Handles external process life cycle with various execution types. - */ -public class HelidonProcessRunner { - - private static final System.Logger LOGGER = System.getLogger(HelidonProcessRunner.class.getName()); - - /** - * HTTP port of running application. Value is set to {@code -1} before application will be started. - */ - public static int HTTP_PORT = -1; - - private final AtomicReference process = new AtomicReference<>(); - private final ExecType execType; - private final Runnable startCommand; - private final Runnable stopCommand; - private final int port; - - private HelidonProcessRunner(Builder builder) { - this.execType = builder.execType; - this.port = findFreePort(); - if (execType == ExecType.IN_MEMORY) { - this.startCommand = builder.inMemoryStartCommand; - this.stopCommand = builder.inMemoryStopCommand; - System.setProperty("server.port", String.valueOf(port)); - } else { - ProcessBuilder pb = new ProcessBuilder(); - pb.environment().put("SERVER_PORT", String.valueOf(port)); - switch (execType) { - case CLASS_PATH -> addClasspathCommand(builder, pb); - case MODULE_PATH -> addModulePathCommand(builder, pb); - case NATIVE -> addNativeCommand(builder, pb); - case JLINK_CLASS_PATH -> addJlinkCommand(builder, pb); - case JLINK_MODULE_PATH -> addJlinkModuleCommand(builder, pb); - default -> throw new IllegalArgumentException("Unsupported exec type: " + execType); - } - startCommand = () -> { - try { - // configure redirects - Thread stdoutReader = new Thread(() -> logStdout(process)); - Thread stderrReader = new Thread(() -> logStderr(process)); - - process.set(pb.start()); - - stdoutReader.start(); - stderrReader.start(); - - waitForSocketOpen(process.get(), port); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException("Failed to start process", e); - } - }; - stopCommand = () -> { - Process p = process.get(); - if (p == null || !p.isAlive()) { - return; - } - p.destroy(); - }; - } - } - - /** - * Create a new builder. - * - * @return builder - */ - public static Builder builder() { - return new Builder(); - } - - /** - * Start the application. - * Value of {@code HTTP_PORT} is set to HTTP port of this application. - * - * @return this instance - */ - public HelidonProcessRunner startApplication() { - startCommand.run(); - HTTP_PORT = port; - return this; - } - - /** - * Return type of execution for the application. - * - * @return type of execution for the application - */ - public ExecType execType() { - return execType; - } - - /** - * Stop the application. - * Value of {@code HTTP_PORT} is set to {@code -1}. - * - * @return this instance - */ - public HelidonProcessRunner stopApplication() { - stopCommand.run(); - if (process.get() != null) { - process.get().destroy(); - } - HTTP_PORT = -1; - return this; - } - - private static void waitForSocketOpen(Process process, int port) { - long timeoutSeconds = 20; - long timeout = TimeUnit.SECONDS.toMillis(timeoutSeconds); - - long begin = System.currentTimeMillis(); - LOGGER.log(Level.TRACE, () -> String.format("Waiting for %d to listen", port)); - while (true) { - // check port open - if (portOpen(port)) { - return; - } - // make sure process still alive - if (!process.isAlive()) { - throw new RuntimeException("Process failed to start. Exit code: " + process.exitValue()); - } - // sleep - try { - TimeUnit.MILLISECONDS.sleep(150); - } catch (InterruptedException e) { - process.destroyForcibly(); - throw new RuntimeException("Cancelling process startup, thread interrupted", e); - } - // timeout - long now = System.currentTimeMillis(); - if (now - begin > timeout) { - process.destroyForcibly(); - throw new RuntimeException("Process failed to start, time out after " + timeoutSeconds + " seconds"); - } - } - } - - private static boolean portOpen(int port) { - SocketAddress sa = new InetSocketAddress("localhost", port); - try (Socket socket = new Socket()) { - socket.connect(sa, 1000); - LOGGER.log(Level.TRACE, () -> String.format("Socket localhost:%d is ready", port)); - return true; - } catch (IOException ex) { - LOGGER.log(Level.TRACE, () -> String.format("Socket localhost:%d exception: %s", port, ex.getMessage())); - return false; - } - } - - private static int findFreePort() { - int port = 7001; - - try (ServerSocket socket = new ServerSocket(0)) { - socket.setReuseAddress(true); - port = socket.getLocalPort(); - } catch (IOException e) { - LOGGER.log(Level.WARNING, "Could not find available port, using 7001", e); - } - - return port; - } - - private static void logStdout(AtomicReference process) { - BufferedReader reader = new BufferedReader( - new InputStreamReader(process.get().getInputStream())); - String line; - try { - line = reader.readLine(); - while (line != null) { - System.out.println("* " + line); - line = reader.readLine(); - } - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } - - /** - * Log the process standard error. - */ - private static void logStderr(AtomicReference process) { - BufferedReader reader = new BufferedReader( - new InputStreamReader(process.get().getErrorStream())); - String line; - try { - line = reader.readLine(); - while (line != null) { - System.err.println("* " + line); - line = reader.readLine(); - } - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } - - private static void addModulePathCommand(Builder builder, ProcessBuilder processBuilder) { - addModuleCommand("java", - "target", - builder.finalName, - builder.moduleName, - builder.mainClassModuleName, - builder.mainClass, - builder.args, - processBuilder); - } - - private static void addJlinkModuleCommand(Builder builder, ProcessBuilder processBuilder) { - String jriDir = "target/" + builder.finalName + "-jri"; - - // FIXME instead of java, we should use the jriDir + "/bin/start" command with a switch such as "--modules" - addModuleCommand(jriDir + "/bin/java", - jriDir + "/app", - builder.finalName, - builder.moduleName, - builder.mainClassModuleName, - builder.mainClass, - builder.args, - processBuilder); - } - - private static void addModuleCommand(String java, - String location, - String finalName, - String moduleName, - String mainClassModuleName, - String mainClass, - String[] args, - ProcessBuilder processBuilder) { - - List command = new ArrayList<>(6); - command.add(java); - command.add("--module-path"); - command.add(location + "/" + finalName + ".jar" + File.pathSeparator + "target/libs"); - command.add("--module"); - command.add(mainClassModuleName + "/" + mainClass); - - if (!Objects.equals(moduleName, mainClassModuleName)) { - // we are running main class from another module, need to add current module - command.add("--add-modules"); - command.add(moduleName); - } - - LOGGER.log(Level.DEBUG, () -> String.format("Command: %s", command)); - processBuilder.command(buildCommand(args, command)); - } - - private static void addJlinkCommand(Builder builder, ProcessBuilder processBuilder) { - String jriDir = "target/" + builder.finalName + "-jri"; - // FIXME - instead of java -jar, we should use the jriDir + "/bin/start" command - processBuilder.command( - buildCommand(builder.args, - jriDir + "/bin/java", - "-jar", - jriDir + "/app/" + builder.finalName + ".jar")); - } - - private static void addClasspathCommand(Builder builder, ProcessBuilder processBuilder) { - processBuilder.command( - buildCommand(builder.args, "java", "-jar", "target/" + builder.finalName + ".jar")); - } - - private static void addNativeCommand(Builder builder, ProcessBuilder processBuilder) { - processBuilder.command(buildCommand(builder.args, "target/" + builder.finalName)); - } - - private static List buildCommand(String[] args, String... command) { - return buildCommand(args, Arrays.asList(command)); - } - - private static List buildCommand(String[] args, List command) { - final List commandList = new LinkedList<>(command); - if (args != null) { - commandList.addAll(Arrays.asList(args)); - } - return commandList; - } - - /** - * Return HTTP port of the application. - * - * @return HTTP port of the application - */ - public int port() { - return port; - } - - /** - * Application execution types. - */ - public enum ExecType { - CLASS_PATH("classpath"), - MODULE_PATH("module"), - NATIVE("native"), - IN_MEMORY("memory"), - JLINK_CLASS_PATH("jlink-cp"), - JLINK_MODULE_PATH("jlink-module"); - - private final String name; - - ExecType(String name) { - this.name = name; - } - - @Override - public String toString() { - return name; - } - - private static final Map NAMES = Arrays.stream(ExecType.values()) - .collect(Collectors.toMap(ExecType::toString, Function.identity())); - - /** - * Get an exec type by name. - * - * @param name name - * @return ExecType - * @throws IllegalArgumentException if no exec type is found - */ - public static ExecType of(String name) { - ExecType execType = NAMES.get(name.toLowerCase()); - if (execType != null) { - return execType; - } - throw new IllegalArgumentException("Unknown execType: " + name); - } - } - - /** - * Builder for {@link HelidonProcessRunner}. - */ - public static class Builder implements io.helidon.common.Builder { - - private ExecType execType = ExecType.CLASS_PATH; - private String moduleName; - private String mainClassModuleName; - private String mainClass; - private String finalName; - private String[] args; - private Runnable inMemoryStartCommand; - private Runnable inMemoryStopCommand; - - /** - * Set the type of execution. - * - * @param execType type of execution - * @return this builder - */ - public Builder execType(ExecType execType) { - this.execType = execType; - return this; - } - - /** - * Set the name of the application module (JPMS), used for {@link ExecType#MODULE_PATH} - * - * @param moduleName module name - * @return this builder - */ - public Builder moduleName(String moduleName) { - this.moduleName = moduleName; - return this; - } - - /** - * Set the name of the module of the main class (JPMS) - used for {@link ExecType#MODULE_PATH} - * - * @param mainClassModuleName module main class - * @return this builder - */ - public Builder mainClassModuleName(String mainClassModuleName) { - this.mainClassModuleName = mainClassModuleName; - return this; - } - - /** - * Set the name of the main class to run, used for {@link ExecType#MODULE_PATH} - * - * @param mainClass main class - * @return this builder - */ - public Builder mainClass(String mainClass) { - this.mainClass = mainClass; - return this; - } - - /** - * Set the final name of the artifact. - * This is the expected name of the native image and jar file - * - * @param finalName final name - * @return this builder - */ - public Builder finalName(String finalName) { - this.finalName = finalName; - return this; - } - - /** - * Set the arguments passed to main method. - * - * @param args main args - * @return this builder - */ - public Builder args(String[] args) { - this.args = args; - return this; - } - - /** - * Set the command to start the server in memory, used for {@link ExecType#IN_MEMORY} - * - * @param inMemoryStartCommand in-memory start command - * @return this builder - */ - public Builder inMemoryStartCommand(Runnable inMemoryStartCommand) { - this.inMemoryStartCommand = inMemoryStartCommand; - return this; - } - - /** - * Set the command to stop the server in memory, used for {@link ExecType#IN_MEMORY} - * - * @param inMemoryStopCommand in-memory stop command - * @return this builder - */ - public Builder inMemoryStopCommand(Runnable inMemoryStopCommand) { - this.inMemoryStopCommand = inMemoryStopCommand; - return this; - } - - @Override - public HelidonProcessRunner build() { - if (mainClassModuleName == null) { - mainClassModuleName = moduleName; - } - return new HelidonProcessRunner(this); - } - } -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/HelidonTestException.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/HelidonTestException.java deleted file mode 100644 index 41ea798271f..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/HelidonTestException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -/** - * Thrown to report error in integration test execution. - */ -public class HelidonTestException extends RuntimeException { - - /** - * Creates an instance of {@code HelidonTestException} with remote cause. - * - * @param message the detail message. The detail message is saved for - * later retrieval by the {@link #getMessage()} method. - * @param cause cause - */ - public HelidonTestException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Creates an instance of {@code HelidonTestException} with no cause. - * - * @param message the detail message. The detail message is saved for - * later retrieval by the {@link #getMessage()} method. - */ - public HelidonTestException(String message) { - super(message); - } - -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/JsonValues.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/JsonValues.java deleted file mode 100644 index c415584f1d5..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/JsonValues.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -import jakarta.json.JsonNumber; -import jakarta.json.JsonString; -import jakarta.json.JsonValue; - -/** - * JSON values. - */ -public class JsonValues { - - /** - * Get a {@link JsonValue} as a {@link String}. - * - * @param value value - * @return String - * @throws IllegalArgumentException if the value type cannot be converted - */ - public static String asString(JsonValue value) { - return switch (value.getValueType()) { - case STRING -> ((JsonString) value).getString(); - case NULL -> null; - default -> throw new IllegalArgumentException(String.format( - "Cannot convert JSON value to String, value: '%s', type: %s", - value, value.getValueType())); - }; - } - - /** - * Get a {@link JsonValue} as a {@code long}. - * - * @param value value - * @return long - * @throws IllegalArgumentException if the value type cannot be converted - */ - public static long asLong(JsonValue value) { - return switch (value.getValueType()) { - case NUMBER -> ((JsonNumber) value).longValue(); - case STRING -> Long.parseLong(((JsonString) value).getString()); - case TRUE -> 1; - case FALSE -> 0; - default -> throw new IllegalArgumentException(String.format( - "Cannot convert JSON value to long, value: '%s', type: %s", - value, value.getValueType())); - }; - } -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/PathFinder.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/PathFinder.java new file mode 100644 index 00000000000..ac52aec0b3b --- /dev/null +++ b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/PathFinder.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.harness; + +import java.io.File; +import java.lang.System.Logger.Level; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Stream; + +/** + * Path utility class. + */ +public class PathFinder { + + private static final System.Logger LOGGER = System.getLogger(PathFinder.class.getName()); + private static final boolean IS_WINDOWS = File.pathSeparatorChar != ':'; + private static final String PATH_ENV_VAR = "PATH"; + private static final List WINDOWS_EXECUTABLE_EXTENSIONS = List.of("exe", "bin", "bat", "cmd", "ps1"); + private static final Predicate VALID_PATH = p -> Files.exists(p) && Files.isDirectory(p); + private static final List PATH_ENTRIES = + Optional.ofNullable(System.getenv(PATH_ENV_VAR)) + .map(p -> Arrays.asList(p.split(File.pathSeparator))) + .stream() + .flatMap(Collection::stream) + .map(Path::of) + .filter(VALID_PATH) + .toList(); + + private PathFinder() { + } + + private static Path findWindowsCmd(Path dir, String cmd) { + return WINDOWS_EXECUTABLE_EXTENSIONS.stream() + .map((ext) -> dir.resolve(cmd + "." + ext)) + .filter(Files::isRegularFile) + .findFirst() + .orElse(null); + } + + private static Path findCmd(Path dir, String cmd) { + LOGGER.log(Level.DEBUG, String.format("Searching for cmd: %s in %s", cmd, dir)); + Path cmdFile = dir.resolve(cmd); + if (Files.isRegularFile(cmdFile)) { + return cmdFile; + } + return IS_WINDOWS ? findWindowsCmd(dir, cmd) : null; + } + + /** + * Find a file in the system path. + * + * @param fileName file to find + * @param envVar override + * @return optional + */ + public static Optional find(String fileName, String envVar) { + return Stream.concat( + Optional.ofNullable(System.getenv(envVar)) + .map(Path::of) + .map(p -> p.resolve("bin")) + .stream() + .filter(VALID_PATH), + PATH_ENTRIES.stream()) + .flatMap(dir -> Optional.ofNullable(findCmd(dir, fileName)).stream()) + .findFirst(); + } +} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessMonitor.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessMonitor.java new file mode 100644 index 00000000000..34db00f3377 --- /dev/null +++ b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessMonitor.java @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.harness; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import io.helidon.common.LazyValue; + +/** + * Process monitor. + */ +public final class ProcessMonitor implements AutoCloseable { + + private static final System.Logger LOGGER = System.getLogger(ProcessMonitor.class.getName()); + private static final LazyValue SHUTDOWN = LazyValue.create(ShutdownThread::new); + private static final String PORT_REGEX = ".* http://localhost:([0-9]*) ?.*"; + private static final Pattern PORT_PATTERN = Pattern.compile(PORT_REGEX); + private static final String LINE_SEP = System.lineSeparator(); + + private final Lock outputLock = new ReentrantLock(); + private final StringBuilder output = new StringBuilder(); + private final int port; + private final Process process; + private final WaitStrategy waitStrategy; + + ProcessMonitor(ProcessBuilder pb, int port, WaitStrategy waitStrategy) { + try { + this.port = port; + this.waitStrategy = waitStrategy; + LOGGER.log(System.Logger.Level.INFO, "Executing " + String.join(" ", pb.command())); + Thread stdoutReader = new Thread(this::logStdout); + Thread stderrReader = new Thread(this::logStderr); + process = pb.start(); + SHUTDOWN.get().add(process); + stdoutReader.start(); + stderrReader.start(); + } catch (Throwable ex) { + throw new RuntimeException("Failed to start process", ex); + } + } + + @Override + public void close() { + stop(); + } + + /** + * Stop the process. + */ + public void stop() { + if (process != null && process.isAlive()) { + LOGGER.log(System.Logger.Level.INFO, "Stopping process: " + process.pid()); + process.destroy(); + SHUTDOWN.get().remove(process); + } + } + + /** + * Get the process. + * + * @return Process + */ + public Process get() { + return process; + } + + /** + * Get the process combined output. + * + * @return output + */ + public String output() { + return output.toString(); + } + + /** + * Wait for the {@link WaitStrategy strategy}. + * + * @return this instance + */ + public ProcessMonitor await() { + return await(waitStrategy); + } + + /** + * Wait for the given {@link WaitStrategy strategy}. + * + * @param waitStrategy wait strategy. + * @return this instance + */ + public ProcessMonitor await(WaitStrategy waitStrategy) { + waitStrategy.await(this, port); + return this; + } + + /** + * Get the port. + * + * @return port + */ + public int port() { + return port > 0 ? port : resolvePort(); + } + + private int resolvePort() { + return output().lines() + .map(PORT_PATTERN::matcher) + .filter(Matcher::matches) + .findFirst() + .map(m -> m.group(1)) + .map(Integer::parseInt) + .orElseThrow(() -> new IllegalStateException("Unable to find port")); + } + + private void logStdout() { + logStream(process.getInputStream(), System.out); + } + + private void logStderr() { + logStream(process.getErrorStream(), System.err); + } + + private void logStream(InputStream is, PrintStream printStream) { + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + try { + String line = reader.readLine(); + while (line != null) { + printStream.println(line); + printStream.flush(); + outputLock.lock(); + output.append(line).append(LINE_SEP); + outputLock.unlock(); + line = reader.readLine(); + } + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + + private static final class ShutdownThread extends Thread { + + private final List processes = Collections.synchronizedList(new ArrayList<>()); + + ShutdownThread() { + Runtime.getRuntime().addShutdownHook(this); + } + + void add(Process process) { + processes.add(process); + } + + void remove(Process process) { + processes.remove(process); + } + + @Override + public void run() { + // use a copy to avoid concurrent modifications + for (Process process : List.copyOf(processes)) { + if (process.isAlive()) { + LOGGER.log(System.Logger.Level.INFO, "Stopping process: " + process.pid()); + process.destroyForcibly(); + } + } + } + } +} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessRunner.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessRunner.java new file mode 100644 index 00000000000..e26fc0fe572 --- /dev/null +++ b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessRunner.java @@ -0,0 +1,500 @@ +/* + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.harness; + +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.ServerSocket; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static java.util.Objects.requireNonNull; + +/** + * Fluent process runner. + */ +@SuppressWarnings("unused") +public abstract class ProcessRunner { + + private static final boolean IS_WINDOWS = File.pathSeparatorChar != ':'; + private static final Pattern VAR_PATTERN = Pattern.compile("[^$]*\\$\\{(?[^}]+)}[^$]*"); + + private final AtomicReference ref = new AtomicReference<>(); + private final List>> lazyProps = new ArrayList<>(); + private final List>> lazyEnv = new ArrayList<>(); + private final List>> lazyOpts = new ArrayList<>(); + private final List>> lazyArgs = new ArrayList<>(); + + protected String moduleName; + protected String mainModule; + protected String mainClass; + protected String finalName; + protected WaitStrategy waitStrategy = WaitStrategy.waitForCompletion(); + protected int port = -1; + + private ProcessRunner() { + } + + /** + * Execution mode. + */ + public enum ExecMode { + /** + * Execute processes using class path. + */ + CLASS_PATH, + + /** + * Execute processes using module path. + */ + MODULE_PATH, + + /** + * Execute native processes. + */ + NATIVE, + + /** + * Execute processes using the Helidon jlink start script. + */ + JLINK_CLASS_PATH, + + /** + * Execute processes using the Helidon jlink distribution with module path. + */ + JLINK_MODULE_PATH + } + + /** + * Create a new process runner. + * + * @param execMode execution mode + * @return ProcessRunner + */ + public static ProcessRunner of(ExecMode execMode) { + return switch (execMode) { + case CLASS_PATH -> new ClassPathRunner(); + case NATIVE -> new NativeImageRunner(); + case MODULE_PATH -> new ModulePathRunner(); + case JLINK_CLASS_PATH -> new JlinkRunner(); + case JLINK_MODULE_PATH -> new JlinkModulePathRunner(); + }; + } + + /** + * Get the last started process. + * + * @return ProcessMonitor + * @throws IllegalStateException if the process is not started + */ + public ProcessMonitor process() { + ProcessMonitor process = ref.get(); + if (process == null) { + throw new IllegalStateException("Process is not started"); + } + return process; + } + + /** + * Set the port. + * + * @param port port, {@code 0} overrides the configured port with a free port + * @return this instance + */ + public ProcessRunner port(int port) { + this.port = port; + return this; + } + + /** + * Set environment variables. + * + * @param env environment variables + * @return this instance + */ + public ProcessRunner env(Map env) { + return env(() -> env); + } + + /** + * Set environment variables. + * + * @param env environment variables + * @return this instance + */ + public ProcessRunner env(Supplier> env) { + this.lazyEnv.add(env); + return this; + } + + /** + * Set system properties. + * + * @param props properties + * @return this instance + */ + public ProcessRunner properties(Map props) { + return properties(() -> props); + } + + /** + * Set system properties. + * + * @param props properties + * @return this instance + */ + public ProcessRunner properties(Supplier> props) { + this.lazyProps.add(props); + return this; + } + + /** + * Set the arguments passed to main method. + * + * @param args main args + * @return this instance + */ + public ProcessRunner args(String... args) { + return args(() -> Arrays.asList(args)); + } + + /** + * Set the arguments passed to main method. + * + * @param args main args + * @return this instance + */ + public ProcessRunner args(List args) { + return args(() -> args); + } + + /** + * Set the arguments passed to main method. + * + * @param args main args + * @return this instance + */ + public ProcessRunner args(Supplier> args) { + this.lazyArgs.add(args); + return this; + } + + /** + * Set the options passed to the executable. + * + * @param opts opts + * @return this instance + */ + public ProcessRunner opts(String... opts) { + return opts(() -> Arrays.asList(opts)); + } + + /** + * Set the options passed to the executable. + * + * @param opts opts + * @return this instance + */ + public ProcessRunner opts(List opts) { + return opts(() -> opts); + } + + /** + * Set the options passed to the executable. + * + * @param opts opts + * @return this instance + */ + public ProcessRunner opts(Supplier> opts) { + this.lazyOpts.add(opts); + return this; + } + + /** + * Set the name of the application module (JPMS), used for + * {@link ProcessRunner.ExecMode#MODULE_PATH} + * + * @param moduleName module name + * @return this instance + */ + public ProcessRunner moduleName(String moduleName) { + this.moduleName = requireNonNull(moduleName, "moduleName is null"); + return this; + } + + /** + * Set the name of the module of the main class (JPMS) - used for + * {@link ProcessRunner.ExecMode#MODULE_PATH} + * + * @param mainModule main module + * @return this instance + */ + public ProcessRunner mainModule(String mainModule) { + this.mainModule = requireNonNull(mainModule, "mainModule is null"); + return this; + } + + /** + * Set the name of the main class to run, used for + * {@link ProcessRunner.ExecMode#MODULE_PATH} + * + * @param mainClass main class + * @return this instance + */ + public ProcessRunner mainClass(String mainClass) { + this.mainClass = requireNonNull(mainClass, "mainClass is null"); + return this; + } + + /** + * Set the final name of the artifact. + * This is the expected name of the native image and jar file + * + * @param finalName final name + * @return this instance + */ + public ProcessRunner finalName(String finalName) { + this.finalName = requireNonNull(finalName, "finalName is null"); + return this; + } + + /** + * Set the waiting strategy. + * + * @param waitStrategy waiting strategy + * @return this builder + * @see WaitStrategy + */ + public ProcessRunner waitingFor(WaitStrategy waitStrategy) { + this.waitStrategy = Objects.requireNonNull(waitStrategy, "waitStrategy is null"); + return this; + } + + /** + * Build the command. + * + * @param opts resolved options + * @param args resolved args + * @return command + */ + protected abstract List command(List opts, List args); + + /** + * Start the process. + * + * @return ProcessMonitor + */ + public ProcessMonitor start() { + int port = resolvePort(); + List opts = resolveOpts(port); + List args = toList(lazyArgs); + Map env = resolveEnv(port); + ProcessBuilder pb = new ProcessBuilder(command(opts, args)); + env.forEach((k, v) -> pb.environment().put(k, toString(v))); + ProcessMonitor monitor = new ProcessMonitor(pb, port, waitStrategy); + ref.set(monitor); + return monitor; + } + + private int resolvePort() { + if (port == 0) { + try (ServerSocket socket = new ServerSocket(0)) { + socket.setReuseAddress(true); + return socket.getLocalPort(); + } catch (IOException e) { + throw new UncheckedIOException("Unable to get free port", e); + } + } + return port; + } + + private Map resolveProps(int port) { + Map props = toMap(lazyProps); + if (port > 0) { + props.putIfAbsent("server.port", port); + } + return props; + } + + private Map resolveEnv(int port) { + Map env = toMap(lazyEnv); + if (port > 0) { + env.putIfAbsent("SERVER_PORT", port); + } + return env; + } + + private List resolveOpts(int port) { + List opts = toList(lazyOpts); + Map props = resolveProps(port); + resolve(props).forEach((k, v) -> opts.add("-D" + k + "=" + v)); + return opts; + } + + private static List toList(List>> lazy) { + List list = new ArrayList<>(); + lazy.forEach(m -> m.get().forEach(v -> { + if (v instanceof Supplier s) { + list.add(toString(s.get())); + } else { + list.add(toString(v)); + } + })); + return list; + } + + private static Map toMap(List>> lazy) { + Map map = new HashMap<>(); + lazy.forEach(m -> m.get().forEach((k, v) -> { + if (v instanceof Supplier s) { + map.put(k, s.get()); + } else { + map.put(k, v); + } + })); + return map; + } + + private static String toString(Object o) { + if (o instanceof Path path) { + return path.toAbsolutePath().normalize().toString(); + } + return o.toString(); + } + + private static Map resolve(Map entries) { + Map map = new HashMap<>(); + entries.forEach((k, v) -> map.put(k, resolve(toString(v), s -> toString(entries.getOrDefault(s, ""))))); + return map; + } + + private static String resolve(String str, Function function) { + StringBuilder sb = new StringBuilder(); + Matcher m = VAR_PATTERN.matcher(str); + int index = 0; + while (m.find()) { + sb.append(str, index, m.start(1) - 2); + sb.append(function.apply(m.group(1))); + index = m.end(1) + 1; + } + sb.append(str.substring(index)); + return sb.toString(); + } + + private static String javaExecutable() { + return PathFinder.find("java", "JAVA_HOME") + .map(Path::toString) + .orElseThrow(() -> new IllegalStateException("Unable to find java")); + } + + private static final class ClassPathRunner extends ProcessRunner { + + @Override + protected List command(List opts, List args) { + Objects.requireNonNull(finalName, "finalName is null"); + return new CommandBuilder(javaExecutable()) + .append(opts) + .append("-jar", Path.of("target/" + finalName + ".jar")) + .append(args) + .command(); + } + } + + private static class ModulePathRunner extends ProcessRunner { + + Path dir() { + return Path.of("target"); + } + + @Override + protected List command(List opts, List args) { + Objects.requireNonNull(mainClass, "mainClass is null"); + Objects.requireNonNull(moduleName, "moduleName is null"); + Objects.requireNonNull(finalName, "finalName is null"); + CommandBuilder cb = new CommandBuilder(javaExecutable()); + String module = mainModule != null ? mainModule : moduleName; + cb.append(opts) + .append("--module-path") + .append(dir().resolve(finalName + ".jar") + File.pathSeparator + dir().resolve("libs")) + .append("--module") + .append(module + "/" + mainClass); + if (!Objects.equals(module, moduleName)) { + // we are running main class from another module, need to add current module + cb.append("--add-modules").append(moduleName); + } + return cb.command(); + } + } + + private static final class NativeImageRunner extends ProcessRunner { + + @Override + protected List command(List opts, List args) { + Objects.requireNonNull(finalName, "finalName is null"); + return new CommandBuilder("target/" + finalName + (IS_WINDOWS ? ".exe" : "")) + .append(opts) + .append(args) + .command(); + } + } + + private static final class JlinkRunner extends ProcessRunner { + + @Override + protected List command(List opts, List args) { + Objects.requireNonNull(finalName, "finalName is null"); + return new CommandBuilder("target/" + finalName + "-jri/bin/start" + (IS_WINDOWS ? ".ps1" : "")) + .append("--jvm", String.join(" ", opts)) + .append(args) + .command(); + } + } + + private static final class JlinkModulePathRunner extends ModulePathRunner { + + @Override + protected Path dir() { + return Path.of("target/" + finalName + "-jri/app"); + } + } + + private record CommandBuilder(List command) { + + CommandBuilder(String bin) { + this(new ArrayList<>(List.of(Path.of(bin).toString()))); + } + + CommandBuilder append(List fragments) { + fragments.forEach(f -> command.add(f.toString())); + return this; + } + + CommandBuilder append(Object... fragments) { + return append(Arrays.asList(fragments)); + } + } +} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessRunnerExtension.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessRunnerExtension.java new file mode 100644 index 00000000000..b55d4dd7405 --- /dev/null +++ b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessRunnerExtension.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.harness; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.List; + +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource; + +/** + * A JUnit extension that manages the lifecycle of {@link ProcessRunner} instances annotated with {@link TestProcess}. + */ +public class ProcessRunnerExtension implements BeforeAllCallback { + + private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace.create(ProcessRunnerExtension.class); + + @Override + public void beforeAll(ExtensionContext context) throws Exception { + Class testClass = context.getRequiredTestClass(); + List runners = findProcessRunners(testClass); + ExtensionContext.Store store = context.getStore(NAMESPACE); + String key = testClass.getName(); + TestProcesses testProcesses = findTestProcesses(testClass); + List monitors = new ArrayList<>(); + if (testProcesses != null && testProcesses.parallel()) { + runners.forEach(p -> monitors.add(p.start())); + monitors.forEach(r -> store.put(key, (CloseableResource) r::close)); + monitors.forEach(ProcessMonitor::await); + } else { + //noinspection resource + runners.forEach(r -> store.put(key, (CloseableResource) r.start().await()::close)); + } + } + + private static TestProcesses findTestProcesses(Class testClass) { + for (Class clazz : allTypes(testClass)) { + if (clazz.isAnnotationPresent(TestProcesses.class)) { + return clazz.getDeclaredAnnotation(TestProcesses.class); + } + } + return null; + } + + private static List findProcessRunners(Class testClass) throws IllegalAccessException { + List runners = new ArrayList<>(); + for (Class clazz : allTypes(testClass)) { + for (Method method : clazz.getDeclaredMethods()) { + if (Modifier.isStatic(method.getModifiers()) && method.isAnnotationPresent(TestProcess.class)) { + try { + method.setAccessible(true); + Object value = method.invoke(null); + if (value instanceof ProcessRunner pr) { + runners.add(pr); + } + } catch (InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + for (Field field : clazz.getDeclaredFields()) { + if (Modifier.isStatic(field.getModifiers()) && field.isAnnotationPresent(TestProcess.class)) { + field.setAccessible(true); + Object value = field.get(null); + if (value instanceof ProcessRunner pr) { + runners.add(pr); + } + } + } + } + return runners; + } + + private static List> allTypes(Class clazz) { + List> types = new ArrayList<>(); + Deque> stack = new ArrayDeque<>(); + stack.push(clazz); + while (!stack.isEmpty()) { + Class aClass = stack.pop(); + types.add(aClass); + Class superclass = aClass.getSuperclass(); + if (superclass != null) { + stack.push(superclass); + } + for (Class interfaceClass : aClass.getInterfaces()) { + stack.push(interfaceClass); + } + } + return types; + } +} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/RemoteTestException.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/RemoteTestException.java deleted file mode 100644 index f4114b3b73f..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/RemoteTestException.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -/** - * Exception in remote test application. - */ -public class RemoteTestException extends RuntimeException { - - /** - * Creates an instance of remote test exception. - * - * @param message detail message - */ - public RemoteTestException(String message) { - super(message); - } - - /** - * Creates an instance of remote test exception. - * - * @param fmt formatted message - * @param args formatted message arguments - */ - public RemoteTestException(String fmt, Object... args) { - super(String.format(fmt, args)); - } -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteContext.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteContext.java deleted file mode 100644 index 1a11dc677da..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteContext.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -import java.lang.reflect.Array; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; - -/** - * Suite context. - */ -public final class SuiteContext { - - private final String id; - private final Class suiteClass; - private final CompletableFuture future = new CompletableFuture<>(); - private final Map parameters = new HashMap<>(); - - /** - * Create a new instance. - * - * @param suiteClass suite class - * @param suiteId suite id - */ - SuiteContext(Class suiteClass, String suiteId) { - this.suiteClass = suiteClass; - this.id = suiteId; - } - - /** - * Get the suite id. - * - * @return suite id - */ - public String suiteId() { - return id; - } - - /** - * Get the suite class. - * - * @return class - */ - public Class suiteClass() { - return suiteClass; - } - - /** - * Get the future. - * - * @return future - */ - public CompletionStage future() { - return future; - } - - /** - * Get the suite parameters. - * - * @return parameters - */ - public Map parameters() { - return parameters; - } - - /** - * Get the first parameter that matches the given type. - * - * @param paramType parameter type - * @param parameter type - * @return parameter value - */ - @SuppressWarnings("unchecked") - public Optional parameter(Class paramType) { - return parameters.values() - .stream() - .filter(o -> { - Class type; - if (paramType.isPrimitive()) { - type = Array.get(Array.newInstance(paramType, 1), 0).getClass(); - } else { - type = paramType; - } - return type.isAssignableFrom(o.getClass()); - }) - .map(o -> (T) o) - .findFirst(); - } -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteFinder.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteFinder.java deleted file mode 100644 index aef316f82b4..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteFinder.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.platform.engine.TestExecutionResult; -import org.junit.platform.engine.support.descriptor.ClassSource; -import org.junit.platform.launcher.TestExecutionListener; -import org.junit.platform.launcher.TestIdentifier; -import org.junit.platform.suite.api.Suite; - -/** - * A {@link TestExecutionListener} that identifies {@link Suite}. - */ -public class SuiteFinder implements TestExecutionListener { - - private static final Map INFOS = new HashMap<>(); - - /** - * Get a suite info for a test id. - * - * @param id test id - * @return suite info - */ - public static Optional findSuite(String id) { - return Optional.ofNullable(INFOS.get(id)) - .flatMap(suiteContext -> { - String suiteId = suiteContext.suiteId(); - if (!suiteId.equals(id)) { - return Optional.of(INFOS.get(suiteId)); - } - return Optional.of(suiteContext); - }); - } - - /** - * Get a suite info for an extension context. - * - * @param context extension context - * @return suite info - */ - public static Optional findSuite(ExtensionContext context) { - String suiteId = context.getParent().map(ExtensionContext::getUniqueId).orElse("?"); - return findSuite(suiteId); - } - - @Override - public void executionStarted(TestIdentifier testIdentifier) { - Class clazz = suiteClass(testIdentifier); - String id = testIdentifier.getUniqueId(); - if (clazz != null) { - INFOS.put(id, new SuiteContext(clazz, id)); - } else { - testIdentifier.getParentId().ifPresent(parentId -> { - SuiteContext suiteContext = INFOS.get(parentId); - if (suiteContext != null) { - INFOS.put(id, suiteContext); - } - }); - } - } - - @Override - public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { - String id = testIdentifier.getUniqueId(); - SuiteContext suiteContext = INFOS.get(testIdentifier.getUniqueId()); - if (suiteContext != null) { - if (suiteContext.suiteId().equals(id)) { - suiteContext.future().toCompletableFuture().complete(null); - } - } - } - - private static Class suiteClass(TestIdentifier testIdentifier) { - return testIdentifier.getSource() - .filter(ClassSource.class::isInstance) - .map(ClassSource.class::cast) - .map(ClassSource::getJavaClass) - .filter(source -> source.getAnnotation(Suite.class) != null) - .orElse(null); - } -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteLifeCycle.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteLifeCycle.java deleted file mode 100644 index d39c628502c..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteLifeCycle.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -import java.lang.annotation.Annotation; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.Parameter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.function.ToIntFunction; - -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.ExtensionContext.Store; - -import static java.util.Comparator.comparingInt; -import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL; - -/** - * An {@link BeforeAllCallback} extension that supports {@link BeforeSuite} and {@link AfterSuite}. - */ -public class SuiteLifeCycle implements BeforeAllCallback { - - private static final String STORE_KEY = SuiteLifeCycle.class.getName(); - private static final Comparator> BS_COMPARATOR = - comparator(BeforeSuite.class, value -> value.annotation().priority()); - private static final Comparator> AS_COMPARATOR = - comparator(AfterSuite.class, value -> value.annotation().priority()); - private static final Comparator> SETUP_COMPARATOR = - comparator(SetUp.class, value -> value.annotation().priority()); - - @Override - public void beforeAll(ExtensionContext context) { - SuiteFinder.findSuite(context).ifPresent(suiteContext -> { - Store store = context.getRoot().getStore(GLOBAL); - Object flag = store.get(STORE_KEY); - if (flag == null) { - store.put(STORE_KEY, this); - invokeBeforeSuite(suiteContext); - suiteContext.future().thenRun(() -> invokeAfterSuite(suiteContext)); - } - context.getTestClass().ifPresent( - clazz -> Arrays.stream(clazz.getMethods()) - .filter(method -> method.isAnnotationPresent(SetUp.class)) - .forEach(method -> handleSetUp(suiteContext, method)) - ); - }); - } - - private void handleBeforeSuite(SuiteContext context, Method method) { - Object value = invoke(BeforeSuite.class, method); - if (value instanceof Map map) { - Map params = context.parameters(); - map.forEach((k, v) -> params.put(k.toString(), v)); - } - } - - private void handleAfterSuite(SuiteContext context, Method method) { - invoke(AfterSuite.class, method, resolveParameters(context, method)); - } - - private void handleSetUp(SuiteContext context, Method method) { - invoke(SetUp.class, method, resolveParameters(context, method)); - } - - private void invokeBeforeSuite(SuiteContext suiteContext) { - findHandlers(suiteContext.suiteClass(), BeforeSuite.class) - .stream() - .sorted(BS_COMPARATOR) - .map(Handler::method) - .forEach(method -> handleBeforeSuite(suiteContext, method)); - } - - private void invokeAfterSuite(SuiteContext suiteContext) { - findHandlers(suiteContext.suiteClass(), AfterSuite.class) - .stream() - .sorted(AS_COMPARATOR) - .map(Handler::method) - .forEach(method -> handleAfterSuite(suiteContext, method)); - } - - private void invokeSetUp(SuiteContext suiteContext) { - findHandlers(suiteContext.suiteClass(), SetUp.class) - .stream() - .sorted(SETUP_COMPARATOR) - .map(Handler::method) - .forEach(method -> handleSetUp(suiteContext, method)); - } - - private static Object[] resolveParameters(SuiteContext context, Method method) { - List paramValues = new ArrayList<>(); - for (Parameter parameter : method.getParameters()) { - Class paramType = parameter.getType(); - Object paramValue = context.parameter(paramType) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "Method %s has a parameter %s that is not supported", - method, paramType))); - paramValues.add(paramValue); - } - return paramValues.toArray(new Object[0]); - } - - private static Object invoke(Class annotationClass, Method method, Object... args) { - try { - method.setAccessible(true); - return method.invoke(null, args); - } catch (IllegalAccessException | InvocationTargetException ex) { - throw new IllegalStateException(String.format( - "Cannot invoke %s method", - annotationClass.getSimpleName()), - ex); - } - } - - private static List> findHandlers(Class clazz, Class annotationClass) { - LinkedList> handlers = new LinkedList<>(); - LinkedList> hierarchy = new LinkedList<>(); - Class analyzedClass = clazz; - while (analyzedClass != null && !analyzedClass.equals(Object.class)) { - hierarchy.addFirst(analyzedClass); - analyzedClass = analyzedClass.getSuperclass(); - } - for (Class aClass : hierarchy) { - for (Method method : aClass.getDeclaredMethods()) { - T annotation = method.getDeclaredAnnotation(annotationClass); - if (annotation != null) { - if (Modifier.isStatic(method.getModifiers())) { - handlers.add(new Handler<>(annotation, method)); - } else { - throw new IllegalStateException("Method " + method + " is annotated with " - + annotationClass.getSimpleName() - + " yet it is not static"); - } - } - } - } - return handlers; - } - - private static Comparator> comparator(Class ignored, - ToIntFunction> function) { - return comparingInt(function); - } - - private record Handler(T annotation, Method method) { - } -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteParameterResolver.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteParameterResolver.java deleted file mode 100644 index 3e06279bee9..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SuiteParameterResolver.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -import java.lang.reflect.Parameter; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.ParameterContext; -import org.junit.jupiter.api.extension.ParameterResolutionException; -import org.junit.jupiter.api.extension.ParameterResolver; -import org.junit.platform.suite.api.Suite; - -/** - * A {@link ParameterResolver} to support {@link Suite}. - */ -public class SuiteParameterResolver implements ParameterResolver { - - @Override - public boolean supportsParameter(ParameterContext parameterContext, - ExtensionContext extensionContext) throws ParameterResolutionException { - - Class paramType = parameterContext.getParameter().getType(); - return SuiteFinder.findSuite(extensionContext) - .map(suite -> suite.parameter(paramType).isPresent()) - .orElse(false); - } - - @Override - public Object resolveParameter(ParameterContext parameterContext, - ExtensionContext extensionContext) throws ParameterResolutionException { - - Parameter parameter = parameterContext.getParameter(); - Class paramType = parameter.getType(); - return SuiteFinder.findSuite(extensionContext) - .flatMap(suite -> suite.parameter(paramType)) - .orElseThrow(() -> new ParameterResolutionException("Unable to resolve parameter: " + parameter)); - } -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestClient.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestClient.java deleted file mode 100644 index aa96b08b3c7..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestClient.java +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -import java.io.StringReader; -import java.io.UnsupportedEncodingException; -import java.lang.System.Logger.Level; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.time.Duration; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import io.helidon.common.media.type.MediaTypes; -import io.helidon.http.media.jsonp.JsonpSupport; -import io.helidon.webclient.http1.Http1Client; -import io.helidon.webclient.http1.Http1ClientRequest; - -import jakarta.json.Json; -import jakarta.json.JsonArray; -import jakarta.json.JsonException; -import jakarta.json.JsonObject; -import jakarta.json.JsonReader; -import jakarta.json.JsonString; -import jakarta.json.JsonValue; -import org.junit.jupiter.api.Assertions; - -/** - * Web client to access all services of remote test application. - */ -public class TestClient { - - private static final System.Logger LOGGER = System.getLogger(TestClient.class.getName()); - private static final String UTF_8_STR = StandardCharsets.UTF_8.toString(); - - private final Http1Client webClient; - - TestClient(Http1Client webClient) { - this.webClient = webClient; - } - - Http1ClientRequest clientGetBuilderWithPath(String service, String method) { - StringBuilder sb = new StringBuilder(service.length() + (method != null ? method.length() : 0) + 2); - sb.append('/'); - sb.append(service); - if (method != null) { - sb.append('/'); - sb.append(method); - } - return webClient.get(sb.toString()); - } - - private static String encode(String str) { - try { - return URLEncoder.encode(str, UTF_8_STR); - } catch (UnsupportedEncodingException ex) { - Assertions.fail(String.format("URL fragment encoding failed: %s", ex.getMessage())); - } - return ""; - } - - private static Exception deserialize(JsonObject response) { - Exception root = null; - Exception ex = null; - JsonArray stackTraces = response.getJsonArray("stacktrace"); - for (JsonObject stackTrace : stackTraces.getValuesAs(JsonObject.class)) { - List elements = new ArrayList<>(); - for (JsonObject elt : stackTrace.getJsonArray("trace").getValuesAs(JsonObject.class)) { - elements.add(new StackTraceElement( - toString(elt.get("class")), - toString(elt.get("method")), - toString(elt.get("file")), - elt.getInt("line"))); - } - Exception cause = new Exception(String.format("Deserialized: class=%s, message=%s", - toString(stackTrace.get("class")), toString(stackTrace.get("message")))); - cause.setStackTrace(elements.toArray(new StackTraceElement[0])); - if (ex == null) { - root = cause; - } else { - ex.initCause(cause); - } - ex = cause; - } - return root; - } - - private static String toString(JsonValue value) { - if (value.getValueType() == JsonValue.ValueType.STRING) { - return ((JsonString) value).getString(); - } - return "?"; - } - - /** - * Creates new web client builder instance. - * - * @return new web client builder instance - */ - public static Builder builder() { - return new Builder(); - } - - /** - * Call remote test service method and return its data. - * - * @param service remote service name - * @param method remote test method name - * @param params remote test method query parameters - * @return data returned by remote test service method - */ - public JsonValue callServiceAndGetData(String service, String method, Map params) { - return evaluateServiceCallResult( - callService( - clientGetBuilderWithPath(service, method), - params)); - } - - /** - * Call remote test service method and return its data. - * No query parameters are passed. - * - * @param service remote service name - * @param method remote test method name - * @return data returned by remote test service method - */ - public JsonValue callServiceAndGetData(String service, String method) { - return callServiceAndGetData(service, method, null); - } - - /** - * Call remote service method and return its raw data as JSON object. - * No response content check is done. - * - * @param service remote service name - * @param method remote test method name - * @param params remote test method query parameters - * @return data returned by remote service - */ - public JsonObject callServiceAndGetRawData(String service, String method, Map params) { - Http1ClientRequest rb = clientGetBuilderWithPath(service, method); - rb.headers().accept(MediaTypes.APPLICATION_JSON); - return callService(rb, params); - } - - /** - * Call remote service method and return its raw data as JSON object. - * No response content check is done. No query parameters are passed. - * - * @param service remote service name - * @param method remote test method name - * @return data returned by remote service - */ - public JsonObject callServiceAndGetRawData(String service, String method) { - return callServiceAndGetRawData(service, method, null); - } - - JsonObject callService(Http1ClientRequest clientRequest, Map params) { - if (params != null && !params.isEmpty()) { - for (Map.Entry entry : params.entrySet()) { - clientRequest.queryParam(entry.getKey(), encode(entry.getValue())); - } - } - String response = clientRequest.requestEntity(String.class); - try { - JsonReader jsonReader = Json.createReader(new StringReader(response)); - JsonValue jsonContent = jsonReader.read(); - if (Objects.requireNonNull(jsonContent.getValueType()) == JsonValue.ValueType.OBJECT) { - return jsonContent.asJsonObject(); - } - throw new HelidonTestException( - String.format( - "Expected JSON object, but got JSON %s", - jsonContent.getValueType().name().toLowerCase())); - } catch (JsonException t) { - LOGGER.log(Level.WARNING, () -> String.format("Caught %s when parsing response: %s", - t.getClass().getSimpleName(), - response), t); - throw new HelidonTestException( - String.format( - "Caught %s when parsing response: %s", - t.getClass().getSimpleName(), - response), - t); - } - } - - JsonValue evaluateServiceCallResult(JsonObject data) { - String status = data.getString("status"); - switch (status) { - case "OK" -> { - return data.get("data"); - } - case "exception" -> throw new HelidonTestException("Remote test execution failed.", deserialize(data)); - default -> throw new HelidonTestException("Unknown response content: " + data); - } - } - - /** - * Remote test web client builder. - */ - public static class Builder { - - @SuppressWarnings("HttpUrlsUsage") - private static final String HTTP_PREFIX = "http://"; - - private String host; - private int port; - - Builder() { - this.host = "localhost"; - this.port = 8080; - } - - /** - * Set test application URL host. - * - * @param host test application URL host - * @return updated {@code TestClient} builder instance - */ - public Builder host(String host) { - this.host = host; - return this; - } - - /** - * Set test application URL port. - * - * @param port test application URL port - * @return updated {@code TestClient} builder instance - */ - public Builder port(int port) { - this.port = port; - return this; - } - - /** - * Set test application URL service. - * Setting service name will result in building extended test client - * with service name support. - * - * @param service test application URL service - * @return updated {@code TestServiceClient} builder instance - */ - public TestServiceClient.Builder service(String service) { - return new TestServiceClient.Builder(this, service); - } - - /** - * Builds web client initialized with parameters stored in this builder. - * - * @return new {@link Http1Client} instance - */ - Http1Client buildWebClient() { - return Http1Client.builder() - .baseUri(HTTP_PREFIX + host + ':' + port) - .readTimeout(Duration.ofMinutes(10)) - .addMediaSupport(JsonpSupport.create()) - .build(); - } - - /** - * Builds test web client initialized with parameters stored in this builder. - * - * @return new {@link TestClient} instance - */ - public TestClient build() { - return new TestClient(buildWebClient()); - } - } -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SetUp.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestProcess.java similarity index 70% rename from tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SetUp.java rename to tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestProcess.java index 03afcf6f144..acdf0508c76 100644 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/SetUp.java +++ b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestProcess.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,16 +21,13 @@ import java.lang.annotation.Target; /** - * Hook for static methods invoked before all tests. + * The {@code @TestProcess} annotation is used to mark {@link ProcessRunner} instances that should be managed + * by {@link ProcessRunnerExtension}. + * + * @see ProcessRunnerExtension + * @see ProcessRunner */ -@Target(ElementType.METHOD) +@Target({ ElementType.FIELD, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) -public @interface SetUp { - - /** - * Priority, higher value has higher priority. - * - * @return priority - */ - int priority() default 100; +public @interface TestProcess { } diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/BeforeSuite.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestProcesses.java similarity index 62% rename from tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/BeforeSuite.java rename to tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestProcesses.java index 2cdb15573ec..cacc68dc712 100644 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/BeforeSuite.java +++ b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestProcesses.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,24 +15,27 @@ */ package io.helidon.tests.integration.harness; -import org.junit.platform.suite.api.Suite; - import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.junit.jupiter.api.extension.ExtendWith; + /** - * Hook for static methods invoked before a {@link Suite}. + * {@code TestProcesses} enables and provides configuration for {@link ProcessRunnerExtension}. */ -@Target(ElementType.METHOD) +@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -public @interface BeforeSuite { +@ExtendWith(ProcessRunnerExtension.class) +@Inherited +public @interface TestProcesses { /** - * Priority, higher value has higher priority. + * Whether processes start in parallel. Defaults to {@code false}. * - * @return priority + * @return if the processes should start in parallel */ - int priority() default 100; + boolean parallel() default false; } diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestServiceClient.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestServiceClient.java deleted file mode 100644 index c81d0d3358c..00000000000 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/TestServiceClient.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2021, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.harness; - -import java.util.Map; - -import io.helidon.webclient.http1.Http1Client; -import io.helidon.webclient.http1.Http1ClientRequest; - -import jakarta.json.JsonValue; - -/** - * Web client to access specific service of remote test application. - * Common service access method is still available. - */ -public class TestServiceClient extends TestClient { - - private final String service; - - private TestServiceClient(Http1Client client, String service) { - super(client); - this.service = service; - } - - /** - * Call remote test service method and return its data. - * Using service name provided to test web client builder. - * - * @param method remote test method name - * @param params remote test method query parameters - * @return data returned by remote test service method - */ - public JsonValue callServiceAndGetData(String method, Map params) { - return evaluateServiceCallResult(callService(clientGetBuilderWithPath(service, method), params)); - } - - /** - * Call remote test service method and return its data. - * Using service name provided to test web client builder. - * No query parameters are passed. - * - * @param method remote test method name - * @return data returned by remote test service method - */ - public JsonValue callServiceAndGetData(String method) { - return callServiceAndGetData(method, (Map) null); - } - - /** - * Call remote service method and return its raw data as JSON object. - * No response content check is done. No query parameters are passed. - * - * @param method remote test method name - * @return data returned by remote service - */ - public String callServiceAndGetString(String method) { - Http1ClientRequest clientRequest = clientGetBuilderWithPath(service, method); - return clientRequest.requestEntity(String.class); - } - - /** - * Remote test web client builder. - */ - public static class Builder { - - private final TestClient.Builder parentBuilder; - private final String service; - - Builder(TestClient.Builder parentBuilder, String service) { - this.parentBuilder = parentBuilder; - this.service = service; - } - - /** - * Set test application URL host. - * - * @param host test application URL host - * @return updated builder instance - */ - public Builder host(String host) { - parentBuilder.host(host); - return this; - } - - /** - * Set test application URL port. - * - * @param port test application URL port - * @return updated builder instance - */ - public Builder port(int port) { - parentBuilder.port(port); - return this; - } - - /** - * Builds test web client initialized with parameters stored in this builder. - * - * @return new {@link TestServiceClient} instance - */ - public TestServiceClient build() { - return new TestServiceClient(parentBuilder.buildWebClient(), service); - } - - } - -} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/WaitStrategy.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/WaitStrategy.java new file mode 100644 index 00000000000..3ec4d51bdb0 --- /dev/null +++ b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/WaitStrategy.java @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.tests.integration.harness; + +import java.io.IOException; +import java.lang.System.Logger.Level; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketAddress; +import java.time.Duration; +import java.util.Objects; + +/** + * Wait strategy. + */ +@SuppressWarnings("unused") +public sealed abstract class WaitStrategy { + + private static final System.Logger LOGGER = System.getLogger(WaitStrategy.class.getName()); + private static final String PORT_REGEX = ".* http://localhost:([0-9]*) ?.*"; + + private long timeout = 60; + + private WaitStrategy() { + } + + /** + * Wait for the configured port to be open. + * + * @return WaitStrategy + */ + public static WaitStrategy waitForPort() { + return new ConfiguredPortWaitStrategy(); + } + + /** + * Wait for the given port to be open. + * + * @return WaitStrategy + */ + public static WaitStrategy waitForPort(int port) { + return new PortWaitStrategy(port); + } + + /** + * Wait for the process to complete. + * + * @return WaitStrategy + */ + public static WaitStrategy waitForCompletion() { + return new CompletionWaitStrategy(); + } + + /** + * Wait for the given regex to match in the standard output. + * + * @param regex regex + * @return WaitStrategy + */ + public static WaitStrategy waitForLine(String regex) { + return new RegexWaitStrategy(regex); + } + + @SuppressWarnings("BusyWait") + void await(ProcessMonitor monitor, int port) { + Process process = monitor.get(); + long pid = process.pid(); + String description = toString(monitor, port); + LOGGER.log(Level.INFO, String.format("Waiting for %s, pid=%d", description, pid)); + long timeoutMillis = timeout * 1000; + long startTime = System.currentTimeMillis(); + while (process.isAlive() && System.currentTimeMillis() - startTime < timeoutMillis) { + if (test(monitor, port)) { + LOGGER.log(Level.INFO, "Process ready, pid=" + pid); + return; + } + try { + Thread.sleep(500L); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + if (test(monitor, port)) { + LOGGER.log(Level.INFO, "Process ready, pid=" + pid); + } else if (!process.isAlive()) { + throw new IllegalStateException("Process is not alive"); + } else { + throw new RuntimeException(String.format("Timeout waiting for %s, pid=%d", description, pid)); + } + } + + /** + * Test the strategy. + * + * @param monitor process monitor + * @param configuredPort configured port + * @return {@code true} if wait condition is sucessful + */ + abstract boolean test(ProcessMonitor monitor, int configuredPort); + + /** + * Get the strategy description. + * + * @param monitor process monitor + * @param configuredPort configured port + * @return description + */ + abstract String toString(ProcessMonitor monitor, int configuredPort); + + /** + * Set the timeout. + * + * @param timeout timeout + */ + public void timeout(Duration timeout) { + this.timeout = Objects.requireNonNull(timeout, "timeout is null").toSeconds(); + } + + /** + * Get the timeout in seconds. + * + * @return timeout + */ + public long timeout() { + return timeout; + } + + private static boolean isPortOpen(int port) { + SocketAddress sa = new InetSocketAddress("localhost", port); + try (Socket socket = new Socket()) { + socket.connect(sa, 1000); + LOGGER.log(Level.TRACE, "Socket localhost:%d is ready", port); + return true; + } catch (IOException ex) { + LOGGER.log(Level.TRACE, "Socket localhost:%d exception: %s", port, ex.getMessage()); + return false; + } + } + + private static boolean matchLines(String output, String regex) { + return output.lines().anyMatch(line -> line.matches(regex)); + } + + private static final class PortWaitStrategy extends WaitStrategy { + + private final int port; + + PortWaitStrategy(int port) { + this.port = port; + } + + @Override + public boolean test(ProcessMonitor monitor, int ignored) { + return isPortOpen(port); + } + + @Override + String toString(ProcessMonitor monitor, int ignored) { + return "port " + port; + } + } + + private static final class ConfiguredPortWaitStrategy extends WaitStrategy { + + @Override + public boolean test(ProcessMonitor monitor, int port) { + return port > 0 ? isPortOpen(port) : matchLines(monitor.output(), PORT_REGEX); + } + + @Override + String toString(ProcessMonitor monitor, int port) { + return port > 0 ? "port " + port : "regex " + PORT_REGEX; + } + } + + private static final class CompletionWaitStrategy extends WaitStrategy { + + @Override + public boolean test(ProcessMonitor monitor, int port) { + return !monitor.get().isAlive(); + } + + @Override + String toString(ProcessMonitor monitor, int port) { + return "completion"; + } + } + + private static final class RegexWaitStrategy extends WaitStrategy { + + private final String regex; + + private RegexWaitStrategy(String regex) { + this.regex = regex; + } + + @Override + public boolean test(ProcessMonitor monitor, int port) { + return matchLines(monitor.output(), regex); + } + + @Override + String toString(ProcessMonitor monitor, int port) { + return "regex " + regex; + } + } +}