From a3babea380818a3c7dbb10585285f6f76bb8d582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kraus?= Date: Fri, 22 Sep 2023 16:08:31 +0200 Subject: [PATCH] Integration tests with testcontainers - framework in tests/integration/junit5 - DbClient tests for H2/MySQL/PostgreSQL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Kraus --- bom/pom.xml | 5 + dbclient/pom.xml | 13 +- .../tests}/common/pom.xml | 67 +- .../dbclient/tests/common/model/Critter.java | 227 ++++++ .../dbclient/tests/common/model/Kind.java | 57 ++ .../tests}/common/model/RangePoJo.java | 6 +- .../common/tests/ExceptionalStmtIT.java | 20 +- .../tests}/common/tests/FlowControlIT.java | 18 +- .../tests}/common/tests/GetStatementIT.java | 28 +- .../tests}/common/tests/HealthCheckIT.java | 10 +- .../tests}/common/tests/InterceptorIT.java | 12 +- .../tests}/common/tests/MapperIT.java | 70 +- .../tests}/common/tests/QueryStatementIT.java | 28 +- .../common/tests/ServerHealthCheckIT.java | 107 +-- .../common/tests/ServerMetricsCheckIT.java | 116 ++++ .../tests}/common/tests/SimpleDeleteIT.java | 52 +- .../tests}/common/tests/SimpleDmlIT.java | 166 +++-- .../tests}/common/tests/SimpleGetIT.java | 40 +- .../tests}/common/tests/SimpleInsertIT.java | 46 +- .../tests}/common/tests/SimpleQueriesIT.java | 40 +- .../tests}/common/tests/SimpleUpdateIT.java | 94 ++- .../tests}/common/tests/StatementDmlIT.java | 64 +- .../common/tests/TransactionDeleteIT.java | 66 +- .../tests/TransactionExceptionalStmtIT.java | 18 +- .../tests}/common/tests/TransactionGetIT.java | 40 +- .../common/tests/TransactionInsertIT.java | 44 +- .../common/tests/TransactionQueriesIT.java | 40 +- .../common/tests/TransactionUpdateIT.java | 94 ++- .../tests/common/utils/InitUtils.java | 139 ++++ .../tests}/common/utils/MapperProvider.java | 12 +- .../tests}/common/utils/RangePoJo.java | 6 +- .../tests/common/utils/TestConfig.java | 86 +++ .../tests}/common/utils/VerifyData.java | 49 +- .../common/src/main/java/module-info.java | 31 +- dbclient/tests/h2/pom.xml | 115 +++ .../io/helidon/dbclient/tests/h2/H2Suite.java | 352 ++++++++++ ...tests.integration.junit5.spi.SuiteProvider | 4 +- .../tests/h2/src/test/resources/test.yaml | 9 +- dbclient/tests/mysql/pom.xml | 115 +++ .../dbclient/tests/mysql/MySqlSuite.java | 292 ++++++++ ...tests.integration.junit5.spi.SuiteProvider | 12 +- .../tests/mysql/src/test/resources/test.yaml | 14 +- dbclient/tests/pgsql/pom.xml | 115 +++ .../dbclient/tests/pgsql/PgSqlSuite.java | 292 ++++++++ ...tests.integration.junit5.spi.SuiteProvider | 17 + .../tests/pgsql/src/test/resources/test.yaml | 16 +- dbclient/tests/pom.xml | 50 ++ dependencies/pom.xml | 2 +- tests/integration/dbclient/app/pom.xml | 265 ------- .../dbclient/app/ErrorHandlerImpl.java | 42 -- .../integration/dbclient/app/InitService.java | 161 ----- .../tests/integration/dbclient/app/Main.java | 161 ----- .../dbclient/app/VerifyService.java | 94 --- .../app/dbmapper/DbClientMapperProvider.java | 44 -- .../app/dbmapper/DbRowToJsonObjectMapper.java | 150 ---- .../app/tests/AbstractDeleteService.java | 189 ----- .../app/tests/AbstractGetService.java | 130 ---- .../app/tests/AbstractInsertService.java | 250 ------- .../app/tests/AbstractQueryService.java | 136 ---- .../dbclient/app/tests/AbstractService.java | 88 --- .../app/tests/AbstractUpdateService.java | 206 ------ .../app/tests/FlowControlService.java | 102 --- .../app/tests/HealthCheckService.java | 147 ---- .../app/tests/InterceptorService.java | 92 --- .../dbclient/app/tests/MapperService.java | 223 ------ .../app/tests/SimpleDeleteService.java | 140 ---- .../dbclient/app/tests/SimpleGetService.java | 90 --- .../app/tests/SimpleInsertService.java | 150 ---- .../app/tests/SimpleQueryService.java | 97 --- .../app/tests/SimpleUpdateService.java | 150 ---- .../app/tests/StatementDmlService.java | 169 ----- .../app/tests/StatementGetService.java | 180 ----- .../app/tests/StatementQueryService.java | 182 ----- .../app/tests/TransactionDeleteService.java | 164 ----- .../app/tests/TransactionGetService.java | 104 --- .../app/tests/TransactionInsertService.java | 180 ----- .../app/tests/TransactionQueryService.java | 118 ---- .../app/tests/TransactionUpdateService.java | 180 ----- .../dbclient/app/tools/ExitService.java | 51 -- .../dbclient/app/tools/QueryParams.java | 94 --- .../app/src/main/resources/mysql.yaml | 59 -- .../integration/dbclient/app/DbInit.java | 115 --- .../integration/dbclient/app/LogData.java | 70 -- .../integration/dbclient/app/SuiteIT.java | 147 ---- .../integration/dbclient/app/VerifyData.java | 82 --- .../dbclient/app/tests/FlowControlIT.java | 72 -- .../dbclient/app/tests/HealthCheckIT.java | 154 ----- .../dbclient/app/tests/InterceptorIT.java | 47 -- .../dbclient/app/tests/MapperIT.java | 178 ----- .../app/tests/ServerMetricsCheckIT.java | 86 --- .../dbclient/app/tests/SimpleDeleteIT.java | 178 ----- .../dbclient/app/tests/SimpleGetIT.java | 116 ---- .../dbclient/app/tests/SimpleInsertIT.java | 173 ----- .../dbclient/app/tests/SimpleQueriesIT.java | 117 ---- .../dbclient/app/tests/SimpleUpdateIT.java | 186 ----- .../dbclient/app/tests/StatementDmlIT.java | 126 ---- .../dbclient/app/tests/StatementGetIT.java | 128 ---- .../dbclient/app/tests/StatementQueryIT.java | 129 ---- .../app/tests/TransactionDeleteIT.java | 178 ----- .../dbclient/app/tests/TransactionGetIT.java | 116 ---- .../app/tests/TransactionInsertIT.java | 174 ----- .../app/tests/TransactionQueriesIT.java | 120 ---- .../app/tests/TransactionUpdateIT.java | 185 ----- .../dbclient/common/model/Pokemon.java | 240 ------- .../dbclient/common/model/Type.java | 67 -- .../tests/DbClientParameterResolver.java | 73 -- .../common/tests/ServerMetricsCheckIT.java | 163 ----- .../dbclient/common/utils/TestConfig.java | 45 -- tests/integration/dbclient/h2/pom.xml | 171 ----- .../dbclient/jdbc/H2SetupProvider.java | 141 ---- tests/integration/dbclient/mongodb/pom.xml | 2 +- tests/integration/dbclient/mysql/pom.xml | 167 +++++ .../dbclient/mysql/MySqlSuite.java | 346 +++++++++ tests/integration/dbclient/pgsql/pom.xml | 163 +++++ .../dbclient/pgsql/PgSqlSuite.java | 343 +++++++++ tests/integration/dbclient/pom.xml | 12 +- tests/integration/junit5/README.md | 213 ++++++ tests/integration/junit5/design.md | 315 +++++++++ tests/integration/junit5/pom.xml | 198 ++++++ .../integration/junit5/AbstractContainer.java | 146 ++++ .../tests/integration/junit5/AfterSuite.java | 28 + .../integration/junit5/BeforeSuite.java} | 29 +- .../integration/junit5/ConfigUpdate.java} | 23 +- .../tests/integration/junit5/ConfigUtils.java | 77 +++ .../junit5/ContainerConfigBlueprint.java | 89 +++ .../junit5/ContainerConfigConstants.java | 26 + .../integration/junit5/ContainerInfo.java | 39 ++ .../integration/junit5/ContainerTest.java | 48 ++ .../integration/junit5/DatabaseContainer.java | 91 +++ .../DatabaseContainerConfigBlueprint.java | 47 ++ .../integration/junit5/DbClientTest.java | 42 ++ .../junit5/DefaultConfigProvider.java | 96 +++ .../junit5/DefaultDbClientProvider.java | 74 ++ .../integration/junit5/MySqlContainer.java | 126 ++++ .../integration/junit5/PgSqlContainer.java | 120 ++++ .../tests/integration/junit5/SetUpConfig.java | 28 + .../integration/junit5/SetUpContainer.java | 31 + .../integration/junit5/SetUpDbClient.java | 28 + .../tests/integration/junit5/Suite.java | 44 ++ .../integration/junit5/SuiteContext.java | 29 + .../junit5/SuiteExtensionProvider.java | 51 ++ .../junit5/SuiteJuit5Extension.java | 654 ++++++++++++++++++ .../junit5/SuiteJunit5Storage.java | 55 ++ .../integration/junit5/SuiteResolver.java | 43 ++ .../tests/integration/junit5/TestConfig.java | 53 ++ .../junit5/spi/ConfigProvider.java | 73 ++ .../junit5/spi/ContainerProvider.java | 83 +++ .../junit5/spi/DbClientProvider.java | 65 ++ .../integration/junit5/spi/SuiteProvider.java | 42 ++ .../junit5/src/main/java/module-info.java | 48 ++ .../tests/integration/junit5/ConfigSuite.java | 75 ++ .../tests/integration/junit5/MySqlSuite.java | 111 +++ .../tests/integration/junit5/PgSqlSuite.java | 111 +++ .../tests/integration/junit5/SimpleSuite.java | 79 +++ .../integration/junit5/TestConfigSuite.java | 69 ++ .../integration/junit5/TestMySqlSuite.java | 53 ++ .../integration/junit5/TestPgSqlSuite.java | 53 ++ .../integration/junit5/TestSimpleSuite.java | 43 ++ ...tests.integration.junit5.spi.SuiteProvider | 20 + .../test/resources/logging-test.properties} | 17 +- .../junit5/src/test/resources/mysql.yaml | 25 + .../junit5/src/test/resources/pgsql.yaml | 25 + .../src/test/resources/test.yaml} | 6 +- tests/integration/oidc/.helidon-oidc-secret | 1 + tests/integration/pom.xml | 2 +- 165 files changed, 7428 insertions(+), 9130 deletions(-) rename {tests/integration/dbclient => dbclient/tests}/common/pom.xml (70%) create mode 100644 dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/Critter.java create mode 100644 dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/Kind.java rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/model/RangePoJo.java (92%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/ExceptionalStmtIT.java (87%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/FlowControlIT.java (77%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/GetStatementIT.java (82%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/HealthCheckIT.java (95%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/InterceptorIT.java (83%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/MapperIT.java (65%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/QueryStatementIT.java (82%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/ServerHealthCheckIT.java (52%) create mode 100644 dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/ServerMetricsCheckIT.java rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/SimpleDeleteIT.java (68%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/SimpleDmlIT.java (60%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/SimpleGetIT.java (73%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/SimpleInsertIT.java (71%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/SimpleQueriesIT.java (74%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/SimpleUpdateIT.java (52%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/StatementDmlIT.java (63%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/TransactionDeleteIT.java (67%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/TransactionExceptionalStmtIT.java (88%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/TransactionGetIT.java (76%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/TransactionInsertIT.java (73%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/TransactionQueriesIT.java (77%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/tests/TransactionUpdateIT.java (54%) create mode 100644 dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/InitUtils.java rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/utils/MapperProvider.java (74%) rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/utils/RangePoJo.java (92%) create mode 100644 dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/TestConfig.java rename {tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient => dbclient/tests/common/src/main/java/io/helidon/dbclient/tests}/common/utils/VerifyData.java (79%) rename {tests/integration/dbclient => dbclient/tests}/common/src/main/java/module-info.java (59%) create mode 100644 dbclient/tests/h2/pom.xml create mode 100644 dbclient/tests/h2/src/test/java/io/helidon/dbclient/tests/h2/H2Suite.java rename tests/integration/dbclient/app/src/main/resources/META-INF/services/io.helidon.dbclient.spi.DbMapperProvider => dbclient/tests/h2/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider (80%) rename tests/integration/dbclient/h2/src/test/resources/h2.yaml => dbclient/tests/h2/src/test/resources/test.yaml (93%) create mode 100644 dbclient/tests/mysql/pom.xml create mode 100644 dbclient/tests/mysql/src/test/java/io/helidon/dbclient/tests/mysql/MySqlSuite.java rename tests/integration/dbclient/app/src/test/resources/logging.properties => dbclient/tests/mysql/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider (50%) rename tests/integration/dbclient/app/src/main/resources/h2.yaml => dbclient/tests/mysql/src/test/resources/test.yaml (87%) create mode 100644 dbclient/tests/pgsql/pom.xml create mode 100644 dbclient/tests/pgsql/src/test/java/io/helidon/dbclient/tests/pgsql/PgSqlSuite.java create mode 100644 dbclient/tests/pgsql/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider rename tests/integration/dbclient/app/src/main/resources/pgsql.yaml => dbclient/tests/pgsql/src/test/resources/test.yaml (86%) create mode 100644 dbclient/tests/pom.xml delete mode 100644 tests/integration/dbclient/app/pom.xml delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/ErrorHandlerImpl.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/InitService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/Main.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/VerifyService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/dbmapper/DbClientMapperProvider.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/dbmapper/DbRowToJsonObjectMapper.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractDeleteService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractGetService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractInsertService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractQueryService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/AbstractUpdateService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/FlowControlService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/HealthCheckService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/InterceptorService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/MapperService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleDeleteService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleGetService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleInsertService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleQueryService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/SimpleUpdateService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementDmlService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementGetService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/StatementQueryService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionDeleteService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionGetService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionInsertService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionQueryService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tests/TransactionUpdateService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tools/ExitService.java delete mode 100644 tests/integration/dbclient/app/src/main/java/io/helidon/tests/integration/dbclient/app/tools/QueryParams.java delete mode 100644 tests/integration/dbclient/app/src/main/resources/mysql.yaml delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/DbInit.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/LogData.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/SuiteIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/VerifyData.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/FlowControlIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/HealthCheckIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/InterceptorIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/MapperIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/ServerMetricsCheckIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleDeleteIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleGetIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleInsertIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleQueriesIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/SimpleUpdateIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementDmlIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementGetIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/StatementQueryIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionDeleteIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionGetIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionInsertIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionQueriesIT.java delete mode 100644 tests/integration/dbclient/app/src/test/java/io/helidon/tests/integration/dbclient/app/tests/TransactionUpdateIT.java delete mode 100644 tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Pokemon.java delete mode 100644 tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Type.java delete mode 100644 tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/DbClientParameterResolver.java delete mode 100644 tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ServerMetricsCheckIT.java delete mode 100644 tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/TestConfig.java delete mode 100644 tests/integration/dbclient/h2/pom.xml delete mode 100644 tests/integration/dbclient/h2/src/main/java/io/helidon/tests/integration/dbclient/jdbc/H2SetupProvider.java create mode 100644 tests/integration/dbclient/mysql/pom.xml create mode 100644 tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySqlSuite.java create mode 100644 tests/integration/dbclient/pgsql/pom.xml create mode 100644 tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PgSqlSuite.java create mode 100644 tests/integration/junit5/README.md create mode 100644 tests/integration/junit5/design.md create mode 100644 tests/integration/junit5/pom.xml create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/AbstractContainer.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/AfterSuite.java rename tests/integration/{dbclient/h2/src/main/java/module-info.java => junit5/src/main/java/io/helidon/tests/integration/junit5/BeforeSuite.java} (53%) rename tests/integration/{dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/spi/SetupProvider.java => junit5/src/main/java/io/helidon/tests/integration/junit5/ConfigUpdate.java} (57%) create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ConfigUtils.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerConfigBlueprint.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerConfigConstants.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerInfo.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerTest.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DatabaseContainer.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DatabaseContainerConfigBlueprint.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DbClientTest.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DefaultConfigProvider.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DefaultDbClientProvider.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/MySqlContainer.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/PgSqlContainer.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpConfig.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpContainer.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpDbClient.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/Suite.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteContext.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteExtensionProvider.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteJuit5Extension.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteJunit5Storage.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteResolver.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/TestConfig.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/ConfigProvider.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/ContainerProvider.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/DbClientProvider.java create mode 100644 tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/SuiteProvider.java create mode 100644 tests/integration/junit5/src/main/java/module-info.java create mode 100644 tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/ConfigSuite.java create mode 100644 tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/MySqlSuite.java create mode 100644 tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/PgSqlSuite.java create mode 100644 tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/SimpleSuite.java create mode 100644 tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestConfigSuite.java create mode 100644 tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestMySqlSuite.java create mode 100644 tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestPgSqlSuite.java create mode 100644 tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestSimpleSuite.java create mode 100644 tests/integration/junit5/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider rename tests/integration/{dbclient/app/src/main/resources/logging.properties => junit5/src/test/resources/logging-test.properties} (55%) create mode 100644 tests/integration/junit5/src/test/resources/mysql.yaml create mode 100644 tests/integration/junit5/src/test/resources/pgsql.yaml rename tests/integration/{dbclient/app/src/main/resources/common.yaml => junit5/src/test/resources/test.yaml} (86%) create mode 100644 tests/integration/oidc/.helidon-oidc-secret diff --git a/bom/pom.xml b/bom/pom.xml index 2715a75f343..9aecd89d1d6 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -762,6 +762,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/dbclient/pom.xml b/dbclient/pom.xml index ecfbfb10a6d..951ae314119 100644 --- a/dbclient/pom.xml +++ b/dbclient/pom.xml @@ -19,16 +19,17 @@ 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 helidon-project 4.0.0-SNAPSHOT - pom io.helidon.dbclient helidon-dbclient-project Helidon Database Client Project + pom dbclient @@ -41,4 +42,14 @@ health jsonp + + + + tests + + tests + + + + diff --git a/tests/integration/dbclient/common/pom.xml b/dbclient/tests/common/pom.xml similarity index 70% rename from tests/integration/dbclient/common/pom.xml rename to dbclient/tests/common/pom.xml index aec8eae0d9f..0c6d8860746 100644 --- a/tests/integration/dbclient/common/pom.xml +++ b/dbclient/tests/common/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 - io.helidon.tests.integration.dbclient - helidon-tests-integration-dbclient-project + io.helidon.dbclient + helidon-dbclient-tests-project 4.0.0-SNAPSHOT - ../pom.xml - helidon-tests-integration-dbclient-common - Helidon Tests Integration Database Client Common + + helidon-dbclient-tests-common + Helidon Database Client Common Tests + Database client tests for all vendors - io.helidon.tests.integration - helidon-tests-integration-harness - ${project.version} + io.helidon.dbclient + helidon-dbclient-metrics + + + io.helidon.dbclient + helidon-dbclient-health io.helidon.config @@ -44,20 +50,25 @@ helidon-config-yaml - io.helidon.metrics - helidon-metrics + io.helidon.webserver + helidon-webserver - io.helidon.dbclient - helidon-dbclient-health + io.helidon.webserver.observe + helidon-webserver-observe-metrics - io.helidon.dbclient - helidon-dbclient-metrics + io.helidon.webserver.observe + helidon-webserver-observe-health + + + io.helidon.tests.integration + helidon-tests-integration-harness + ${project.version} - org.eclipse.parsson - parsson + io.helidon.webserver.testing.junit5 + helidon-webserver-testing-junit5 org.junit.jupiter @@ -67,22 +78,6 @@ org.hamcrest hamcrest-all - - io.helidon.webserver - helidon-webserver - - - io.helidon.webserver.observe - helidon-webserver-observe-metrics - - - io.helidon.webserver.observe - helidon-webserver-observe-health - - - io.micrometer - micrometer-core - diff --git a/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/Critter.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/Critter.java new file mode 100644 index 00000000000..e94f52c98e9 --- /dev/null +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/Critter.java @@ -0,0 +1,227 @@ +/* + * 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.dbclient.tests.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 static io.helidon.dbclient.tests.common.model.Kind.KINDS; + +/** + * {@code Critter} POJO. + */ +@SuppressWarnings("SpellCheckingInspection") +public class Critter { + + /** + * {@code Critter} POJO mapper. + */ + public static final class CritterMapper implements DbMapper { + + public static final CritterMapper INSTANCE = new CritterMapper(); + + @Override + public Critter read(DbRow row) { + return new Critter(row.column("id").get(Integer.class), row.column("name").get(String.class)); + } + + @Override + public Map toNamedParameters(Critter value) { + Map params = new HashMap<>(2); + params.put("id", value.getId()); + params.put("name", value.getName()); + return params; + } + + @Override + public List toIndexedParameters(Critter value) { + List params = new ArrayList<>(2); + params.add(value.getName()); + params.add(value.getId()); + return params; + } + + } + + /** + * Map of {@code Critter} by ID. + */ + public static final Map CRITTERS = new HashMap<>(); + + static { + // query tests + CRITTERS.put(1, new Critter(1, "Pikachu", KINDS.get(13))); + CRITTERS.put(2, new Critter(2, "Raichu", KINDS.get(13))); + CRITTERS.put(3, new Critter(3, "Machop", KINDS.get(2))); + CRITTERS.put(4, new Critter(4, "Snorlax", KINDS.get(1))); + CRITTERS.put(5, new Critter(5, "Charizard", KINDS.get(10), KINDS.get(3))); + CRITTERS.put(6, new Critter(6, "Meowth", KINDS.get(1))); + CRITTERS.put(7, new Critter(7, "Gyarados", KINDS.get(3), KINDS.get(11))); + // update tests + CRITTERS.put(8, new Critter(8, "Spearow", KINDS.get(1), KINDS.get(3))); + CRITTERS.put(9, new Critter(9, "Fearow", KINDS.get(1), KINDS.get(3))); + CRITTERS.put(10, new Critter(10, "Ekans", KINDS.get(4))); + CRITTERS.put(11, new Critter(11, "Arbok", KINDS.get(4))); + CRITTERS.put(12, new Critter(12, "Sandshrew", KINDS.get(5))); + CRITTERS.put(13, new Critter(13, "Sandslash", KINDS.get(5))); + CRITTERS.put(14, new Critter(14, "Diglett", KINDS.get(5))); + // delete tests + CRITTERS.put(15, new Critter(15, "Rayquaza", KINDS.get(3), KINDS.get(16))); + CRITTERS.put(16, new Critter(16, "Lugia", KINDS.get(3), KINDS.get(14))); + CRITTERS.put(17, new Critter(17, "Ho-Oh", KINDS.get(3), KINDS.get(10))); + CRITTERS.put(18, new Critter(18, "Raikou", KINDS.get(13))); + CRITTERS.put(19, new Critter(19, "Giratina", KINDS.get(8), KINDS.get(16))); + CRITTERS.put(20, new Critter(20, "Regirock", KINDS.get(6))); + CRITTERS.put(21, new Critter(21, "Kyogre", KINDS.get(11))); + // IDs reserved for insert tests are 22 - 28 + // DML update tests + CRITTERS.put(29, new Critter(29, "Piplup", KINDS.get(11))); + CRITTERS.put(30, new Critter(30, "Prinplup", KINDS.get(11))); + CRITTERS.put(31, new Critter(31, "Empoleon", KINDS.get(9), KINDS.get(11))); + CRITTERS.put(32, new Critter(32, "Staryu", KINDS.get(11))); + CRITTERS.put(33, new Critter(33, "Starmie", KINDS.get(11), KINDS.get(14))); + CRITTERS.put(34, new Critter(34, "Horsea", KINDS.get(11))); + CRITTERS.put(35, new Critter(35, "Seadra", KINDS.get(11))); + // DML delete tests + CRITTERS.put(36, new Critter(36, "Mudkip", KINDS.get(11))); + CRITTERS.put(37, new Critter(37, "Marshtomp", KINDS.get(5), KINDS.get(11))); + CRITTERS.put(38, new Critter(38, "Swampert", KINDS.get(5), KINDS.get(11))); + CRITTERS.put(39, new Critter(39, "Muk", KINDS.get(4))); + CRITTERS.put(40, new Critter(40, "Grimer", KINDS.get(4))); + CRITTERS.put(41, new Critter(41, "Cubchoo", KINDS.get(15))); + CRITTERS.put(42, new Critter(42, "Beartic", KINDS.get(15))); + // IDs reserved for DML insert tests are 43 - 49 + // DML statement IT + CRITTERS.put(50, new Critter(50, "Shinx", KINDS.get(13))); + CRITTERS.put(51, new Critter(51, "Luxio", KINDS.get(13))); + CRITTERS.put(52, new Critter(52, "Luxray", KINDS.get(13))); + CRITTERS.put(53, new Critter(53, "Kricketot", KINDS.get(7))); + CRITTERS.put(54, new Critter(54, "Kricketune", KINDS.get(7))); + CRITTERS.put(55, new Critter(55, "Phione", KINDS.get(11))); + CRITTERS.put(56, new Critter(56, "Chatot", KINDS.get(1), KINDS.get(3))); + // update tests in transaction + CRITTERS.put(57, new Critter(57, "Teddiursa", KINDS.get(1))); + CRITTERS.put(58, new Critter(58, "Ursaring", KINDS.get(1))); + CRITTERS.put(59, new Critter(59, "Slugma", KINDS.get(10))); + CRITTERS.put(60, new Critter(60, "Magcargo", KINDS.get(6), KINDS.get(10))); + CRITTERS.put(61, new Critter(61, "Lotad", KINDS.get(11), KINDS.get(12))); + CRITTERS.put(62, new Critter(62, "Lombre", KINDS.get(11), KINDS.get(12))); + CRITTERS.put(63, new Critter(63, "Ludicolo", KINDS.get(11), KINDS.get(12))); + // DML update tests in transaction + CRITTERS.put(64, new Critter(64, "Natu", KINDS.get(3), KINDS.get(14))); + CRITTERS.put(65, new Critter(65, "Xatu", KINDS.get(3), KINDS.get(14))); + CRITTERS.put(66, new Critter(66, "Snubbull", KINDS.get(18))); + CRITTERS.put(67, new Critter(67, "Granbull", KINDS.get(18))); + CRITTERS.put(68, new Critter(68, "Entei", KINDS.get(10))); + CRITTERS.put(69, new Critter(69, "Raikou", KINDS.get(13))); + CRITTERS.put(70, new Critter(70, "Suicune", KINDS.get(11))); + // delete tests in transaction + CRITTERS.put(71, new Critter(71, "Omanyte", KINDS.get(6), KINDS.get(11))); + CRITTERS.put(72, new Critter(72, "Omastar", KINDS.get(6), KINDS.get(11))); + CRITTERS.put(73, new Critter(73, "Kabuto", KINDS.get(6), KINDS.get(11))); + CRITTERS.put(74, new Critter(74, "Kabutops", KINDS.get(6), KINDS.get(11))); + CRITTERS.put(75, new Critter(75, "Chikorita", KINDS.get(12))); + CRITTERS.put(76, new Critter(76, "Bayleef", KINDS.get(12))); + CRITTERS.put(77, new Critter(77, "Meganium", KINDS.get(12))); + // DML delete tests in transaction + CRITTERS.put(78, new Critter(78, "Trapinch", KINDS.get(5))); + CRITTERS.put(79, new Critter(79, "Vibrava", KINDS.get(5), KINDS.get(16))); + CRITTERS.put(80, new Critter(80, "Spoink", KINDS.get(14))); + CRITTERS.put(81, new Critter(81, "Grumpig", KINDS.get(14))); + CRITTERS.put(82, new Critter(82, "Beldum", KINDS.get(9), KINDS.get(14))); + CRITTERS.put(83, new Critter(83, "Metang", KINDS.get(9), KINDS.get(14))); + CRITTERS.put(84, new Critter(84, "Metagross", KINDS.get(9), KINDS.get(14))); + // IDs reserved for DML insert tests in transaction are 85 - 98 + // mapping tests + CRITTERS.put(99, new Critter(99, "Moltres", KINDS.get(3), KINDS.get(10))); + CRITTERS.put(100, new Critter(100, "Masquerain", KINDS.get(3), KINDS.get(7))); + CRITTERS.put(101, new Critter(101, "Makuhita", KINDS.get(2))); + CRITTERS.put(102, new Critter(102, "Hariyama", KINDS.get(2))); + // IDs reserved for mapping tests with insert are 103 - 104 + } + + public static List typesList(Kind... 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 Critter(int id, String name, Kind... 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 Critter(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 Kind[] getTypesArray() { + return types.toArray(new Kind[0]); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Critter: {id="); + sb.append(id); + sb.append(", name="); + sb.append(name); + sb.append(", types=["); + boolean first = true; + for (Kind type : types) { + if (first) { + first = false; + } else { + sb.append(", "); + } + sb.append(type.toString()); + } + sb.append("]}"); + return sb.toString(); + } + +} diff --git a/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/Kind.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/Kind.java new file mode 100644 index 00000000000..4ebb5835737 --- /dev/null +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/Kind.java @@ -0,0 +1,57 @@ +/* + * 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.dbclient.tests.common.model; + +import java.util.HashMap; +import java.util.Map; + +/** + * {@code Critter} type POJO. + */ +public record Kind(int id, String name) { + + /** + * Map of {@code Critter} types by ID. + */ + public static final Map KINDS = new HashMap<>(); + + static { + KINDS.put(1, new Kind(1, "Normal")); + KINDS.put(2, new Kind(2, "Fighting")); + KINDS.put(3, new Kind(3, "Flying")); + KINDS.put(4, new Kind(4, "Poison")); + KINDS.put(5, new Kind(5, "Ground")); + KINDS.put(6, new Kind(6, "Rock")); + KINDS.put(7, new Kind(7, "Bug")); + KINDS.put(8, new Kind(8, "Ghost")); + KINDS.put(9, new Kind(9, "Steel")); + KINDS.put(10, new Kind(10, "Fire")); + KINDS.put(11, new Kind(11, "Water")); + KINDS.put(12, new Kind(12, "Grass")); + KINDS.put(13, new Kind(13, "Electric")); + KINDS.put(14, new Kind(14, "Psychic")); + KINDS.put(15, new Kind(15, "Ice")); + KINDS.put(16, new Kind(16, "Dragon")); + KINDS.put(17, new Kind(17, "Dark")); + KINDS.put(18, new Kind(18, "Fairy")); + } + + @Override + public String toString() { + return "Type: {id=" + id + ", name=" + name + "}"; + } + +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/RangePoJo.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/RangePoJo.java similarity index 92% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/RangePoJo.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/RangePoJo.java index 74d98b15dad..0d45a398e46 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/RangePoJo.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/model/RangePoJo.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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.model; +package io.helidon.dbclient.tests.common.model; import java.util.ArrayList; import java.util.HashMap; @@ -24,7 +24,7 @@ import io.helidon.dbclient.DbRow; /** - * POJO used to define {@code Pokemon} IDs range in query statement tests. + * POJO used to define {@code Critter} IDs range in query statement tests. * * @param idMin Beginning of IDs range. * @param idMax End of IDs range. diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ExceptionalStmtIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/ExceptionalStmtIT.java similarity index 87% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ExceptionalStmtIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/ExceptionalStmtIT.java index dfc5ac3ddd6..f358e050871 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ExceptionalStmtIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/ExceptionalStmtIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; @@ -21,22 +21,20 @@ 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 io.helidon.dbclient.tests.common.model.Critter.CRITTERS; import static org.junit.jupiter.api.Assertions.fail; /** * Test exceptional states. */ -@ExtendWith(DbClientParameterResolver.class) -class ExceptionalStmtIT { +public abstract class ExceptionalStmtIT { private static final System.Logger LOGGER = System.getLogger(ExceptionalStmtIT.class.getName()); private final DbClient dbClient; - ExceptionalStmtIT(DbClient dbClient) { + public ExceptionalStmtIT(DbClient dbClient) { this.dbClient = dbClient; } @@ -80,8 +78,8 @@ void testCreateNamedQueryNamedAndOrderArgsWithArgs() { try { dbClient.execute() .createNamedQuery("select-pokemons-error-arg") - .addParam("id", POKEMONS.get(5).getId()) - .addParam(POKEMONS.get(5).getName()) + .addParam("id", CRITTERS.get(5).getId()) + .addParam(CRITTERS.get(5).getName()) .execute() .forEach(it -> {}); fail("Execution of query with both named and ordered parameters without passing them shall fail."); @@ -98,7 +96,7 @@ void testCreateNamedQueryNamedArgsSetOrderArg() { try { dbClient.execute() .createNamedQuery("select-pokemon-named-arg") - .addParam(POKEMONS.get(5).getName()) + .addParam(CRITTERS.get(5).getName()) .execute() .forEach(it -> {}); fail("Execution of query with named parameter with passing ordered parameter value shall fail."); @@ -115,7 +113,7 @@ void testCreateNamedQueryOrderArgsSetNamedArg() { try { dbClient.execute() .createNamedQuery("select-pokemon-order-arg") - .addParam("name", POKEMONS.get(6).getName()) + .addParam("name", CRITTERS.get(6).getName()) .execute() .forEach(it -> {}); fail("Execution of query with ordered parameter with passing named parameter value shall fail."); diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/FlowControlIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/FlowControlIT.java similarity index 77% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/FlowControlIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/FlowControlIT.java index 06e18eb0f4e..16640f5487d 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/FlowControlIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/FlowControlIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; import java.util.List; @@ -21,12 +21,11 @@ import io.helidon.dbclient.DbClient; import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.model.Type; +import io.helidon.dbclient.tests.common.model.Kind; 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.dbclient.tests.common.model.Kind.KINDS; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; @@ -36,14 +35,13 @@ /** * Verify proper flow control handling in query processing. */ -@ExtendWith(DbClientParameterResolver.class) -public class FlowControlIT { +public abstract class FlowControlIT { private static final System.Logger LOGGER = System.getLogger(FlowControlIT.class.getName()); private final DbClient dbClient; - FlowControlIT(DbClient dbClient) { + public FlowControlIT(DbClient dbClient) { this.dbClient = dbClient; } @@ -61,8 +59,8 @@ public void testSourceData() { 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)); + Kind type = new Kind(id, name); + assertThat(name, KINDS.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/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/GetStatementIT.java similarity index 82% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/GetStatementIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/GetStatementIT.java index 0d4a7bc24a2..ec6b29fa3ca 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/GetStatementIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/GetStatementIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.util.ArrayList; import java.util.HashMap; @@ -23,22 +23,20 @@ import io.helidon.dbclient.DbClient; import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.utils.RangePoJo; +import io.helidon.dbclient.tests.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 io.helidon.dbclient.tests.common.utils.VerifyData.verifyCrittersIdRange; /** * Test DbStatementGet methods. */ -@ExtendWith(DbClientParameterResolver.class) -public class GetStatementIT { +public abstract class GetStatementIT { private final DbClient dbClient; - GetStatementIT(DbClient dbClient) { + public GetStatementIT(DbClient dbClient) { this.dbClient = dbClient; } @@ -51,7 +49,7 @@ public void testGetArrayParams() { .createNamedGet("select-pokemons-idrng-order-arg") .params(1, 3) .execute(); - verifyPokemonsIdRange(maybeRow, 1, 3); + verifyCrittersIdRange(maybeRow, 1, 3); } /** @@ -67,7 +65,7 @@ public void testGetListParams() { .params(params) .execute(); - verifyPokemonsIdRange(maybeRow, 2, 4); + verifyCrittersIdRange(maybeRow, 2, 4); } /** @@ -83,7 +81,7 @@ public void testGetMapParams() { .params(params) .execute(); - verifyPokemonsIdRange(maybeRow, 3, 5); + verifyCrittersIdRange(maybeRow, 3, 5); } /** @@ -96,7 +94,7 @@ public void testGetOrderParam() { .addParam(4) .addParam(6) .execute(); - verifyPokemonsIdRange(maybeRow, 4, 6); + verifyCrittersIdRange(maybeRow, 4, 6); } /** @@ -109,7 +107,7 @@ public void testGetNamedParam() { .addParam("idmin", 5) .addParam("idmax", 7) .execute(); - verifyPokemonsIdRange(maybeRow, 5, 7); + verifyCrittersIdRange(maybeRow, 5, 7); } /** @@ -122,7 +120,7 @@ public void testGetMappedNamedParam() { .createNamedGet("select-pokemons-idrng-named-arg") .namedParam(range) .execute(); - verifyPokemonsIdRange(maybeRow, 0, 2); + verifyCrittersIdRange(maybeRow, 0, 2); } /** @@ -135,7 +133,7 @@ public void testGetMappedOrderParam() { .createNamedGet("select-pokemons-idrng-order-arg") .indexedParam(range) .execute(); - verifyPokemonsIdRange(maybeRow, 6, 8); + verifyCrittersIdRange(maybeRow, 6, 8); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/HealthCheckIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/HealthCheckIT.java similarity index 95% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/HealthCheckIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/HealthCheckIT.java index a3fc9eea2ca..b7bb0b27657 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/HealthCheckIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/HealthCheckIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; @@ -24,7 +24,6 @@ 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; @@ -34,8 +33,7 @@ /** * Verify that health check works. */ -@ExtendWith(DbClientParameterResolver.class) -public class HealthCheckIT { +public abstract class HealthCheckIT { private static final System.Logger LOGGER = System.getLogger(HealthCheckIT.class.getName()); @@ -43,7 +41,7 @@ public class HealthCheckIT { private final Config config; private final boolean pingDml; - HealthCheckIT(DbClient dbClient, Config config) { + public HealthCheckIT(DbClient dbClient, Config config) { this.dbClient = dbClient; this.config = config; Config cfgPingDml = config.get("test.ping-dml"); diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/InterceptorIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/InterceptorIT.java similarity index 83% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/InterceptorIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/InterceptorIT.java index 00fa855a673..feb100ac8e3 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/InterceptorIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/InterceptorIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import io.helidon.config.Config; import io.helidon.dbclient.DbClient; @@ -21,17 +21,15 @@ 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 io.helidon.dbclient.tests.common.model.Critter.CRITTERS; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; /** * Verify services handling. */ -@ExtendWith(DbClientParameterResolver.class) -public class InterceptorIT { +public abstract class InterceptorIT { private final Config config; @@ -68,7 +66,7 @@ public void testStatementInterceptor() { DbClient dbClient = DbClient.builder(config.get("db")).addService(interceptor).build(); dbClient.execute() .createNamedQuery("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(6).getName()) + .addParam("name", CRITTERS.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/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/MapperIT.java similarity index 65% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/MapperIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/MapperIT.java index e3c73e6ed39..8a172abb340 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/MapperIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/MapperIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; import java.util.Optional; @@ -23,18 +23,17 @@ 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 io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.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 io.helidon.dbclient.tests.common.model.Critter.CRITTERS; +import static io.helidon.dbclient.tests.common.model.Kind.KINDS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyInsertCritter; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyCritter; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyUpdateCritter; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -42,23 +41,22 @@ * Verify mapping interface. */ @SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class MapperIT { +public abstract 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) { + public MapperIT(DbClient dbClient) { this.dbClient = dbClient; } - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { - POKEMONS.put(pokemon.getId(), pokemon); + private static void addCritter(DbClient dbClient, Critter pokemon) { + CRITTERS.put(pokemon.getId(), pokemon); long result = dbClient.execute() .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } @BeforeAll @@ -66,10 +64,10 @@ public static void setup(DbClient dbClient) throws ExecutionException, Interrupt 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 + addCritter(dbClient, new Critter(++curId, "Moltres", KINDS.get(3), KINDS.get(10))); // BASE_ID+3 + addCritter(dbClient, new Critter(++curId, "Masquerain", KINDS.get(3), KINDS.get(7))); // BASE_ID+4 + addCritter(dbClient, new Critter(++curId, "Makuhita", KINDS.get(2))); // BASE_ID+5 + addCritter(dbClient, new Critter(++curId, "Hariyama", KINDS.get(2))); // BASE_ID+6 } catch (Exception ex) { LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex.getMessage()), ex); throw ex; @@ -81,12 +79,12 @@ public static void setup(DbClient dbClient) throws ExecutionException, Interrupt */ @Test public void testInsertWithOrderMapping() { - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Articuno", TYPES.get(3), TYPES.get(15)); + Critter pokemon = new Critter(BASE_ID + 1, "Articuno", KINDS.get(3), KINDS.get(15)); long result = dbClient.execute() .createNamedInsert("insert-pokemon-order-arg-rev") .indexedParam(pokemon) .execute(); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -94,12 +92,12 @@ public void testInsertWithOrderMapping() { */ @Test public void testInsertWithNamedMapping() { - Pokemon pokemon = new Pokemon(BASE_ID + 2, "Zapdos", TYPES.get(3), TYPES.get(13)); + Critter pokemon = new Critter(BASE_ID + 2, "Zapdos", KINDS.get(3), KINDS.get(13)); long result = dbClient.execute() .createNamedInsert("insert-pokemon-named-arg") .namedParam(pokemon) .execute(); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -107,12 +105,12 @@ public void testInsertWithNamedMapping() { */ @Test public void testUpdateWithOrderMapping() { - Pokemon pokemon = new Pokemon(BASE_ID + 3, "Masquerain", TYPES.get(3), TYPES.get(15)); + Critter pokemon = new Critter(BASE_ID + 3, "Masquerain", KINDS.get(3), KINDS.get(15)); long result = dbClient.execute() .createNamedUpdate("update-pokemon-order-arg") .indexedParam(pokemon) .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); + verifyUpdateCritter(dbClient, result, pokemon); } /** @@ -120,12 +118,12 @@ public void testUpdateWithOrderMapping() { */ @Test public void testUpdateWithNamedMapping() { - Pokemon pokemon = new Pokemon(BASE_ID + 4, "Moltres", TYPES.get(3), TYPES.get(13)); + Critter pokemon = new Critter(BASE_ID + 4, "Moltres", KINDS.get(3), KINDS.get(13)); long result = dbClient.execute() .createNamedUpdate("update-pokemon-named-arg") .namedParam(pokemon) .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); + verifyUpdateCritter(dbClient, result, pokemon); } /** @@ -134,7 +132,7 @@ public void testUpdateWithNamedMapping() { @Test public void testDeleteWithOrderMapping() { DbExecute exec = dbClient.execute(); - Pokemon pokemon = POKEMONS.get(BASE_ID + 5); + Critter pokemon = CRITTERS.get(BASE_ID + 5); long result = exec.createNamedDelete("delete-pokemon-full-order-arg") .indexedParam(pokemon) @@ -152,7 +150,7 @@ public void testDeleteWithOrderMapping() { @Test public void testDeleteWithNamedMapping() { DbExecute exec = dbClient.execute(); - Pokemon pokemon = POKEMONS.get(BASE_ID + 6); + Critter pokemon = CRITTERS.get(BASE_ID + 6); long result = exec.createNamedDelete("delete-pokemon-full-named-arg") .namedParam(pokemon) @@ -171,11 +169,11 @@ public void testDeleteWithNamedMapping() { public void testQueryWithMapping() { Stream rows = dbClient.execute() .createNamedQuery("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(2).getName()) + .addParam("name", CRITTERS.get(2).getName()) .execute(); - Pokemon pokemon = rows.map(it -> it.as(Pokemon.class)).toList().get(0); - verifyPokemon(pokemon, POKEMONS.get(2)); + Critter pokemon = rows.map(it -> it.as(Critter.class)).toList().get(0); + verifyCritter(pokemon, CRITTERS.get(2)); } /** @@ -185,11 +183,11 @@ public void testQueryWithMapping() { public void testGetWithMapping() { Optional maybeRow = dbClient.execute() .createNamedGet("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(3).getName()) + .addParam("name", CRITTERS.get(3).getName()) .execute(); assertThat(maybeRow.isPresent(), equalTo(true)); - Pokemon pokemon = maybeRow.get().as(Pokemon.class); - verifyPokemon(pokemon, POKEMONS.get(3)); + Critter pokemon = maybeRow.get().as(Critter.class); + verifyCritter(pokemon, CRITTERS.get(3)); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/QueryStatementIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/QueryStatementIT.java similarity index 82% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/QueryStatementIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/QueryStatementIT.java index 154bcccaaad..61b6f24b24e 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/QueryStatementIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/QueryStatementIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.util.ArrayList; import java.util.HashMap; @@ -23,22 +23,20 @@ import io.helidon.dbclient.DbClient; import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.utils.RangePoJo; +import io.helidon.dbclient.tests.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 io.helidon.dbclient.tests.common.utils.VerifyData.verifyCrittersIdRange; /** * Test DbStatementQuery methods. */ -@ExtendWith(DbClientParameterResolver.class) -public class QueryStatementIT { +public abstract class QueryStatementIT { private final DbClient dbClient; - QueryStatementIT(DbClient dbClient) { + public QueryStatementIT(DbClient dbClient) { this.dbClient = dbClient; } @@ -52,7 +50,7 @@ public void testQueryArrayParams() { .params(1, 7) .execute(); - verifyPokemonsIdRange(rows, 1, 7); + verifyCrittersIdRange(rows, 1, 7); } /** @@ -68,7 +66,7 @@ public void testQueryListParams() { .params(params) .execute(); - verifyPokemonsIdRange(rows, 1, 7); + verifyCrittersIdRange(rows, 1, 7); } /** @@ -84,7 +82,7 @@ public void testQueryMapParams() { .params(params) .execute(); - verifyPokemonsIdRange(rows, 1, 7); + verifyCrittersIdRange(rows, 1, 7); } /** @@ -98,7 +96,7 @@ public void testQueryOrderParam() { .addParam(7) .execute(); - verifyPokemonsIdRange(rows, 1, 7); + verifyCrittersIdRange(rows, 1, 7); } /** @@ -112,7 +110,7 @@ public void testQueryNamedParam() { .addParam("idmax", 7) .execute(); - verifyPokemonsIdRange(rows, 1, 7); + verifyCrittersIdRange(rows, 1, 7); } /** @@ -126,7 +124,7 @@ public void testQueryMappedNamedParam() { .namedParam(range) .execute(); - verifyPokemonsIdRange(rows, 1, 7); + verifyCrittersIdRange(rows, 1, 7); } /** @@ -140,7 +138,7 @@ public void testQueryMappedOrderParam() { .indexedParam(range) .execute(); - verifyPokemonsIdRange(rows, 1, 7); + verifyCrittersIdRange(rows, 1, 7); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ServerHealthCheckIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/ServerHealthCheckIT.java similarity index 52% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ServerHealthCheckIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/ServerHealthCheckIT.java index 5a4d10cd63e..4b3efed383c 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/ServerHealthCheckIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/ServerHealthCheckIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,71 +13,57 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.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.webclient.api.ClientResponseTyped; +import io.helidon.webclient.api.WebClient; 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 jakarta.json.JsonObject; 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; +import static org.hamcrest.Matchers.is; /** * Verify health check in web server environment. */ -@ExtendWith(DbClientParameterResolver.class) -public class ServerHealthCheckIT { +public abstract 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; + private final WebServer server; + private final WebClient webClient; - public ServerHealthCheckIT(DbClient dbClient) { + public ServerHealthCheckIT(Config config, 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")) + this.server = WebServer.builder() + .update(builder -> routing(config, dbClient, builder)) .build() .start(); - URL = "http://localhost:" + SERVER.port(); - LOGGER.log(Level.TRACE, () -> "WEB server is running at " + URL); + this.webClient = WebClient.builder() + .baseUri("http://localhost:" + server.port()) + .build(); } // 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) { + private static void routing(Config config, DbClient dbClient, WebServerConfig.Builder router) { router.addFeature( createObserveFeature(dbClient, config, "healthNoDetails", "noDetails", false)); router.addFeature( @@ -99,32 +85,6 @@ private static ObserveFeature createObserveFeature(DbClient dbClient, Config con .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. * @@ -135,11 +95,10 @@ private static HttpResponse get(String url) throws IOException, Interrup 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())); + ClientResponseTyped response = webClient.get("/noDetails/health") + .request(String.class); + assertThat(response.status(), is(Status.NO_CONTENT_204)); } /** @@ -152,24 +111,18 @@ void testHttpHealthNoDetails() throws IOException, InterruptedException { 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")); - }); + ClientResponseTyped response = webClient.get("/details/health") + .request(JsonObject.class); + assertThat(response.status(), is(Status.OK_200)); + + JsonObject jsonResponse = response.entity(); + JsonArray checks = jsonResponse.getJsonArray("checks"); + assertThat(checks.size(), greaterThan(0)); + checks.forEach((check) -> { + String status = check.asJsonObject().getString("status"); + assertThat(status, equalTo("UP")); + }); } } diff --git a/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/ServerMetricsCheckIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/ServerMetricsCheckIT.java new file mode 100644 index 00000000000..1253e983f64 --- /dev/null +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/ServerMetricsCheckIT.java @@ -0,0 +1,116 @@ +/* + * 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.dbclient.tests.common.tests; + +import java.io.IOException; +import java.lang.System.Logger.Level; + +import io.helidon.common.media.type.MediaType; +import io.helidon.common.media.type.MediaTypes; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.common.utils.TestConfig; +import io.helidon.http.HeaderName; +import io.helidon.http.HeaderNames; +import io.helidon.http.Status; +import io.helidon.webclient.api.ClientResponseTyped; +import io.helidon.webclient.api.WebClient; +import io.helidon.webserver.WebServer; +import io.helidon.webserver.testing.junit5.ServerTest; + +import jakarta.json.JsonObject; +import jakarta.json.JsonValue; +import org.junit.jupiter.api.Test; + +import static io.helidon.dbclient.tests.common.model.Kind.KINDS; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +/** + * Verify metrics check in web server environment. + */ +@ServerTest +public abstract 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 final DbClient dbClient; + private final WebServer server; + private final WebClient webClient; + + public ServerMetricsCheckIT(DbClient dbClient) { + this.dbClient = dbClient; + this.server = WebServer.builder() + .build() + .start(); + this.webClient = WebClient.builder() + .baseUri("http://localhost:" + server.port()) + .build(); + } + + /** + * 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 + void testHttpMetrics() throws IOException, InterruptedException { + // Call select-pokemons to trigger it + + dbClient.execute() + .namedQuery("select-pokemons") + .forEach(p -> { + }); + + // Call insert-pokemon to trigger it + Critter pokemon = new Critter(BASE_ID + 1, "Lickitung", KINDS.get(1)); + long count = dbClient.execute() + .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); + assertThat(count, equalTo(1L)); + + // Read and process metrics response + ClientResponseTyped response = webClient.get("/observe/metrics/application") + .header(HeaderNames.ACCEPT, "application/json") + .request(JsonObject.class); + assertThat(response.status(), is(Status.OK_200)); + + JsonObject application = response.entity(); + 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 selectCritters = application.getInt("db.counter.select-pokemons"); + int insertCritters = application.getInt("db.counter.insert-pokemon"); + assertThat(selectCritters, greaterThan(0)); + assertThat(insertCritters, greaterThan(0)); + 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, greaterThan(0)); + } + +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDeleteIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleDeleteIT.java similarity index 68% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDeleteIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleDeleteIT.java index f2b657c0ce5..01817b4b303 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDeleteIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleDeleteIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; import java.util.HashMap; @@ -21,27 +21,25 @@ 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 io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.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.dbclient.tests.common.model.Kind.KINDS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyDeleteCritter; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyInsertCritter; /** * Test set of basic JDBC delete calls. */ @SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class SimpleDeleteIT { +public abstract 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 static final Map POKEMONS = new HashMap<>(); private final DbClient dbClient; private final Config config; @@ -51,24 +49,24 @@ public SimpleDeleteIT(DbClient dbClient, Config config) { this.config = config; } - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { + private static void addCritter(DbClient dbClient, Critter pokemon) { POKEMONS.put(pokemon.getId(), pokemon); long result = dbClient.execute() .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(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 + addCritter(dbClient, new Critter(++curId, "Rayquaza", KINDS.get(3), KINDS.get(16))); // BASE_ID+1 + addCritter(dbClient, new Critter(++curId, "Lugia", KINDS.get(3), KINDS.get(14))); // BASE_ID+2 + addCritter(dbClient, new Critter(++curId, "Ho-Oh", KINDS.get(3), KINDS.get(10))); // BASE_ID+3 + addCritter(dbClient, new Critter(++curId, "Raikou", KINDS.get(13))); // BASE_ID+4 + addCritter(dbClient, new Critter(++curId, "Giratina", KINDS.get(8), KINDS.get(16))); // BASE_ID+5 + addCritter(dbClient, new Critter(++curId, "Regirock", KINDS.get(6))); // BASE_ID+6 + addCritter(dbClient, new Critter(++curId, "Kyogre", KINDS.get(11))); // BASE_ID+7 } catch (Exception ex) { LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex)); throw ex; @@ -85,7 +83,7 @@ public void testCreateNamedDeleteStrStrOrderArgs() { long result = dbClient.execute() .createNamedDelete("delete-rayquaza", stmt) .addParam(POKEMONS.get(BASE_ID + 1).getId()).execute(); - verifyDeletePokemon(dbClient, result, POKEMONS.get(BASE_ID + 1)); + verifyDeleteCritter(dbClient, result, POKEMONS.get(BASE_ID + 1)); } /** @@ -96,7 +94,7 @@ 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)); + verifyDeleteCritter(dbClient, result, POKEMONS.get(BASE_ID + 2)); } /** @@ -107,7 +105,7 @@ 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)); + verifyDeleteCritter(dbClient, result, POKEMONS.get(BASE_ID + 3)); } /** @@ -119,7 +117,7 @@ public void testCreateDeleteNamedArgs() { long result = dbClient.execute() .createDelete(stmt) .addParam("id", POKEMONS.get(BASE_ID + 4).getId()).execute(); - verifyDeletePokemon(dbClient, result, POKEMONS.get(BASE_ID + 4)); + verifyDeleteCritter(dbClient, result, POKEMONS.get(BASE_ID + 4)); } /** @@ -131,7 +129,7 @@ public void testCreateDeleteOrderArgs() { long result = dbClient.execute() .createDelete(stmt) .addParam(POKEMONS.get(BASE_ID + 5).getId()).execute(); - verifyDeletePokemon(dbClient, result, POKEMONS.get(BASE_ID + 5)); + verifyDeleteCritter(dbClient, result, POKEMONS.get(BASE_ID + 5)); } /** @@ -141,7 +139,7 @@ public void testCreateDeleteOrderArgs() { 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)); + verifyDeleteCritter(dbClient, result, POKEMONS.get(BASE_ID + 6)); } /** @@ -152,7 +150,7 @@ 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)); + verifyDeleteCritter(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/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleDmlIT.java similarity index 60% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDmlIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleDmlIT.java index 95b7fb1d505..5693dea2920 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleDmlIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleDmlIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; import java.util.HashMap; @@ -21,28 +21,26 @@ 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 io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.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; +import static io.helidon.dbclient.tests.common.model.Kind.KINDS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyDeleteCritter; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyInsertCritter; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyUpdateCritter; /** * Test set of basic JDBC DML statement calls. */ @SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class SimpleDmlIT { +public abstract 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 static final Map POKEMONS = new HashMap<>(); private final DbClient dbClient; private final Config config; @@ -51,11 +49,11 @@ public SimpleDmlIT(DbClient dbClient, Config config) { this.config = config; } - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { + private static void addCritter(DbClient dbClient, Critter pokemon) { POKEMONS.put(pokemon.getId(), pokemon); long result = dbClient.execute() .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } @BeforeAll @@ -63,21 +61,21 @@ 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 + addCritter(dbClient, new Critter(BASE_ID + 10, "Piplup", KINDS.get(11))); // BASE_ID+10 + addCritter(dbClient, new Critter(BASE_ID + 11, "Prinplup", KINDS.get(11))); // BASE_ID+11 + addCritter(dbClient, new Critter(BASE_ID + 12, "Empoleon", KINDS.get(9), KINDS.get(11))); // BASE_ID+12 + addCritter(dbClient, new Critter(BASE_ID + 13, "Staryu", KINDS.get(11))); // BASE_ID+13 + addCritter(dbClient,new Critter(BASE_ID + 14, "Starmie", KINDS.get(11), KINDS.get(14))); // BASE_ID+14 + addCritter(dbClient,new Critter(BASE_ID + 15, "Horsea", KINDS.get(11))); // BASE_ID+15 + addCritter(dbClient,new Critter(BASE_ID + 16, "Seadra", KINDS.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 + addCritter(dbClient,new Critter(BASE_ID + 20, "Mudkip", KINDS.get(11))); // BASE_ID+20 + addCritter(dbClient,new Critter(BASE_ID + 21, "Marshtomp", KINDS.get(5), KINDS.get(11))); // BASE_ID+21 + addCritter(dbClient,new Critter(BASE_ID + 22, "Swampert", KINDS.get(5), KINDS.get(11))); // BASE_ID+22 + addCritter(dbClient,new Critter(BASE_ID + 23, "Muk", KINDS.get(4))); // BASE_ID+23 + addCritter(dbClient,new Critter(BASE_ID + 24, "Grimer", KINDS.get(4))); // BASE_ID+24 + addCritter(dbClient,new Critter(BASE_ID + 25, "Cubchoo", KINDS.get(15))); // BASE_ID+25 + addCritter(dbClient,new Critter(BASE_ID + 26, "Beartic", KINDS.get(15))); // BASE_ID+26 } catch (Exception ex) { LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex)); throw ex; @@ -89,13 +87,13 @@ public static void setup(DbClient dbClient) { */ @Test public void testCreateNamedDmlWithInsertStrStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Torchic", TYPES.get(10)); + Critter pokemon = new Critter(BASE_ID + 1, "Torchic", KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -103,12 +101,12 @@ public void testCreateNamedDmlWithInsertStrStrNamedArgs() { */ @Test public void testCreateNamedDmlWithInsertStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 2, "Combusken", TYPES.get(2), TYPES.get(10)); + Critter pokemon = new Critter(BASE_ID + 2, "Combusken", KINDS.get(2), KINDS.get(10)); long result = dbClient.execute() .createNamedDmlStatement("insert-pokemon-named-arg") .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()) .execute(); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -116,12 +114,12 @@ public void testCreateNamedDmlWithInsertStrNamedArgs() { */ @Test public void testCreateNamedDmlWithInsertStrOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 3, "Treecko", TYPES.get(12)); + Critter pokemon = new Critter(BASE_ID + 3, "Treecko", KINDS.get(12)); long result = dbClient.execute() .createNamedDmlStatement("insert-pokemon-order-arg") .addParam(pokemon.getId()).addParam(pokemon.getName()) .execute(); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -129,13 +127,13 @@ public void testCreateNamedDmlWithInsertStrOrderArgs() { */ @Test public void testCreateDmlWithInsertNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 4, "Grovyle", TYPES.get(12)); + Critter pokemon = new Critter(BASE_ID + 4, "Grovyle", KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -143,13 +141,13 @@ public void testCreateDmlWithInsertNamedArgs() { */ @Test public void testCreateDmlWithInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 5, "Sceptile", TYPES.get(12)); + Critter pokemon = new Critter(BASE_ID + 5, "Sceptile", KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -158,10 +156,10 @@ public void testCreateDmlWithInsertOrderArgs() { */ @Test public void testNamedDmlWithInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 6, "Snover", TYPES.get(12), TYPES.get(15)); + Critter pokemon = new Critter(BASE_ID + 6, "Snover", KINDS.get(12), KINDS.get(15)); long result = dbClient.execute() .namedDml("insert-pokemon-order-arg", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -170,11 +168,11 @@ public void testNamedDmlWithInsertOrderArgs() { */ @Test public void testDmlWithInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 7, "Abomasnow", TYPES.get(12), TYPES.get(15)); + Critter pokemon = new Critter(BASE_ID + 7, "Abomasnow", KINDS.get(12), KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -182,14 +180,14 @@ public void testDmlWithInsertOrderArgs() { */ @Test public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 10); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 10, "Prinplup", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 10); + Critter updatedCritter = new Critter(BASE_ID + 10, "Prinplup", srcCritter.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()) + .addParam("name", updatedCritter.getName()).addParam("id", updatedCritter.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -197,13 +195,13 @@ public void testCreateNamedDmlWithUpdateStrStrNamedArgs() { */ @Test public void testCreateNamedDmlWithUpdateStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 11); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 11, "Empoleon", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 11); + Critter updatedCritter = new Critter(BASE_ID + 11, "Empoleon", srcCritter.getTypesArray()); long result = dbClient.execute() .createNamedDmlStatement("update-pokemon-named-arg") - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) + .addParam("name", updatedCritter.getName()).addParam("id", updatedCritter.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -211,13 +209,13 @@ public void testCreateNamedDmlWithUpdateStrNamedArgs() { */ @Test public void testCreateNamedDmlWithUpdateStrOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 12); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 12, "Piplup", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 12); + Critter updatedCritter = new Critter(BASE_ID + 12, "Piplup", srcCritter.getTypesArray()); long result = dbClient.execute() .createNamedDmlStatement("update-pokemon-order-arg") - .addParam(updatedPokemon.getName()).addParam(updatedPokemon.getId()) + .addParam(updatedCritter.getName()).addParam(updatedCritter.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -225,14 +223,14 @@ public void testCreateNamedDmlWithUpdateStrOrderArgs() { */ @Test public void testCreateDmlWithUpdateNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 13); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 13, "Starmie", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 13); + Critter updatedCritter = new Critter(BASE_ID + 13, "Starmie", srcCritter.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()) + .addParam("name", updatedCritter.getName()).addParam("id", updatedCritter.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -240,14 +238,14 @@ public void testCreateDmlWithUpdateNamedArgs() { */ @Test public void testCreateDmlWithUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 14); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 14, "Staryu", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 14); + Critter updatedCritter = new Critter(BASE_ID + 14, "Staryu", srcCritter.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()) + .addParam(updatedCritter.getName()).addParam(updatedCritter.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -256,11 +254,11 @@ public void testCreateDmlWithUpdateOrderArgs() { */ @Test public void testNamedDmlWithUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 15); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 15, "Seadra", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 15); + Critter updatedCritter = new Critter(BASE_ID + 15, "Seadra", srcCritter.getTypesArray()); long result = dbClient.execute() - .namedDml("update-pokemon-order-arg", updatedPokemon.getName(), updatedPokemon.getId()); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + .namedDml("update-pokemon-order-arg", updatedCritter.getName(), updatedCritter.getId()); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -269,12 +267,12 @@ public void testNamedDmlWithUpdateOrderArgs() { */ @Test public void testDmlWithUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 16); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 16, "Horsea", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 16); + Critter updatedCritter = new Critter(BASE_ID + 16, "Horsea", srcCritter.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); + .dml(stmt, updatedCritter.getName(), updatedCritter.getId()); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -282,13 +280,13 @@ public void testDmlWithUpdateOrderArgs() { */ @Test public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 20); + Critter 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); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -296,12 +294,12 @@ public void testCreateNamedDmlWithDeleteStrStrOrderArgs() { */ @Test public void testCreateNamedDmlWithDeleteStrNamedArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 21); + Critter pokemon = POKEMONS.get(BASE_ID + 21); long result = dbClient.execute() .createNamedDmlStatement("delete-pokemon-named-arg") .addParam("id", pokemon.getId()) .execute(); - verifyDeletePokemon(dbClient, result, pokemon); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -309,12 +307,12 @@ public void testCreateNamedDmlWithDeleteStrNamedArgs() { */ @Test public void testCreateNamedDmlWithDeleteStrOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 22); + Critter pokemon = POKEMONS.get(BASE_ID + 22); long result = dbClient.execute() .createNamedDmlStatement("delete-pokemon-order-arg") .addParam(pokemon.getId()) .execute(); - verifyDeletePokemon(dbClient, result, pokemon); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -322,13 +320,13 @@ public void testCreateNamedDmlWithDeleteStrOrderArgs() { */ @Test public void testCreateDmlWithDeleteNamedArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 23); + Critter 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); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -336,13 +334,13 @@ public void testCreateDmlWithDeleteNamedArgs() { */ @Test public void testCreateDmlWithDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 24); + Critter 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); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -350,9 +348,9 @@ public void testCreateDmlWithDeleteOrderArgs() { */ @Test public void testNamedDmlWithDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 25); + Critter pokemon = POKEMONS.get(BASE_ID + 25); long result = dbClient.execute().namedDml("delete-pokemon-order-arg", pokemon.getId()); - verifyDeletePokemon(dbClient, result, pokemon); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -360,9 +358,9 @@ public void testNamedDmlWithDeleteOrderArgs() { */ @Test public void testDmlWithDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 26); + Critter 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); + verifyDeleteCritter(dbClient, result, pokemon); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleGetIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleGetIT.java similarity index 73% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleGetIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleGetIT.java index 07ba959e42a..fe755385e70 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleGetIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleGetIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.util.Optional; @@ -22,16 +22,14 @@ 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; +import static io.helidon.dbclient.tests.common.model.Critter.CRITTERS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyCritter; /** * Test set of basic JDBC get calls. */ -@ExtendWith(DbClientParameterResolver.class) -public class SimpleGetIT { +public abstract class SimpleGetIT { private final DbClient dbClient; private final Config config; @@ -49,9 +47,9 @@ 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()) + .addParam("name", CRITTERS.get(1).getName()) .execute(); - verifyPokemon(maybeRow, POKEMONS.get(1)); + verifyCritter(maybeRow, CRITTERS.get(1)); } /** @@ -61,9 +59,9 @@ public void testCreateNamedGetStrStrNamedArgs() { public void testCreateNamedGetStrNamedArgs() { Optional maybeRow = dbClient.execute() .createNamedGet("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(2).getName()) + .addParam("name", CRITTERS.get(2).getName()) .execute(); - verifyPokemon(maybeRow, POKEMONS.get(2)); + verifyCritter(maybeRow, CRITTERS.get(2)); } /** @@ -73,9 +71,9 @@ public void testCreateNamedGetStrNamedArgs() { public void testCreateNamedGetStrOrderArgs() { Optional maybeRow = dbClient.execute() .createNamedGet("select-pokemon-order-arg") - .addParam(POKEMONS.get(3).getName()) + .addParam(CRITTERS.get(3).getName()) .execute(); - verifyPokemon(maybeRow, POKEMONS.get(3)); + verifyCritter(maybeRow, CRITTERS.get(3)); } /** @@ -86,9 +84,9 @@ 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()) + .addParam("name", CRITTERS.get(4).getName()) .execute(); - verifyPokemon(maybeRow, POKEMONS.get(4)); + verifyCritter(maybeRow, CRITTERS.get(4)); } /** @@ -99,9 +97,9 @@ 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()) + .addParam(CRITTERS.get(5).getName()) .execute(); - verifyPokemon(maybeRow, POKEMONS.get(5)); + verifyCritter(maybeRow, CRITTERS.get(5)); } /** @@ -110,8 +108,8 @@ public void testCreateGetOrderArgs() { @Test public void testNamedGetStrOrderArgs() { Optional maybeRow = dbClient.execute() - .namedGet("select-pokemon-order-arg", POKEMONS.get(6).getName()); - verifyPokemon(maybeRow, POKEMONS.get(6)); + .namedGet("select-pokemon-order-arg", CRITTERS.get(6).getName()); + verifyCritter(maybeRow, CRITTERS.get(6)); } /** @@ -121,7 +119,7 @@ public void testNamedGetStrOrderArgs() { 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)); + .get(stmt, CRITTERS.get(7).getName()); + verifyCritter(maybeRow, CRITTERS.get(7)); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleInsertIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleInsertIT.java similarity index 71% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleInsertIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleInsertIT.java index de26e70a6e7..7bd040e773b 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleInsertIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleInsertIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,28 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.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 io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.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; +import static io.helidon.dbclient.tests.common.model.Kind.KINDS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyInsertCritter; /** * Test set of basic JDBC inserts. */ @SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class SimpleInsertIT { +public abstract class SimpleInsertIT { /** - * Maximum Pokemon ID. + * Maximum Critter ID. */ private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 10; @@ -51,13 +49,13 @@ public SimpleInsertIT(DbClient dbClient, Config config) { */ @Test public void testCreateNamedInsertStrStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Bulbasaur", TYPES.get(4), TYPES.get(12)); + Critter pokemon = new Critter(BASE_ID + 1, "Bulbasaur", KINDS.get(4), KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -65,12 +63,12 @@ public void testCreateNamedInsertStrStrNamedArgs() { */ @Test public void testCreateNamedInsertStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 2, "Ivysaur", TYPES.get(4), TYPES.get(12)); + Critter pokemon = new Critter(BASE_ID + 2, "Ivysaur", KINDS.get(4), KINDS.get(12)); long result = dbClient.execute() .createNamedInsert("insert-pokemon-named-arg") .addParam("id", pokemon.getId()).addParam("name", pokemon.getName()) .execute(); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -78,12 +76,12 @@ public void testCreateNamedInsertStrNamedArgs() { */ @Test public void testCreateNamedInsertStrOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 3, "Venusaur", TYPES.get(4), TYPES.get(12)); + Critter pokemon = new Critter(BASE_ID + 3, "Venusaur", KINDS.get(4), KINDS.get(12)); long result = dbClient.execute() .createNamedInsert("insert-pokemon-order-arg") .addParam(pokemon.getId()).addParam(pokemon.getName()) .execute(); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -91,13 +89,13 @@ public void testCreateNamedInsertStrOrderArgs() { */ @Test public void testCreateInsertNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 4, "Magby", TYPES.get(10)); + Critter pokemon = new Critter(BASE_ID + 4, "Magby", KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -105,13 +103,13 @@ public void testCreateInsertNamedArgs() { */ @Test public void testCreateInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 5, "Magmar", TYPES.get(10)); + Critter pokemon = new Critter(BASE_ID + 5, "Magmar", KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -119,9 +117,9 @@ public void testCreateInsertOrderArgs() { */ @Test public void testNamedInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 6, "Rattata", TYPES.get(1)); + Critter pokemon = new Critter(BASE_ID + 6, "Rattata", KINDS.get(1)); long result = dbClient.execute().namedInsert("insert-pokemon-order-arg", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -129,10 +127,10 @@ public void testNamedInsertOrderArgs() { */ @Test public void testInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 7, "Raticate", TYPES.get(1)); + Critter pokemon = new Critter(BASE_ID + 7, "Raticate", KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleQueriesIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleQueriesIT.java similarity index 74% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleQueriesIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleQueriesIT.java index 10d355205db..5794a31ccb8 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleQueriesIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleQueriesIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.util.stream.Stream; @@ -22,16 +22,14 @@ 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; +import static io.helidon.dbclient.tests.common.model.Critter.CRITTERS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyCritter; /** * Test set of basic JDBC queries. */ -@ExtendWith(DbClientParameterResolver.class) -public class SimpleQueriesIT { +public abstract class SimpleQueriesIT { private final DbClient dbClient; private final Config config; @@ -49,10 +47,10 @@ 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()) + .addParam(CRITTERS.get(1).getName()) .execute(); - verifyPokemon(rows, POKEMONS.get(1)); + verifyCritter(rows, CRITTERS.get(1)); } /** @@ -62,9 +60,9 @@ public void testCreateNamedQueryStrStrOrderArgs() { public void testCreateNamedQueryStrNamedArgs() { Stream rows = dbClient.execute() .createNamedQuery("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(2).getName()) + .addParam("name", CRITTERS.get(2).getName()) .execute(); - verifyPokemon(rows, POKEMONS.get(2)); + verifyCritter(rows, CRITTERS.get(2)); } /** @@ -74,9 +72,9 @@ public void testCreateNamedQueryStrNamedArgs() { public void testCreateNamedQueryStrOrderArgs() { Stream rows = dbClient.execute() .createNamedQuery("select-pokemon-order-arg") - .addParam(POKEMONS.get(3).getName()) + .addParam(CRITTERS.get(3).getName()) .execute(); - verifyPokemon(rows, POKEMONS.get(3)); + verifyCritter(rows, CRITTERS.get(3)); } /** @@ -87,9 +85,9 @@ 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()) + .addParam("name", CRITTERS.get(4).getName()) .execute(); - verifyPokemon(rows, POKEMONS.get(4)); + verifyCritter(rows, CRITTERS.get(4)); } /** @@ -100,9 +98,9 @@ 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()) + .addParam(CRITTERS.get(5).getName()) .execute(); - verifyPokemon(rows, POKEMONS.get(5)); + verifyCritter(rows, CRITTERS.get(5)); } /** @@ -111,8 +109,8 @@ public void testCreateQueryOrderArgs() { @Test public void testNamedQueryOrderArgs() { Stream rows = dbClient.execute() - .namedQuery("select-pokemon-order-arg", POKEMONS.get(6).getName()); - verifyPokemon(rows, POKEMONS.get(6)); + .namedQuery("select-pokemon-order-arg", CRITTERS.get(6).getName()); + verifyCritter(rows, CRITTERS.get(6)); } /** @@ -122,8 +120,8 @@ public void testNamedQueryOrderArgs() { 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)); + .query(stmt, CRITTERS.get(7).getName()); + verifyCritter(rows, CRITTERS.get(7)); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleUpdateIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleUpdateIT.java similarity index 52% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleUpdateIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleUpdateIT.java index 8e8f820a793..ee91a031a6e 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/SimpleUpdateIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/SimpleUpdateIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; import java.util.HashMap; @@ -21,27 +21,25 @@ 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 io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.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; +import static io.helidon.dbclient.tests.common.model.Kind.KINDS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyInsertCritter; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyUpdateCritter; /** * Test set of basic JDBC updates. */ @SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class SimpleUpdateIT { +public abstract 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 static final Map POKEMONS = new HashMap<>(); private final DbClient dbClient; private final Config config; @@ -51,11 +49,11 @@ public SimpleUpdateIT(DbClient dbClient, Config config) { this.config = config; } - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { + private static void addCritter(DbClient dbClient, Critter pokemon) { POKEMONS.put(pokemon.getId(), pokemon); long result = dbClient.execute() .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -65,13 +63,13 @@ private static void addPokemon(DbClient dbClient, Pokemon pokemon) { 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 + addCritter(dbClient, new Critter(++curId, "Spearow", KINDS.get(1), KINDS.get(3))); // BASE_ID+1 + addCritter(dbClient, new Critter(++curId, "Fearow", KINDS.get(1), KINDS.get(3))); // BASE_ID+2 + addCritter(dbClient, new Critter(++curId, "Ekans", KINDS.get(4))); // BASE_ID+3 + addCritter(dbClient, new Critter(++curId, "Arbok", KINDS.get(4))); // BASE_ID+4 + addCritter(dbClient, new Critter(++curId, "Sandshrew", KINDS.get(5))); // BASE_ID+5 + addCritter(dbClient, new Critter(++curId, "Sandslash", KINDS.get(5))); // BASE_ID+6 + addCritter(dbClient, new Critter(++curId, "Diglett", KINDS.get(5))); // BASE_ID+7 } catch (Exception ex) { LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex)); throw ex; @@ -83,14 +81,14 @@ public static void setup(DbClient dbClient) { */ @Test public void testCreateNamedUpdateStrStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 1); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 1, "Fearow", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 1); + Critter updatedCritter = new Critter(BASE_ID + 1, "Fearow", srcCritter.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()) + .addParam("name", updatedCritter.getName()).addParam("id", updatedCritter.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -98,13 +96,13 @@ public void testCreateNamedUpdateStrStrNamedArgs() { */ @Test public void testCreateNamedUpdateStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 2); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 2, "Spearow", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 2); + Critter updatedCritter = new Critter(BASE_ID + 2, "Spearow", srcCritter.getTypesArray()); long result = dbClient.execute() .createNamedUpdate("update-pokemon-named-arg") - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) + .addParam("name", updatedCritter.getName()).addParam("id", updatedCritter.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -112,13 +110,13 @@ public void testCreateNamedUpdateStrNamedArgs() { */ @Test public void testCreateNamedUpdateStrOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 3); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 3, "Arbok", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 3); + Critter updatedCritter = new Critter(BASE_ID + 3, "Arbok", srcCritter.getTypesArray()); long result = dbClient.execute() .createNamedUpdate("update-pokemon-order-arg") - .addParam(updatedPokemon.getName()).addParam(updatedPokemon.getId()) + .addParam(updatedCritter.getName()).addParam(updatedCritter.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -126,14 +124,14 @@ public void testCreateNamedUpdateStrOrderArgs() { */ @Test public void testCreateUpdateNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 4); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 4, "Ekans", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 4); + Critter updatedCritter = new Critter(BASE_ID + 4, "Ekans", srcCritter.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()) + .addParam("name", updatedCritter.getName()).addParam("id", updatedCritter.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -141,14 +139,14 @@ public void testCreateUpdateNamedArgs() { */ @Test public void testCreateUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 5); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 5, "Diglett", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 5); + Critter updatedCritter = new Critter(BASE_ID + 5, "Diglett", srcCritter.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()) + .addParam(updatedCritter.getName()).addParam(updatedCritter.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -156,11 +154,11 @@ public void testCreateUpdateOrderArgs() { */ @Test public void testNamedUpdateNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 6); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 6, "Sandshrew", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 6); + Critter updatedCritter = new Critter(BASE_ID + 6, "Sandshrew", srcCritter.getTypesArray()); long result = dbClient.execute() - .namedUpdate("update-pokemon-order-arg", updatedPokemon.getName(), updatedPokemon.getId()); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + .namedUpdate("update-pokemon-order-arg", updatedCritter.getName(), updatedCritter.getId()); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -168,11 +166,11 @@ public void testNamedUpdateNamedArgs() { */ @Test public void testUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 7); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 7, "Sandslash", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 7); + Critter updatedCritter = new Critter(BASE_ID + 7, "Sandslash", srcCritter.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); + .update(stmt, updatedCritter.getName(), updatedCritter.getId()); + verifyUpdateCritter(dbClient, result, updatedCritter); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/StatementDmlIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/StatementDmlIT.java similarity index 63% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/StatementDmlIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/StatementDmlIT.java index d8cc1be2150..33101b7795d 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/StatementDmlIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/StatementDmlIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; import java.util.ArrayList; @@ -22,23 +22,21 @@ 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 io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.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; +import static io.helidon.dbclient.tests.common.model.Kind.KINDS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyInsertCritter; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyUpdateCritter; /** * Test DbStatementDml methods. */ @SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class StatementDmlIT { +public abstract class StatementDmlIT { private static final System.Logger LOGGER = System.getLogger(StatementDmlIT.class.getName()); private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 100; @@ -49,10 +47,10 @@ public StatementDmlIT(DbClient dbClient) { this.dbClient = dbClient; } - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { + private static void addCritter(DbClient dbClient, Critter pokemon) { long result = dbClient.execute() .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -61,13 +59,13 @@ private static void addPokemon(DbClient dbClient, Pokemon pokemon) { @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 + addCritter(dbClient, new Critter(BASE_ID, "Shinx", KINDS.get(13))); // BASE_ID+0 + addCritter(dbClient, new Critter(BASE_ID + 1, "Luxio", KINDS.get(13))); // BASE_ID+1 + addCritter(dbClient, new Critter(BASE_ID + 2, "Luxray", KINDS.get(13))); // BASE_ID+2 + addCritter(dbClient, new Critter(BASE_ID + 3, "Kricketot", KINDS.get(7))); // BASE_ID+3 + addCritter(dbClient, new Critter(BASE_ID + 4, "Kricketune", KINDS.get(7))); // BASE_ID+4 + addCritter(dbClient, new Critter(BASE_ID + 5, "Phione", KINDS.get(11))); // BASE_ID+5 + addCritter(dbClient, new Critter(BASE_ID + 6, "Chatot", KINDS.get(1), KINDS.get(3))); // BASE_ID+6 } catch (Exception ex) { LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex), ex); throw ex; @@ -79,12 +77,12 @@ public static void setup(DbClient dbClient) { */ @Test public void testDmlArrayParams() { - Pokemon pokemon = new Pokemon(BASE_ID, "Luxio", TYPES.get(13)); + Critter pokemon = new Critter(BASE_ID, "Luxio", KINDS.get(13)); long result = dbClient.execute() .createNamedDmlStatement("update-pokemon-order-arg") .params(pokemon.getName(), pokemon.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); + verifyUpdateCritter(dbClient, result, pokemon); } /** @@ -92,7 +90,7 @@ public void testDmlArrayParams() { */ @Test public void testDmlListParams() { - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Luxray", TYPES.get(13)); + Critter pokemon = new Critter(BASE_ID + 1, "Luxray", KINDS.get(13)); List params = new ArrayList<>(2); params.add(pokemon.getName()); params.add(pokemon.getId()); @@ -100,7 +98,7 @@ public void testDmlListParams() { .createNamedDmlStatement("update-pokemon-order-arg") .params(params) .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); + verifyUpdateCritter(dbClient, result, pokemon); } /** @@ -108,7 +106,7 @@ public void testDmlListParams() { */ @Test public void testDmlMapParams() { - Pokemon pokemon = new Pokemon(BASE_ID + 2, "Shinx", TYPES.get(13)); + Critter pokemon = new Critter(BASE_ID + 2, "Shinx", KINDS.get(13)); Map params = new HashMap<>(2); params.put("name", pokemon.getName()); params.put("id", pokemon.getId()); @@ -116,7 +114,7 @@ public void testDmlMapParams() { .createNamedDmlStatement("update-pokemon-named-arg") .params(params) .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); + verifyUpdateCritter(dbClient, result, pokemon); } /** @@ -124,13 +122,13 @@ public void testDmlMapParams() { */ @Test public void testDmlOrderParam() { - Pokemon pokemon = new Pokemon(BASE_ID + 3, "Kricketune", TYPES.get(7)); + Critter pokemon = new Critter(BASE_ID + 3, "Kricketune", KINDS.get(7)); long result = dbClient.execute() .createNamedDmlStatement("update-pokemon-order-arg") .addParam(pokemon.getName()) .addParam(pokemon.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); + verifyUpdateCritter(dbClient, result, pokemon); } /** @@ -138,13 +136,13 @@ public void testDmlOrderParam() { */ @Test public void testDmlNamedParam() { - Pokemon pokemon = new Pokemon(BASE_ID + 4, "Kricketot", TYPES.get(7)); + Critter pokemon = new Critter(BASE_ID + 4, "Kricketot", KINDS.get(7)); long result = dbClient.execute() .createNamedDmlStatement("update-pokemon-named-arg") .addParam("name", pokemon.getName()) .addParam("id", pokemon.getId()) .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); + verifyUpdateCritter(dbClient, result, pokemon); } /** @@ -152,12 +150,12 @@ public void testDmlNamedParam() { */ @Test public void testDmlMappedNamedParam() { - Pokemon pokemon = new Pokemon(BASE_ID + 5, "Chatot", TYPES.get(1), TYPES.get(3)); + Critter pokemon = new Critter(BASE_ID + 5, "Chatot", KINDS.get(1), KINDS.get(3)); long result = dbClient.execute() .createNamedDmlStatement("update-pokemon-named-arg") .namedParam(pokemon) .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); + verifyUpdateCritter(dbClient, result, pokemon); } /** @@ -165,11 +163,11 @@ public void testDmlMappedNamedParam() { */ @Test public void testDmlMappedOrderParam() { - Pokemon pokemon = new Pokemon(BASE_ID + 6, "Phione", TYPES.get(11)); + Critter pokemon = new Critter(BASE_ID + 6, "Phione", KINDS.get(11)); long result = dbClient.execute() .createNamedDmlStatement("update-pokemon-order-arg") .indexedParam(pokemon) .execute(); - verifyUpdatePokemon(dbClient, result, pokemon); + verifyUpdateCritter(dbClient, result, pokemon); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionDeleteIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionDeleteIT.java similarity index 67% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionDeleteIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionDeleteIT.java index 0a3203142ef..ba5d8a3094f 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionDeleteIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionDeleteIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; import java.util.HashMap; @@ -23,27 +23,25 @@ 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 io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.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.dbclient.tests.common.model.Kind.KINDS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyDeleteCritter; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyInsertCritter; /** * Test set of basic JDBC delete calls in transaction. */ @SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class TransactionDeleteIT { +public abstract 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 static final Map POKEMONS = new HashMap<>(); private final DbClient dbClient; private final Config config; @@ -53,24 +51,24 @@ public TransactionDeleteIT(DbClient dbClient, Config config) { this.config = config; } - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { + private static void addCritter(DbClient dbClient, Critter pokemon) { POKEMONS.put(pokemon.getId(), pokemon); long result = dbClient.execute() .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(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 + addCritter(dbClient, new Critter(++curId, "Omanyte", KINDS.get(6), KINDS.get(11))); // BASE_ID+1 + addCritter(dbClient, new Critter(++curId, "Omastar", KINDS.get(6), KINDS.get(11))); // BASE_ID+2 + addCritter(dbClient, new Critter(++curId, "Kabuto", KINDS.get(6), KINDS.get(11))); // BASE_ID+3 + addCritter(dbClient, new Critter(++curId, "Kabutops", KINDS.get(6), KINDS.get(11))); // BASE_ID+4 + addCritter(dbClient, new Critter(++curId, "Chikorita", KINDS.get(12))); // BASE_ID+5 + addCritter(dbClient, new Critter(++curId, "Bayleef", KINDS.get(12))); // BASE_ID+6 + addCritter(dbClient, new Critter(++curId, "Meganium", KINDS.get(12))); // BASE_ID+7 } catch (Exception ex) { LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex)); throw ex; @@ -82,7 +80,7 @@ public static void setup(DbClient dbClient) throws ExecutionException, Interrupt */ @Test public void testCreateNamedDeleteStrStrOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 1); + Critter 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 @@ -90,7 +88,7 @@ public void testCreateNamedDeleteStrStrOrderArgs() { .addParam(pokemon.getId()) .execute(); tx.commit(); - verifyDeletePokemon(dbClient, result, pokemon); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -98,14 +96,14 @@ public void testCreateNamedDeleteStrStrOrderArgs() { */ @Test public void testCreateNamedDeleteStrNamedArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 2); + Critter 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); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -113,14 +111,14 @@ public void testCreateNamedDeleteStrNamedArgs() { */ @Test public void testCreateNamedDeleteStrOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 3); + Critter 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); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -128,7 +126,7 @@ public void testCreateNamedDeleteStrOrderArgs() { */ @Test public void testCreateDeleteNamedArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 4); + Critter 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 @@ -136,7 +134,7 @@ public void testCreateDeleteNamedArgs() { .addParam("id", pokemon.getId()) .execute(); tx.commit(); - verifyDeletePokemon(dbClient, result, pokemon); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -144,7 +142,7 @@ public void testCreateDeleteNamedArgs() { */ @Test public void testCreateDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 5); + Critter 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 @@ -152,7 +150,7 @@ public void testCreateDeleteOrderArgs() { .addParam(pokemon.getId()) .execute(); tx.commit(); - verifyDeletePokemon(dbClient, result, pokemon); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -160,12 +158,12 @@ public void testCreateDeleteOrderArgs() { */ @Test public void testNamedDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 6); + Critter 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); + verifyDeleteCritter(dbClient, result, pokemon); } /** @@ -173,12 +171,12 @@ public void testNamedDeleteOrderArgs() { */ @Test public void testDeleteOrderArgs() { - Pokemon pokemon = POKEMONS.get(BASE_ID + 7); + Critter 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); + verifyDeleteCritter(dbClient, result, pokemon); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionExceptionalStmtIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionExceptionalStmtIT.java similarity index 88% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionExceptionalStmtIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionExceptionalStmtIT.java index f32eac068e2..9b7cc05fd44 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionExceptionalStmtIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionExceptionalStmtIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; import java.util.concurrent.CompletionException; @@ -23,16 +23,14 @@ 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.dbclient.tests.common.model.Critter.CRITTERS; import static org.junit.jupiter.api.Assertions.fail; /** * Test exceptional states. */ -@ExtendWith(DbClientParameterResolver.class) -public class TransactionExceptionalStmtIT { +public abstract class TransactionExceptionalStmtIT { private static final System.Logger LOGGER = System.getLogger(TransactionExceptionalStmtIT.class.getName()); @@ -85,8 +83,8 @@ 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()) + .addParam("id", CRITTERS.get(5).getId()) + .addParam(CRITTERS.get(5).getName()) .execute() .forEach(it -> {}); tx.commit(); @@ -104,7 +102,7 @@ public void testCreateNamedQueryNamedArgsSetOrderArg() { try { DbTransaction tx = dbClient.transaction(); tx.createNamedQuery("select-pokemon-named-arg") - .addParam(POKEMONS.get(5).getName()) + .addParam(CRITTERS.get(5).getName()) .execute() .forEach(it -> {}); tx.commit(); @@ -122,7 +120,7 @@ public void testCreateNamedQueryOrderArgsSetNamedArg() { try { DbTransaction tx = dbClient.transaction(); tx.createNamedQuery("select-pokemon-order-arg") - .addParam("name", POKEMONS.get(6).getName()) + .addParam("name", CRITTERS.get(6).getName()) .execute() .forEach(it -> {}); tx.commit(); diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionGetIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionGetIT.java similarity index 76% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionGetIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionGetIT.java index 43e4e7ae108..6d7d3508ed3 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionGetIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionGetIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.util.Optional; @@ -23,16 +23,14 @@ 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; +import static io.helidon.dbclient.tests.common.model.Critter.CRITTERS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyCritter; /** * Test set of basic JDBC get calls in transaction. */ -@ExtendWith(DbClientParameterResolver.class) -public class TransactionGetIT { +public abstract class TransactionGetIT { private final DbClient dbClient; private final Config config; @@ -51,10 +49,10 @@ public void testCreateNamedGetStrStrNamedArgs() { DbTransaction tx = dbClient.transaction(); Optional maybeRow = tx .createNamedGet("select-pikachu", stmt) - .addParam("name", POKEMONS.get(1).getName()) + .addParam("name", CRITTERS.get(1).getName()) .execute(); tx.commit(); - verifyPokemon(maybeRow, POKEMONS.get(1)); + verifyCritter(maybeRow, CRITTERS.get(1)); } /** @@ -65,11 +63,11 @@ public void testCreateNamedGetStrNamedArgs() { DbTransaction tx = dbClient.transaction(); Optional maybeRow = tx .createNamedGet("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(2).getName()) + .addParam("name", CRITTERS.get(2).getName()) .execute(); tx.commit(); - verifyPokemon(maybeRow, POKEMONS.get(2)); + verifyCritter(maybeRow, CRITTERS.get(2)); } /** @@ -80,11 +78,11 @@ public void testCreateNamedGetStrOrderArgs() { DbTransaction tx = dbClient.transaction(); Optional maybeRow = tx .createNamedGet("select-pokemon-order-arg") - .addParam(POKEMONS.get(3).getName()) + .addParam(CRITTERS.get(3).getName()) .execute(); tx.commit(); - verifyPokemon(maybeRow, POKEMONS.get(3)); + verifyCritter(maybeRow, CRITTERS.get(3)); } /** @@ -96,11 +94,11 @@ public void testCreateGetNamedArgs() { DbTransaction tx = dbClient.transaction(); Optional maybeRow = tx .createGet(stmt) - .addParam("name", POKEMONS.get(4).getName()) + .addParam("name", CRITTERS.get(4).getName()) .execute(); tx.commit(); - verifyPokemon(maybeRow, POKEMONS.get(4)); + verifyCritter(maybeRow, CRITTERS.get(4)); } /** @@ -112,11 +110,11 @@ public void testCreateGetOrderArgs() { DbTransaction tx = dbClient.transaction(); Optional maybeRow = tx .createGet(stmt) - .addParam(POKEMONS.get(5).getName()) + .addParam(CRITTERS.get(5).getName()) .execute(); tx.commit(); - verifyPokemon(maybeRow, POKEMONS.get(5)); + verifyCritter(maybeRow, CRITTERS.get(5)); } /** @@ -126,10 +124,10 @@ public void testCreateGetOrderArgs() { public void testNamedGetStrOrderArgs() { DbTransaction tx = dbClient.transaction(); Optional maybeRow = tx - .namedGet("select-pokemon-order-arg", POKEMONS.get(6).getName()); + .namedGet("select-pokemon-order-arg", CRITTERS.get(6).getName()); tx.commit(); - verifyPokemon(maybeRow, POKEMONS.get(6)); + verifyCritter(maybeRow, CRITTERS.get(6)); } /** @@ -140,9 +138,9 @@ 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()); + .get(stmt, CRITTERS.get(7).getName()); tx.commit(); - verifyPokemon(maybeRow, POKEMONS.get(7)); + verifyCritter(maybeRow, CRITTERS.get(7)); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionInsertIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionInsertIT.java similarity index 73% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionInsertIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionInsertIT.java index a8d19199f40..23f62588eea 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionInsertIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionInsertIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,26 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.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 io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.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; +import static io.helidon.dbclient.tests.common.model.Kind.KINDS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyInsertCritter; /** * Test set of basic JDBC inserts in transaction. */ @SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class TransactionInsertIT { +public abstract class TransactionInsertIT { private static final int BASE_ID = TestConfig.LAST_POKEMON_ID + 210; @@ -49,14 +47,14 @@ public TransactionInsertIT(DbClient dbClient, Config config) { */ @Test public void testCreateNamedInsertStrStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 1, "Sentret", TYPES.get(1)); + Critter pokemon = new Critter(BASE_ID + 1, "Sentret", KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -64,13 +62,13 @@ public void testCreateNamedInsertStrStrNamedArgs() { */ @Test public void testCreateNamedInsertStrNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 2, "Furret", TYPES.get(1)); + Critter pokemon = new Critter(BASE_ID + 2, "Furret", KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -78,13 +76,13 @@ public void testCreateNamedInsertStrNamedArgs() { */ @Test public void testCreateNamedInsertStrOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 3, "Chinchou", TYPES.get(11), TYPES.get(13)); + Critter pokemon = new Critter(BASE_ID + 3, "Chinchou", KINDS.get(11), KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -92,14 +90,14 @@ public void testCreateNamedInsertStrOrderArgs() { */ @Test public void testCreateInsertNamedArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 4, "Lanturn", TYPES.get(11), TYPES.get(13)); + Critter pokemon = new Critter(BASE_ID + 4, "Lanturn", KINDS.get(11), KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -107,14 +105,14 @@ public void testCreateInsertNamedArgs() { */ @Test public void testCreateInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 5, "Swinub", TYPES.get(5), TYPES.get(15)); + Critter pokemon = new Critter(BASE_ID + 5, "Swinub", KINDS.get(5), KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -122,12 +120,12 @@ public void testCreateInsertOrderArgs() { */ @Test public void testNamedInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 6, "Piloswine", TYPES.get(5), TYPES.get(15)); + Critter pokemon = new Critter(BASE_ID + 6, "Piloswine", KINDS.get(5), KINDS.get(15)); DbTransaction tx = dbClient.transaction(); long result = tx .namedInsert("insert-pokemon-order-arg", pokemon.getId(), pokemon.getName()); tx.commit(); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(dbClient, result, pokemon); } /** @@ -135,12 +133,12 @@ public void testNamedInsertOrderArgs() { */ @Test public void testInsertOrderArgs() { - Pokemon pokemon = new Pokemon(BASE_ID + 7, "Mamoswine", TYPES.get(5), TYPES.get(15)); + Critter pokemon = new Critter(BASE_ID + 7, "Mamoswine", KINDS.get(5), KINDS.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); + verifyInsertCritter(dbClient, result, pokemon); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionQueriesIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionQueriesIT.java similarity index 77% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionQueriesIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionQueriesIT.java index aba3a98e987..cb4968a5f8f 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionQueriesIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionQueriesIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.util.List; @@ -23,16 +23,14 @@ 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; +import static io.helidon.dbclient.tests.common.model.Critter.CRITTERS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyCritter; /** * Test set of basic JDBC queries in transaction. */ -@ExtendWith(DbClientParameterResolver.class) -public class TransactionQueriesIT { +public abstract class TransactionQueriesIT { private final DbClient dbClient; private final Config config; @@ -51,11 +49,11 @@ public void testCreateNamedQueryStrStrOrderArgs() { DbTransaction tx = dbClient.transaction(); List rows = tx .createNamedQuery("select-pikachu", stmt) - .addParam(POKEMONS.get(1).getName()) + .addParam(CRITTERS.get(1).getName()) .execute() .toList(); tx.commit(); - verifyPokemon(rows, POKEMONS.get(1)); + verifyCritter(rows, CRITTERS.get(1)); } /** @@ -66,11 +64,11 @@ public void testCreateNamedQueryStrNamedArgs() { DbTransaction tx = dbClient.transaction(); List rows = tx .createNamedQuery("select-pokemon-named-arg") - .addParam("name", POKEMONS.get(2).getName()) + .addParam("name", CRITTERS.get(2).getName()) .execute() .toList(); tx.commit(); - verifyPokemon(rows, POKEMONS.get(2)); + verifyCritter(rows, CRITTERS.get(2)); } /** @@ -81,11 +79,11 @@ public void testCreateNamedQueryStrOrderArgs() { DbTransaction tx = dbClient.transaction(); List rows = tx .createNamedQuery("select-pokemon-order-arg") - .addParam(POKEMONS.get(3).getName()) + .addParam(CRITTERS.get(3).getName()) .execute() .toList(); tx.commit(); - verifyPokemon(rows, POKEMONS.get(3)); + verifyCritter(rows, CRITTERS.get(3)); } /** @@ -97,11 +95,11 @@ public void testCreateQueryNamedArgs() { DbTransaction tx = dbClient.transaction(); List rows = tx .createQuery(stmt) - .addParam("name", POKEMONS.get(4).getName()) + .addParam("name", CRITTERS.get(4).getName()) .execute() .toList(); tx.commit(); - verifyPokemon(rows, POKEMONS.get(4)); + verifyCritter(rows, CRITTERS.get(4)); } /** @@ -113,11 +111,11 @@ public void testCreateQueryOrderArgs() { DbTransaction tx = dbClient.transaction(); List rows = tx .createQuery(stmt) - .addParam(POKEMONS.get(5).getName()) + .addParam(CRITTERS.get(5).getName()) .execute() .toList(); tx.commit(); - verifyPokemon(rows, POKEMONS.get(5)); + verifyCritter(rows, CRITTERS.get(5)); } /** @@ -127,10 +125,10 @@ public void testCreateQueryOrderArgs() { public void testNamedQueryOrderArgs() { DbTransaction tx = dbClient.transaction(); List rows = tx - .namedQuery("select-pokemon-order-arg", POKEMONS.get(6).getName()) + .namedQuery("select-pokemon-order-arg", CRITTERS.get(6).getName()) .toList(); tx.commit(); - verifyPokemon(rows, POKEMONS.get(6)); + verifyCritter(rows, CRITTERS.get(6)); } /** @@ -141,9 +139,9 @@ 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()) + .query(stmt, CRITTERS.get(7).getName()) .toList(); tx.commit(); - verifyPokemon(rows, POKEMONS.get(7)); + verifyCritter(rows, CRITTERS.get(7)); } } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionUpdateIT.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionUpdateIT.java similarity index 54% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionUpdateIT.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionUpdateIT.java index c39f3a57910..12114e74b51 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/tests/TransactionUpdateIT.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/tests/TransactionUpdateIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.tests; +package io.helidon.dbclient.tests.common.tests; import java.lang.System.Logger.Level; import java.util.HashMap; @@ -22,27 +22,25 @@ 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 io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.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; +import static io.helidon.dbclient.tests.common.model.Kind.KINDS; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyInsertCritter; +import static io.helidon.dbclient.tests.common.utils.VerifyData.verifyUpdateCritter; /** * Test set of basic JDBC updates in transaction. */ @SuppressWarnings("SpellCheckingInspection") -@ExtendWith(DbClientParameterResolver.class) -public class TransactionUpdateIT { +public abstract 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 static final Map POKEMONS = new HashMap<>(); private final DbClient dbClient; private final Config config; @@ -52,24 +50,24 @@ public TransactionUpdateIT(DbClient dbClient, Config config) { this.config = config; } - private static void addPokemon(DbClient dbClient, Pokemon pokemon) { + private static void addCritter(DbClient dbClient, Critter pokemon) { POKEMONS.put(pokemon.getId(), pokemon); long result = dbClient.execute() .namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName()); - verifyInsertPokemon(dbClient, result, pokemon); + verifyInsertCritter(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 + addCritter(dbClient, new Critter(++curId, "Teddiursa", KINDS.get(1))); // BASE_ID+1 + addCritter(dbClient, new Critter(++curId, "Ursaring", KINDS.get(1))); // BASE_ID+2 + addCritter(dbClient, new Critter(++curId, "Slugma", KINDS.get(10))); // BASE_ID+3 + addCritter(dbClient, new Critter(++curId, "Magcargo", KINDS.get(6), KINDS.get(10))); // BASE_ID+4 + addCritter(dbClient, new Critter(++curId, "Lotad", KINDS.get(11), KINDS.get(12))); // BASE_ID+5 + addCritter(dbClient, new Critter(++curId, "Lombre", KINDS.get(11), KINDS.get(12))); // BASE_ID+6 + addCritter(dbClient, new Critter(++curId, "Ludicolo", KINDS.get(11), KINDS.get(12))); // BASE_ID+7 } catch (Exception ex) { LOGGER.log(Level.WARNING, String.format("Exception in setup: %s", ex)); throw ex; @@ -81,16 +79,16 @@ public static void setup(DbClient dbClient) { */ @Test public void testCreateNamedUpdateStrStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 1); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 1, "Ursaring", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 1); + Critter updatedCritter = new Critter(BASE_ID + 1, "Ursaring", srcCritter.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()) + .addParam("name", updatedCritter.getName()).addParam("id", updatedCritter.getId()) .execute(); tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -98,15 +96,15 @@ public void testCreateNamedUpdateStrStrNamedArgs() { */ @Test public void testCreateNamedUpdateStrNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 2); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 2, "Teddiursa", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 2); + Critter updatedCritter = new Critter(BASE_ID + 2, "Teddiursa", srcCritter.getTypesArray()); DbTransaction tx = dbClient.transaction(); long result = tx .createNamedUpdate("update-pokemon-named-arg") - .addParam("name", updatedPokemon.getName()).addParam("id", updatedPokemon.getId()) + .addParam("name", updatedCritter.getName()).addParam("id", updatedCritter.getId()) .execute(); tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -114,15 +112,15 @@ public void testCreateNamedUpdateStrNamedArgs() { */ @Test public void testCreateNamedUpdateStrOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 3); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 3, "Magcargo", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 3); + Critter updatedCritter = new Critter(BASE_ID + 3, "Magcargo", srcCritter.getTypesArray()); DbTransaction tx = dbClient.transaction(); long result = tx .createNamedUpdate("update-pokemon-order-arg") - .addParam(updatedPokemon.getName()).addParam(updatedPokemon.getId()) + .addParam(updatedCritter.getName()).addParam(updatedCritter.getId()) .execute(); tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -130,16 +128,16 @@ public void testCreateNamedUpdateStrOrderArgs() { */ @Test public void testCreateUpdateNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 4); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 4, "Slugma", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 4); + Critter updatedCritter = new Critter(BASE_ID + 4, "Slugma", srcCritter.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()) + .addParam("name", updatedCritter.getName()).addParam("id", updatedCritter.getId()) .execute(); tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -147,16 +145,16 @@ public void testCreateUpdateNamedArgs() { */ @Test public void testCreateUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 5); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 5, "Lombre", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 5); + Critter updatedCritter = new Critter(BASE_ID + 5, "Lombre", srcCritter.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()) + .addParam(updatedCritter.getName()).addParam(updatedCritter.getId()) .execute(); tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -164,13 +162,13 @@ public void testCreateUpdateOrderArgs() { */ @Test public void testNamedUpdateNamedArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 6); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 6, "Ludicolo", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 6); + Critter updatedCritter = new Critter(BASE_ID + 6, "Ludicolo", srcCritter.getTypesArray()); DbTransaction tx = dbClient.transaction(); long result = tx - .namedUpdate("update-pokemon-order-arg", updatedPokemon.getName(), updatedPokemon.getId()); + .namedUpdate("update-pokemon-order-arg", updatedCritter.getName(), updatedCritter.getId()); tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } /** @@ -178,13 +176,13 @@ public void testNamedUpdateNamedArgs() { */ @Test public void testUpdateOrderArgs() { - Pokemon srcPokemon = POKEMONS.get(BASE_ID + 7); - Pokemon updatedPokemon = new Pokemon(BASE_ID + 7, "Lotad", srcPokemon.getTypesArray()); + Critter srcCritter = POKEMONS.get(BASE_ID + 7); + Critter updatedCritter = new Critter(BASE_ID + 7, "Lotad", srcCritter.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()); + .update(stmt, updatedCritter.getName(), updatedCritter.getId()); tx.commit(); - verifyUpdatePokemon(dbClient, result, updatedPokemon); + verifyUpdateCritter(dbClient, result, updatedCritter); } } diff --git a/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/InitUtils.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/InitUtils.java new file mode 100644 index 00000000000..ccabd50acb6 --- /dev/null +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/InitUtils.java @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2023, 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.dbclient.tests.common.utils; + +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.sql.DriverManager; +import java.util.Map; + +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbExecute; +import io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.common.model.Kind; + +/** + * Test initialization utilities. + */ +public class InitUtils { + + private static final Logger LOGGER = System.getLogger(InitUtils.class.getName()); + + /** + * Check code to be executed periodically while waiting for database container to come up. + */ + @FunctionalInterface + public interface StartCheck { + /** + * Check whether database is already up and accepts connections. + * + * @throws Exception when check failed + */ + void check() throws Exception; + } + + /** + * Wait for database container to come up. + * + * @param check container check to be executed periodically until no exception is thrown + * @param timeout container start up timeout in seconds + */ + @SuppressWarnings("SleepWhileInLoop") + public static void waitForStart(StartCheck check, int timeout) { + LOGGER.log(Level.TRACE, "Waiting for database server to come up"); + long endTm = 1000L * timeout + System.currentTimeMillis(); + while (true) { + try { + check.check(); + break; + } catch (Throwable th) { + if (System.currentTimeMillis() > endTm) { + throw new IllegalStateException("Database startup failed!", th); + } + LOGGER.log(Level.DEBUG, () -> String.format("Exception: %s", th.getMessage()), th); + try { + Thread.sleep(1000); + } catch (InterruptedException ignored) { + } + } + } + } + + /** + * Wait for database container to come up. + * With single check timeout modified. + * + * @param check container check to be executed periodically until no exception is thrown + * @param timeout container start up timeout in seconds + * @param checkTimeout single check timeout in seconds + */ + public static void waitForStart(StartCheck check, int timeout, int checkTimeout) { + int currentLoginTimeout = DriverManager.getLoginTimeout(); + DriverManager.setLoginTimeout(checkTimeout); + InitUtils.waitForStart(check, timeout); + DriverManager.setLoginTimeout(currentLoginTimeout); + } + + /** + * Initialize database schema. + * + * @param dbClient database client instance + */ + public static void initSchema(DbClient dbClient) { + DbExecute exec = dbClient.execute(); + exec.namedDml("create-types"); + exec.namedDml("create-pokemons"); + exec.namedDml("create-poketypes"); + } + + /** + * Initialize database data. + * + * @param dbClient database client instance + */ + public static void initData(DbClient dbClient) { + DbExecute exec = dbClient.execute(); + long count = 0; + for (Map.Entry entry : Kind.KINDS.entrySet()) { + count += exec.namedInsert("insert-type", entry.getKey(), entry.getValue().name()); + } + + for (Map.Entry entry : Critter.CRITTERS.entrySet()) { + count += exec.namedInsert("insert-pokemon", entry.getKey(), entry.getValue().getName()); + } + + for (Map.Entry entry : Critter.CRITTERS.entrySet()) { + Critter pokemon = entry.getValue(); + for (Kind type : pokemon.getTypes()) { + count += exec.namedInsert("insert-poketype", pokemon.getId(), type.id()); + } + } + LOGGER.log(System.Logger.Level.INFO, String.format("executed %s statements", count)); + } + + /** + * Destroy database data. + * + * @param dbClient database client instance + */ + public static void dropSchema(DbClient dbClient) { + DbExecute exec = dbClient.execute(); + exec.namedDml("drop-poketypes"); + exec.namedDml("drop-pokemons"); + exec.namedDml("drop-types"); + } + +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/MapperProvider.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/MapperProvider.java similarity index 74% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/MapperProvider.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/MapperProvider.java index 53dd69928f9..15e44bb8ebc 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/MapperProvider.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/MapperProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.utils; +package io.helidon.dbclient.tests.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; +import io.helidon.dbclient.tests.common.model.Critter; +import io.helidon.dbclient.tests.common.model.Critter.CritterMapper; /** * Mapper provider used in integration tests. @@ -32,8 +32,8 @@ public class MapperProvider implements DbMapperProvider { 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); + } else if (type.equals(Critter.class)) { + return Optional.of((DbMapper) CritterMapper.INSTANCE); } return Optional.empty(); } diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/RangePoJo.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/RangePoJo.java similarity index 92% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/RangePoJo.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/RangePoJo.java index 9812440fef6..32be831b257 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/RangePoJo.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/RangePoJo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.utils; +package io.helidon.dbclient.tests.common.utils; import java.util.ArrayList; import java.util.HashMap; @@ -24,7 +24,7 @@ import io.helidon.dbclient.DbRow; /** - * POJO used to define {@code Pokemon} IDs range in query statement tests. + * POJO used to define {@code Critter} IDs range in query statement tests. */ public class RangePoJo { diff --git a/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/TestConfig.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/TestConfig.java new file mode 100644 index 00000000000..79b5912d968 --- /dev/null +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/TestConfig.java @@ -0,0 +1,86 @@ +/* + * 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.dbclient.tests.common.utils; + +import java.lang.System.Logger.Level; +import java.net.URI; + +/** + * Configuration utilities. + */ +public class TestConfig { + + /** Last used id in {@code Critter} 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; + } + + /** + * Create {@link URI} from database URL. + * JDBC URL like {@code "jdbc:mysql://127.0.0.1:3306/database"} is not valid URI {@code String}. + * {@code "jdbc:"} prefix must be removed before passing this URL {@code String} to URI factory method. + * Configuration values processing utility. + * + * @param url JDBC database URL + * @return {@link URI} from database URL + */ + public static URI uriFromDbUrl(String url) { + int separator = url.indexOf(':'); // 4 + if (separator == -1) { + throw new IllegalArgumentException("Missing ':' character to separate leading jdbc prefix in database URL"); + } + if (url.length() < separator + 2) { + throw new IllegalArgumentException("Missing characters after \"jdbc:\"prefix"); + } + return URI.create(url.substring(separator + 1)); + } + + /** + * Retrieve database name from database {@link URI}. + * {@link URI} path element contains leading {@code '/'} character which must be removed before returning + * the database name. + * + * @param dbUri database {@link URI} + * @return database name from database {@link URI} + */ + public static String dbNameFromUri(URI dbUri) { + String dbPath = dbUri.getPath(); + if (dbPath.length() == 0) { + throw new IllegalArgumentException("Database name is empty"); + } + String dbName = dbPath.charAt(0) == '/' ? dbPath.substring(1, dbPath.length()) : dbPath; + if (dbName.length() == 0) { + throw new IllegalArgumentException("Database name is empty"); + } + return dbName; + } + +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/VerifyData.java b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/VerifyData.java similarity index 79% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/VerifyData.java rename to dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/VerifyData.java index 31f0c19ec71..ebce1617927 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/utils/VerifyData.java +++ b/dbclient/tests/common/src/main/java/io/helidon/dbclient/tests/common/utils/VerifyData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023 Oracle and/or its affiliates. + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.utils; +package io.helidon.dbclient.tests.common.utils; import java.lang.System.Logger.Level; import java.util.HashMap; @@ -24,9 +24,9 @@ import io.helidon.dbclient.DbClient; import io.helidon.dbclient.DbRow; -import io.helidon.tests.integration.dbclient.common.model.Pokemon; +import io.helidon.dbclient.tests.common.model.Critter; -import static io.helidon.tests.integration.dbclient.common.model.Pokemon.POKEMONS; +import static io.helidon.dbclient.tests.common.model.Critter.CRITTERS; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; @@ -49,9 +49,9 @@ private VerifyData() { * @param idMin beginning of ID range * @param idMax end of ID range */ - public static void verifyPokemonsIdRange(Stream rows, int idMin, int idMax) { + public static void verifyCrittersIdRange(Stream rows, int idMin, int idMax) { // Build Map of valid data - Map valid = range(idMin, idMax); + Map valid = range(idMin, idMax); // Compare result with valid data assertThat(rows, notNullValue()); @@ -60,7 +60,7 @@ public static void verifyPokemonsIdRange(Stream rows, int idMin, int idMa 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)); + LOGGER.log(Level.INFO, () -> String.format("Critter id=%d, name=%s", id, name)); assertThat(valid.containsKey(id), equalTo(true)); assertThat(name, equalTo(valid.get(id).getName())); } @@ -73,8 +73,9 @@ public static void verifyPokemonsIdRange(Stream rows, int idMin, int idMa * @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); + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + public static void verifyCrittersIdRange(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); @@ -89,10 +90,10 @@ public static void verifyPokemonsIdRange(Optional maybeRow, int idMin, in * @param rows database query result to verify * @param expected data to compare with */ - public static void verifyPokemon(List rows, Pokemon expected) { + public static void verifyCritter(List rows, Critter expected) { assertThat(rows, notNullValue()); assertThat(rows, hasSize(1)); - DbRow row = rows.get(0); + DbRow row = rows.getFirst(); Integer id = row.column(1).get(Integer.class); String name = row.column(2).get(String.class); assertThat(id, equalTo(expected.getId())); @@ -105,9 +106,9 @@ public static void verifyPokemon(List rows, Pokemon expected) { * @param rows database query result to verify * @param pokemon data to compare with */ - public static void verifyPokemon(Stream rows, Pokemon pokemon) { + public static void verifyCritter(Stream rows, Critter pokemon) { assertThat(rows, notNullValue()); - verifyPokemon(rows.toList(), pokemon); + verifyCritter(rows.toList(), pokemon); } /** @@ -116,7 +117,8 @@ public static void verifyPokemon(Stream rows, Pokemon pokemon) { * @param maybeRow database query result to verify * @param expected data to compare with */ - public static void verifyPokemon(Optional maybeRow, Pokemon expected) { + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + public static void verifyCritter(Optional maybeRow, Critter expected) { assertThat(maybeRow.isPresent(), equalTo(true)); DbRow row = maybeRow.get(); Integer id = row.column(1).get(Integer.class); @@ -131,7 +133,7 @@ public static void verifyPokemon(Optional maybeRow, Pokemon expected) { * @param actual database query result * @param expected data to compare with */ - public static void verifyPokemon(Pokemon actual, Pokemon expected) { + public static void verifyCritter(Critter actual, Critter expected) { assertThat(actual.getId(), equalTo(expected.getId())); assertThat(actual.getName(), equalTo(expected.getName())); } @@ -143,7 +145,7 @@ public static void verifyPokemon(Pokemon actual, Pokemon expected) { * @param result DML statement result * @param data data to compare with */ - public static void verifyInsertPokemon(DbClient dbClient, long result, Pokemon data) { + public static void verifyInsertCritter(DbClient dbClient, long result, Critter data) { assertThat(result, equalTo(1L)); Optional maybeRow = dbClient.execute() .namedGet("select-pokemon-by-id", data.getId()); @@ -163,11 +165,11 @@ public static void verifyInsertPokemon(DbClient dbClient, long result, Pokemon d * @param result DML statement result * @param data data to compare with */ - public static void verifyUpdatePokemon(DbClient dbClient, long result, Pokemon data) { + public static void verifyUpdateCritter(DbClient dbClient, long result, Critter data) { assertThat(result, equalTo(1L)); Optional maybeRow = dbClient.execute() .namedGet("select-pokemon-by-id", data.getId()); - verifyPokemon(maybeRow, data); + verifyCritter(maybeRow, data); } /** @@ -177,22 +179,23 @@ public static void verifyUpdatePokemon(DbClient dbClient, long result, Pokemon d * @param result DML statement result * @param expected data to compare with */ - public static void verifyDeletePokemon(DbClient dbClient, long result, Pokemon expected) { + public static void verifyDeleteCritter(DbClient dbClient, long result, Critter 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()) { + private static Map range(int idMin, int idMax) { + Map map = new HashMap<>(CRITTERS.size()); + for (Map.Entry entry : CRITTERS.entrySet()) { int id = entry.getKey(); - Pokemon pokemon = entry.getValue(); + Critter 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/dbclient/tests/common/src/main/java/module-info.java similarity index 59% rename from tests/integration/dbclient/common/src/main/java/module-info.java rename to dbclient/tests/common/src/main/java/module-info.java index 23fca963da9..7d2fa9b23a9 100644 --- a/tests/integration/dbclient/common/src/main/java/module-info.java +++ b/dbclient/tests/common/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2023, 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,34 +13,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** - * Helidon Database Client Integration Tests. + * Helidon Database Client Common Tests. */ -module io.helidon.tests.integration.dbclient.common { +module io.helidon.dbclient.tests.common { - requires org.junit.jupiter.api; - requires java.net.http; - requires jakarta.json; - requires hamcrest.all; + requires java.sql; requires io.helidon.common; requires io.helidon.config; requires io.helidon.dbclient; + requires io.helidon.dbclient.health; 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; + requires io.helidon.webserver.testing.junit5; - 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; + requires jakarta.json; + requires org.junit.jupiter.api; + requires hamcrest.all; - uses io.helidon.tests.integration.dbclient.common.spi.SetupProvider; + exports io.helidon.dbclient.tests.common.model; + exports io.helidon.dbclient.tests.common.tests; + exports io.helidon.dbclient.tests.common.utils; provides io.helidon.dbclient.spi.DbMapperProvider - with io.helidon.tests.integration.dbclient.common.utils.MapperProvider; + with io.helidon.dbclient.tests.common.utils.MapperProvider; + } \ No newline at end of file diff --git a/dbclient/tests/h2/pom.xml b/dbclient/tests/h2/pom.xml new file mode 100644 index 00000000000..e30fc16c700 --- /dev/null +++ b/dbclient/tests/h2/pom.xml @@ -0,0 +1,115 @@ + + + + + 4.0.0 + + + io.helidon.dbclient + helidon-dbclient-tests-project + 4.0.0-SNAPSHOT + + + helidon-dbclient-tests-h2 + Helidon Database Client H2 Tests + Database client tests with H2 + + + true + + + + + io.helidon.dbclient + helidon-dbclient-jdbc + test + + + io.helidon.dbclient + helidon-dbclient-hikari + test + + + io.helidon.dbclient + helidon-dbclient-tests-common + ${project.version} + test + + + io.helidon.tests.integration + helidon-tests-integration-junit5 + ${project.version} + test + + + io.helidon.integrations.db + h2 + test + + + com.h2database + h2 + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + org.apache.maven.plugins + maven-failsafe-plugin + + ${maven.test.redirectTestOutputToFile} + methods + 10 + + true + + + io.helidon.dbclient.tests.h2.H2Suite$*IT + + + + + + + + + test + integration-test + + integration-test + verify + + + + + + + + diff --git a/dbclient/tests/h2/src/test/java/io/helidon/dbclient/tests/h2/H2Suite.java b/dbclient/tests/h2/src/test/java/io/helidon/dbclient/tests/h2/H2Suite.java new file mode 100644 index 00000000000..6c7e6f46a11 --- /dev/null +++ b/dbclient/tests/h2/src/test/java/io/helidon/dbclient/tests/h2/H2Suite.java @@ -0,0 +1,352 @@ +/* + * Copyright (c) 2023, 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.dbclient.tests.h2; + +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.lang.reflect.Type; +import java.net.URI; +import java.nio.file.Paths; +import java.sql.DriverManager; +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.DbStatementType; +import io.helidon.dbclient.metrics.DbClientMetrics; +import io.helidon.dbclient.tests.common.utils.InitUtils; +import io.helidon.dbclient.tests.common.utils.TestConfig; +import io.helidon.tests.integration.junit5.AfterSuite; +import io.helidon.tests.integration.junit5.BeforeSuite; +import io.helidon.tests.integration.junit5.Suite; +import io.helidon.tests.integration.junit5.SuiteResolver; +import io.helidon.tests.integration.junit5.spi.SuiteProvider; + +import org.h2.tools.Server; + +/** + * Helidon Database Client Integration Tests with H2 Database {@link SuiteProvider}. + */ +public class H2Suite implements SuiteProvider, SuiteResolver { + + private static final Logger LOGGER = System.getLogger(H2Suite.class.getName()); + + private static final String CONFIG_FILE = "test.yaml"; + private static final int STARTUP_TIMEOUT = 60; + private static final int CONNECTION_CHECK_TIMEOUT = 1; + + private Server server; + private Config config; + private DbClient dbClient; + + public H2Suite() { + server = null; + config = null; + dbClient = null; + } + + @BeforeSuite + public void beforeSuite() { + config = Config.just(ConfigSources.classpath(CONFIG_FILE)); + if (config == null) { + throw new IllegalStateException(String.format("Config file %s is not available", CONFIG_FILE)); + } + start(config.get("db")); + InitUtils.waitForStart( + () -> DriverManager.getConnection(config.get("db.connection.url").as(String.class).get()), + STARTUP_TIMEOUT, + CONNECTION_CHECK_TIMEOUT); + dbClient = DbClient.builder(config.get("db")) + // 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(); + InitUtils.initSchema(dbClient); + InitUtils.initData(dbClient); + } + + @AfterSuite + public void afterSuite() { + InitUtils.dropSchema(dbClient); + stop(); + } + + @Override + public boolean supportsParameter(Type type) { + return DbClient.class.isAssignableFrom((Class) type) || Config.class.isAssignableFrom((Class) type); + } + + @Override + public Object resolveParameter(Type type) { + if (DbClient.class.isAssignableFrom((Class)type)) { + return dbClient; + } + if (Config.class.isAssignableFrom((Class) type)) { + return config; + } + throw new IllegalArgumentException(String.format("Cannot resolve parameter Type %s", type.getTypeName())); + } + + private void start(Config dbConfig) { + String url = dbConfig.get("connection.url").as(String.class).get(); + LOGGER.log(Level.TRACE, + () -> String.format("Starting H2 database %s", url)); + URI dbUri = URI.create( + dbConfig.get("connection.url").asString().get().substring("jdbc:h2:".length())); + int dbPort = dbUri.getPort(); + String dbName = dbNameFromUri(dbUri); + String password = dbConfig.get("rootpw").asString().get(); + String baseDir = Paths.get("").toAbsolutePath().resolve("target").resolve(dbName).toString(); + try { + // Starting without specific TCP port to allow server to choose one + server = Server.createTcpServer( + "-web", + "-webAllowOthers", + "-tcp", + "-tcpAllowOthers", + "-tcpAllowOthers", + "-tcpPassword", + password, + "-baseDir", + baseDir, + "-ifNotExists"); + server.start(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + String newUrl = url.replace(Integer.toString(dbPort), Integer.toString(server.getPort())); + LOGGER.log(Level.TRACE, + () -> String.format("Updated H2 database URL: %s", newUrl)); + // Update config if URL has changed + if (!url.equals(newUrl)) { + config = Config.create(ConfigSources.create(Map.of("db.connection.url", newUrl)), + ConfigSources.create(config)); + } + } + + private void stop() { + LOGGER.log(Level.TRACE, "Shutting down H2 database"); + server.stop(); + } + + private static String dbNameFromUri(URI dbUri) { + String dbNameWithParams = TestConfig.dbNameFromUri(dbUri); + return dbNameWithParams.substring(0, dbNameWithParams.indexOf(';')); + } + + @Suite(H2Suite.class) + public static class ExceptionalStmtIT extends io.helidon.dbclient.tests.common.tests.ExceptionalStmtIT { + + public ExceptionalStmtIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(H2Suite.class) + public static class FlowControlIT extends io.helidon.dbclient.tests.common.tests.FlowControlIT { + public FlowControlIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(H2Suite.class) + public static class GetStatementIT extends io.helidon.dbclient.tests.common.tests.GetStatementIT { + + public GetStatementIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(H2Suite.class) + public static class HealthCheckIT extends io.helidon.dbclient.tests.common.tests.HealthCheckIT { + + public HealthCheckIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class InterceptorIT extends io.helidon.dbclient.tests.common.tests.InterceptorIT { + + public InterceptorIT(Config config) { + super(config); + } + + } + + @Suite(H2Suite.class) + public static class MapperIT extends io.helidon.dbclient.tests.common.tests.MapperIT { + + public MapperIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(H2Suite.class) + public static class QueryStatementIT extends io.helidon.dbclient.tests.common.tests.QueryStatementIT { + + public QueryStatementIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(H2Suite.class) + public static class ServerHealthCheckIT extends io.helidon.dbclient.tests.common.tests.ServerHealthCheckIT { + + public ServerHealthCheckIT(Config config, DbClient dbClient) { + super(config, dbClient); + } + + } + + @Suite(H2Suite.class) + public static class ServerMetricsCheckIT extends io.helidon.dbclient.tests.common.tests.ServerMetricsCheckIT { + + public ServerMetricsCheckIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(H2Suite.class) + public static class SimpleDeleteIT extends io.helidon.dbclient.tests.common.tests.SimpleDeleteIT { + + public SimpleDeleteIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class SimpleDmlIT extends io.helidon.dbclient.tests.common.tests.SimpleDmlIT { + + public SimpleDmlIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class SimpleGetIT extends io.helidon.dbclient.tests.common.tests.SimpleGetIT { + + public SimpleGetIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class SimpleInsertIT extends io.helidon.dbclient.tests.common.tests.SimpleInsertIT { + + public SimpleInsertIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class SimpleQueriesIT extends io.helidon.dbclient.tests.common.tests.SimpleQueriesIT { + + public SimpleQueriesIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class SimpleUpdateIT extends io.helidon.dbclient.tests.common.tests.SimpleUpdateIT { + + public SimpleUpdateIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class StatementDmlIT extends io.helidon.dbclient.tests.common.tests.StatementDmlIT { + + public StatementDmlIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(H2Suite.class) + public static class TransactionDeleteIT extends io.helidon.dbclient.tests.common.tests.TransactionDeleteIT { + + public TransactionDeleteIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class TransactionExceptionalStmtIT extends io.helidon.dbclient.tests.common.tests.TransactionExceptionalStmtIT { + + public TransactionExceptionalStmtIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(H2Suite.class) + public static class TransactionGetIT extends io.helidon.dbclient.tests.common.tests.TransactionGetIT { + + public TransactionGetIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class TransactionInsertIT extends io.helidon.dbclient.tests.common.tests.TransactionInsertIT { + + public TransactionInsertIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class TransactionQueriesIT extends io.helidon.dbclient.tests.common.tests.TransactionQueriesIT { + + public TransactionQueriesIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(H2Suite.class) + public static class TransactionUpdateIT extends io.helidon.dbclient.tests.common.tests.TransactionUpdateIT { + + public TransactionUpdateIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + +} diff --git a/tests/integration/dbclient/app/src/main/resources/META-INF/services/io.helidon.dbclient.spi.DbMapperProvider b/dbclient/tests/h2/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider similarity index 80% rename from tests/integration/dbclient/app/src/main/resources/META-INF/services/io.helidon.dbclient.spi.DbMapperProvider rename to dbclient/tests/h2/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider index a08ca6a9e1c..901a8de9370 100644 --- a/tests/integration/dbclient/app/src/main/resources/META-INF/services/io.helidon.dbclient.spi.DbMapperProvider +++ b/dbclient/tests/h2/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider @@ -1,5 +1,5 @@ # -# Copyright (c) 2019, 2022 Oracle and/or its affiliates. +# Copyright (c) 2023, 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.dbclient.tests.h2.H2Suite diff --git a/tests/integration/dbclient/h2/src/test/resources/h2.yaml b/dbclient/tests/h2/src/test/resources/test.yaml similarity index 93% rename from tests/integration/dbclient/h2/src/test/resources/h2.yaml rename to dbclient/tests/h2/src/test/resources/test.yaml index c7845596538..2d08fc6eee5 100644 --- a/tests/integration/dbclient/h2/src/test/resources/h2.yaml +++ b/dbclient/tests/h2/src/test/resources/test.yaml @@ -1,5 +1,5 @@ # -# Copyright (c) 2019, 2023 Oracle and/or its affiliates. +# 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. @@ -15,12 +15,9 @@ # db: source: jdbc - host: "localhost" - port: 9092 - password: "password" - database: "test" + rootpw: "password" connection: - url: jdbc:h2:tcp://${db.host}:${db.port}/${db.database};DATABASE_TO_UPPER=FALSE + url: jdbc:h2:tcp://localhost:9092/test;DATABASE_TO_UPPER=FALSE health-check: type: query statement: "SELECT 0" diff --git a/dbclient/tests/mysql/pom.xml b/dbclient/tests/mysql/pom.xml new file mode 100644 index 00000000000..5d75b95d78d --- /dev/null +++ b/dbclient/tests/mysql/pom.xml @@ -0,0 +1,115 @@ + + + + + 4.0.0 + + + io.helidon.dbclient + helidon-dbclient-tests-project + 4.0.0-SNAPSHOT + + + helidon-dbclient-tests-mysql + Helidon Database Client MySQL Tests + Database client tests with MySQL + + + true + + + + + io.helidon.dbclient + helidon-dbclient-jdbc + test + + + io.helidon.dbclient + helidon-dbclient-hikari + test + + + io.helidon.dbclient + helidon-dbclient-tests-common + ${project.version} + test + + + io.helidon.tests.integration + helidon-tests-integration-junit5 + ${project.version} + test + + + io.helidon.integrations.db + helidon-integrations-db-mysql + test + + + com.mysql + mysql-connector-j + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + org.apache.maven.plugins + maven-failsafe-plugin + + ${maven.test.redirectTestOutputToFile} + methods + 10 + + true + + + io.helidon.dbclient.tests.mysql.MySqlSuite$*IT + + + + + + + + + test + integration-test + + integration-test + verify + + + + + + + + diff --git a/dbclient/tests/mysql/src/test/java/io/helidon/dbclient/tests/mysql/MySqlSuite.java b/dbclient/tests/mysql/src/test/java/io/helidon/dbclient/tests/mysql/MySqlSuite.java new file mode 100644 index 00000000000..1a0588ffd08 --- /dev/null +++ b/dbclient/tests/mysql/src/test/java/io/helidon/dbclient/tests/mysql/MySqlSuite.java @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2023, 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.dbclient.tests.mysql; + +import java.sql.DriverManager; +import java.util.HashMap; +import java.util.Map; + +import io.helidon.config.Config; +import io.helidon.config.ConfigSources; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbStatementType; +import io.helidon.dbclient.metrics.DbClientMetrics; +import io.helidon.dbclient.tests.common.utils.InitUtils; +import io.helidon.tests.integration.junit5.AfterSuite; +import io.helidon.tests.integration.junit5.BeforeSuite; +import io.helidon.tests.integration.junit5.ConfigUpdate; +import io.helidon.tests.integration.junit5.ContainerInfo; +import io.helidon.tests.integration.junit5.ContainerTest; +import io.helidon.tests.integration.junit5.DatabaseContainer; +import io.helidon.tests.integration.junit5.DatabaseContainerConfig; +import io.helidon.tests.integration.junit5.DbClientTest; +import io.helidon.tests.integration.junit5.MySqlContainer; +import io.helidon.tests.integration.junit5.SetUpContainer; +import io.helidon.tests.integration.junit5.SetUpDbClient; +import io.helidon.tests.integration.junit5.Suite; +import io.helidon.tests.integration.junit5.TestConfig; +import io.helidon.tests.integration.junit5.spi.SuiteProvider; + +@TestConfig +@DbClientTest +@ContainerTest(provider = MySqlContainer.class, image = "mysql:8") +public class MySqlSuite implements SuiteProvider { + + static final String DB_NODE = "db"; + private static final int STARTUP_TIMEOUT = 60; + private static final int CONNECTION_CHECK_TIMEOUT = 1; + + @SetUpContainer + public void setupContainer(Config config, DatabaseContainerConfig.Builder dbConfigBuilder) { + config.get(DB_NODE + ".connection").asNode().ifPresent(dbConfigBuilder::dbClient); + } + + @SetUpDbClient + public void setupDbClient(Config config, ConfigUpdate update, ContainerInfo info, DbClient.Builder builder) { + // Merges ContainerInfo into DbClient config + Map updatedNodes = new HashMap<>(1); + config.get(DB_NODE + ".connection.url").as(String.class).ifPresent(value -> updatedNodes.put( + DB_NODE + ".connection.url", + DatabaseContainer.replacePortInUrl( + value, + info.portMappings().get(info.config().exposedPorts()[0])))); + Config containerConfig = Config.create(ConfigSources.create(updatedNodes), ConfigSources.create(config)); + // This replaces config stored by @TestConfig provider + update.config(containerConfig); + builder.config(containerConfig.get(DB_NODE)); + builder.addService(DbClientMetrics.counter() + .statementNames("select-pokemons", "insert-pokemon")) + .addService(DbClientMetrics.timer() + .statementTypes(DbStatementType.INSERT)); + } + + // Value of config was updated in DbClient config hook and contains valid connection properties + @BeforeSuite + public void beforeSuite(DbClient dbClient, Config config) { + InitUtils.waitForStart( + () -> DriverManager.getConnection(config.get("db.connection.url").asString().get(), + config.get("db.connection.username").asString().get(), + config.get("db.connection.password").asString().get()), + STARTUP_TIMEOUT, + CONNECTION_CHECK_TIMEOUT); + InitUtils.initSchema(dbClient); + InitUtils.initData(dbClient); + } + + @AfterSuite + public void afterSuite(DbClient dbClient) { + InitUtils.dropSchema(dbClient); + } + + @Suite(MySqlSuite.class) + public static class ExceptionalStmtIT extends io.helidon.dbclient.tests.common.tests.ExceptionalStmtIT { + + public ExceptionalStmtIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class FlowControlIT extends io.helidon.dbclient.tests.common.tests.FlowControlIT { + + public FlowControlIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class GetStatementIT extends io.helidon.dbclient.tests.common.tests.GetStatementIT { + + public GetStatementIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class HealthCheckIT extends io.helidon.dbclient.tests.common.tests.HealthCheckIT { + + public HealthCheckIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class InterceptorIT extends io.helidon.dbclient.tests.common.tests.InterceptorIT { + + public InterceptorIT(Config config) { + super(config); + } + + } + + @Suite(MySqlSuite.class) + public static class MapperIT extends io.helidon.dbclient.tests.common.tests.MapperIT { + + public MapperIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class QueryStatementIT extends io.helidon.dbclient.tests.common.tests.QueryStatementIT { + + public QueryStatementIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class ServerHealthCheckIT extends io.helidon.dbclient.tests.common.tests.ServerHealthCheckIT { + + public ServerHealthCheckIT(Config config, DbClient dbClient) { + super(config, dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class ServerMetricsCheckIT extends io.helidon.dbclient.tests.common.tests.ServerMetricsCheckIT { + + public ServerMetricsCheckIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleDeleteIT extends io.helidon.dbclient.tests.common.tests.SimpleDeleteIT { + + public SimpleDeleteIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleDmlIT extends io.helidon.dbclient.tests.common.tests.SimpleDmlIT { + + public SimpleDmlIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleGetIT extends io.helidon.dbclient.tests.common.tests.SimpleGetIT { + + public SimpleGetIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleInsertIT extends io.helidon.dbclient.tests.common.tests.SimpleInsertIT { + + public SimpleInsertIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleQueriesIT extends io.helidon.dbclient.tests.common.tests.SimpleQueriesIT { + + public SimpleQueriesIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleUpdateIT extends io.helidon.dbclient.tests.common.tests.SimpleUpdateIT { + + public SimpleUpdateIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class StatementDmlIT extends io.helidon.dbclient.tests.common.tests.StatementDmlIT { + + public StatementDmlIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionDeleteIT extends io.helidon.dbclient.tests.common.tests.TransactionDeleteIT { + + public TransactionDeleteIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionExceptionalStmtIT extends io.helidon.dbclient.tests.common.tests.TransactionExceptionalStmtIT { + + public TransactionExceptionalStmtIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionGetIT extends io.helidon.dbclient.tests.common.tests.TransactionGetIT { + + public TransactionGetIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionInsertIT extends io.helidon.dbclient.tests.common.tests.TransactionInsertIT { + + public TransactionInsertIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionQueriesIT extends io.helidon.dbclient.tests.common.tests.TransactionQueriesIT { + + public TransactionQueriesIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionUpdateIT extends io.helidon.dbclient.tests.common.tests.TransactionUpdateIT { + + public TransactionUpdateIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + +} diff --git a/tests/integration/dbclient/app/src/test/resources/logging.properties b/dbclient/tests/mysql/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider similarity index 50% rename from tests/integration/dbclient/app/src/test/resources/logging.properties rename to dbclient/tests/mysql/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider index e1b27ef2055..255c5f7216f 100644 --- a/tests/integration/dbclient/app/src/test/resources/logging.properties +++ b/dbclient/tests/mysql/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider @@ -1,5 +1,5 @@ # -# Copyright (c) 2020, 2023 Oracle and/or its affiliates. +# Copyright (c) 2023, 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,12 +14,4 @@ # 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 +io.helidon.dbclient.tests.mysql.MySqlSuite diff --git a/tests/integration/dbclient/app/src/main/resources/h2.yaml b/dbclient/tests/mysql/src/test/resources/test.yaml similarity index 87% rename from tests/integration/dbclient/app/src/main/resources/h2.yaml rename to dbclient/tests/mysql/src/test/resources/test.yaml index 9961aa9db56..7b26e77a204 100644 --- a/tests/integration/dbclient/app/src/main/resources/h2.yaml +++ b/dbclient/tests/mysql/src/test/resources/test.yaml @@ -1,5 +1,5 @@ # -# Copyright (c) 2022, 2023 Oracle and/or its affiliates. +# 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. @@ -15,19 +15,21 @@ # db: + container: mysql:8.0 source: jdbc connection: - url: ${db.url} - username: ${db.user} - password: ${db.password} + url: jdbc:mysql://127.0.0.1:3306/pokemon?useSSL=false&allowPublicKeyRetrieval=true + username: user + password: p4ssw0rd 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, id_type INTEGER NOT NULL REFERENCES Types(id))" + 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" @@ -37,8 +39,6 @@ db: 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" diff --git a/dbclient/tests/pgsql/pom.xml b/dbclient/tests/pgsql/pom.xml new file mode 100644 index 00000000000..5de862f124b --- /dev/null +++ b/dbclient/tests/pgsql/pom.xml @@ -0,0 +1,115 @@ + + + + + 4.0.0 + + + io.helidon.dbclient + helidon-dbclient-tests-project + 4.0.0-SNAPSHOT + + + helidon-dbclient-tests-pgsql + Helidon Database Client PostgreSQL Tests + Database client tests with PostgreSQL + + + true + + + + + io.helidon.dbclient + helidon-dbclient-jdbc + test + + + io.helidon.dbclient + helidon-dbclient-hikari + test + + + io.helidon.dbclient + helidon-dbclient-tests-common + ${project.version} + test + + + io.helidon.tests.integration + helidon-tests-integration-junit5 + ${project.version} + test + + + io.helidon.integrations.db + helidon-integrations-db-pgsql + test + + + org.postgresql + postgresql + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + org.apache.maven.plugins + maven-failsafe-plugin + + ${maven.test.redirectTestOutputToFile} + methods + 10 + + true + + + io.helidon.dbclient.tests.pgsql.PgSqlSuite$*IT + + + + + + + + + test + integration-test + + integration-test + verify + + + + + + + + diff --git a/dbclient/tests/pgsql/src/test/java/io/helidon/dbclient/tests/pgsql/PgSqlSuite.java b/dbclient/tests/pgsql/src/test/java/io/helidon/dbclient/tests/pgsql/PgSqlSuite.java new file mode 100644 index 00000000000..458e7fcaf6f --- /dev/null +++ b/dbclient/tests/pgsql/src/test/java/io/helidon/dbclient/tests/pgsql/PgSqlSuite.java @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2023, 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.dbclient.tests.pgsql; + +import java.sql.DriverManager; +import java.util.HashMap; +import java.util.Map; + +import io.helidon.config.Config; +import io.helidon.config.ConfigSources; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbStatementType; +import io.helidon.dbclient.metrics.DbClientMetrics; +import io.helidon.dbclient.tests.common.utils.InitUtils; +import io.helidon.tests.integration.junit5.AfterSuite; +import io.helidon.tests.integration.junit5.BeforeSuite; +import io.helidon.tests.integration.junit5.ConfigUpdate; +import io.helidon.tests.integration.junit5.ContainerInfo; +import io.helidon.tests.integration.junit5.ContainerTest; +import io.helidon.tests.integration.junit5.DatabaseContainer; +import io.helidon.tests.integration.junit5.DatabaseContainerConfig; +import io.helidon.tests.integration.junit5.DbClientTest; +import io.helidon.tests.integration.junit5.PgSqlContainer; +import io.helidon.tests.integration.junit5.SetUpContainer; +import io.helidon.tests.integration.junit5.SetUpDbClient; +import io.helidon.tests.integration.junit5.Suite; +import io.helidon.tests.integration.junit5.TestConfig; +import io.helidon.tests.integration.junit5.spi.SuiteProvider; + +@TestConfig +@DbClientTest +@ContainerTest(provider = PgSqlContainer.class, image = "postgres:16.0") +public class PgSqlSuite implements SuiteProvider { + + static final String DB_NODE = "db"; + private static final int STARTUP_TIMEOUT = 60; + private static final int CONNECTION_CHECK_TIMEOUT = 1; + + @SetUpContainer + public void setupContainer(Config config, DatabaseContainerConfig.Builder dbConfigBuilder) { + config.get(DB_NODE + ".connection").asNode().ifPresent(dbConfigBuilder::dbClient); + } + + @SetUpDbClient + public void setupDbClient(Config config, ConfigUpdate update, ContainerInfo info, DbClient.Builder builder) { + // Merges ContainerInfo into DbClient config + Map updatedNodes = new HashMap<>(1); + config.get(DB_NODE + ".connection.url").as(String.class).ifPresent(value -> updatedNodes.put( + DB_NODE + ".connection.url", + DatabaseContainer.replacePortInUrl( + value, + info.portMappings().get(info.config().exposedPorts()[0])))); + Config containerConfig = Config.create(ConfigSources.create(updatedNodes), ConfigSources.create(config)); + // This replaces config stored by @TestConfig provider + update.config(containerConfig); + builder.config(containerConfig.get(DB_NODE)); + builder.addService(DbClientMetrics.counter() + .statementNames("select-pokemons", "insert-pokemon")) + .addService(DbClientMetrics.timer() + .statementTypes(DbStatementType.INSERT)); + } + + // Value of config was updated in DbClient config hook and contains valid connection properties + @BeforeSuite + public void beforeSuite(DbClient dbClient, Config config) { + InitUtils.waitForStart( + () -> DriverManager.getConnection(config.get("db.connection.url").asString().get(), + config.get("db.connection.username").asString().get(), + config.get("db.connection.password").asString().get()), + STARTUP_TIMEOUT, + CONNECTION_CHECK_TIMEOUT); + InitUtils.initSchema(dbClient); + InitUtils.initData(dbClient); + } + + @AfterSuite + public void afterSuite(DbClient dbClient) { + InitUtils.dropSchema(dbClient); + } + + @Suite(PgSqlSuite.class) + public static class ExceptionalStmtIT extends io.helidon.dbclient.tests.common.tests.ExceptionalStmtIT { + + public ExceptionalStmtIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class FlowControlIT extends io.helidon.dbclient.tests.common.tests.FlowControlIT { + + public FlowControlIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class GetStatementIT extends io.helidon.dbclient.tests.common.tests.GetStatementIT { + + public GetStatementIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class HealthCheckIT extends io.helidon.dbclient.tests.common.tests.HealthCheckIT { + + public HealthCheckIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class InterceptorIT extends io.helidon.dbclient.tests.common.tests.InterceptorIT { + + public InterceptorIT(Config config) { + super(config); + } + + } + + @Suite(PgSqlSuite.class) + public static class MapperIT extends io.helidon.dbclient.tests.common.tests.MapperIT { + + public MapperIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class QueryStatementIT extends io.helidon.dbclient.tests.common.tests.QueryStatementIT { + + public QueryStatementIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class ServerHealthCheckIT extends io.helidon.dbclient.tests.common.tests.ServerHealthCheckIT { + + public ServerHealthCheckIT(Config config, DbClient dbClient) { + super(config, dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class ServerMetricsCheckIT extends io.helidon.dbclient.tests.common.tests.ServerMetricsCheckIT { + + public ServerMetricsCheckIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleDeleteIT extends io.helidon.dbclient.tests.common.tests.SimpleDeleteIT { + + public SimpleDeleteIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleDmlIT extends io.helidon.dbclient.tests.common.tests.SimpleDmlIT { + + public SimpleDmlIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleGetIT extends io.helidon.dbclient.tests.common.tests.SimpleGetIT { + + public SimpleGetIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleInsertIT extends io.helidon.dbclient.tests.common.tests.SimpleInsertIT { + + public SimpleInsertIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleQueriesIT extends io.helidon.dbclient.tests.common.tests.SimpleQueriesIT { + + public SimpleQueriesIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleUpdateIT extends io.helidon.dbclient.tests.common.tests.SimpleUpdateIT { + + public SimpleUpdateIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class StatementDmlIT extends io.helidon.dbclient.tests.common.tests.StatementDmlIT { + + public StatementDmlIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionDeleteIT extends io.helidon.dbclient.tests.common.tests.TransactionDeleteIT { + + public TransactionDeleteIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionExceptionalStmtIT extends io.helidon.dbclient.tests.common.tests.TransactionExceptionalStmtIT { + + public TransactionExceptionalStmtIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionGetIT extends io.helidon.dbclient.tests.common.tests.TransactionGetIT { + + public TransactionGetIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionInsertIT extends io.helidon.dbclient.tests.common.tests.TransactionInsertIT { + + public TransactionInsertIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionQueriesIT extends io.helidon.dbclient.tests.common.tests.TransactionQueriesIT { + + public TransactionQueriesIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionUpdateIT extends io.helidon.dbclient.tests.common.tests.TransactionUpdateIT { + + public TransactionUpdateIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + +} diff --git a/dbclient/tests/pgsql/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider b/dbclient/tests/pgsql/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider new file mode 100644 index 00000000000..a4da521c877 --- /dev/null +++ b/dbclient/tests/pgsql/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider @@ -0,0 +1,17 @@ +# +# Copyright (c) 2023, 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. +# + +io.helidon.dbclient.tests.pgsql.PgSqlSuite diff --git a/tests/integration/dbclient/app/src/main/resources/pgsql.yaml b/dbclient/tests/pgsql/src/test/resources/test.yaml similarity index 86% rename from tests/integration/dbclient/app/src/main/resources/pgsql.yaml rename to dbclient/tests/pgsql/src/test/resources/test.yaml index 7f66eceac99..cda873339a9 100644 --- a/tests/integration/dbclient/app/src/main/resources/pgsql.yaml +++ b/dbclient/tests/pgsql/src/test/resources/test.yaml @@ -1,5 +1,5 @@ # -# Copyright (c) 2021, 2023 Oracle and/or its affiliates. +# 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. @@ -15,19 +15,21 @@ # db: + container: postgres:16.0 source: jdbc connection: - url: ${db.url} - username: ${db.user} - password: ${db.password} + url: jdbc:postgresql://127.0.0.1:5432/pokemon + username: user + password: p4ssw0rd 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, id_type INTEGER NOT NULL REFERENCES Types(id))" + 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" @@ -37,8 +39,6 @@ db: 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" @@ -58,4 +58,4 @@ db: select-pokemons-error-arg: "SELECT id, name FROM Pokemons WHERE id > :id AND name = ?" test: - ping-dml: false + ping-dml: false diff --git a/dbclient/tests/pom.xml b/dbclient/tests/pom.xml new file mode 100644 index 00000000000..25dcf8d5a0b --- /dev/null +++ b/dbclient/tests/pom.xml @@ -0,0 +1,50 @@ + + + + + 4.0.0 + + + io.helidon.dbclient + helidon-dbclient-project + 4.0.0-SNAPSHOT + + + helidon-dbclient-tests-project + Helidon Database Client Tests Project + pom + + + common + h2 + + + + + testcontainers + + mysql + pgsql + + + + + diff --git a/dependencies/pom.xml b/dependencies/pom.xml index e7af1a00b66..e2d753bef71 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -153,7 +153,7 @@ 2.0.9 3.3.4 2.0 - 1.19.3 + 1.19.6 1.4.2 2.1.5 5.0.SP3 diff --git a/tests/integration/dbclient/app/pom.xml b/tests/integration/dbclient/app/pom.xml deleted file mode 100644 index e8eebda21bf..00000000000 --- a/tests/integration/dbclient/app/pom.xml +++ /dev/null @@ -1,265 +0,0 @@ - - - - 4.0.0 - - io.helidon.applications - helidon-se - 4.0.0-SNAPSHOT - ../../../../applications/se/pom.xml - - io.helidon.tests.integration.dbclient - helidon-tests-integration-dbclient-app - 4.0.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/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/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/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 deleted file mode 100644 index 2305475ddbe..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Pokemon.java +++ /dev/null @@ -1,240 +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.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. - */ -@SuppressWarnings("SpellCheckingInspection") -public class Pokemon { - - /** - * {@code Pokemon} POJO mapper. - */ - 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(); - } - -} 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 deleted file mode 100644 index 45b938455c1..00000000000 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/model/Type.java +++ /dev/null @@ -1,67 +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.HashMap; -import java.util.Map; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; - -/** - * {@code Pokemon} type POJO. - */ -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/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/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/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/h2/pom.xml b/tests/integration/dbclient/h2/pom.xml deleted file mode 100644 index 4e185b00980..00000000000 --- a/tests/integration/dbclient/h2/pom.xml +++ /dev/null @@ -1,171 +0,0 @@ - - - - - 4.0.0 - - io.helidon.tests.integration.dbclient - helidon-tests-integration-dbclient-project - 4.0.0-SNAPSHOT - ../pom.xml - - helidon-tests-integration-dbclient-h2 - Helidon Tests Integration Database Client H2 - - - true - - - - - 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 - - - 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 - - - - - 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 - - - - - - - - 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/tests/integration/dbclient/mongodb/pom.xml b/tests/integration/dbclient/mongodb/pom.xml index ef4a71c4596..30fb7fc915c 100644 --- a/tests/integration/dbclient/mongodb/pom.xml +++ b/tests/integration/dbclient/mongodb/pom.xml @@ -1,6 +1,6 @@ + + + 4.0.0 + + io.helidon.tests.integration.dbclient + helidon-tests-integration-dbclient-project + 4.0.0-SNAPSHOT + ../pom.xml + + helidon-tests-integration-dbclient-mysql + Helidon Tests Integration Database Client MySQL + + + true + + + + + io.helidon.tests.integration.dbclient + helidon-tests-integration-dbclient-common + ${project.version} + + + io.helidon.tests.integration + helidon-tests-integration-junit5 + ${project.version} + + + io.helidon.integrations.db + helidon-integrations-db-mysql + ${project.version} + + + com.mysql + mysql-connector-j + test + + + 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.platform + junit-platform-launcher + + + org.junit.jupiter + junit-jupiter-engine + + + org.junit.jupiter + junit-jupiter-api + test + + + org.hamcrest + hamcrest-all + test + + + org.testcontainers + mysql + + + org.testcontainers + jdbc + + + org.testcontainers + testcontainers + + + + + + + src/test/resources + true + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + org.apache.maven.plugins + maven-failsafe-plugin + + ${maven.test.redirectTestOutputToFile} + methods + 10 + + true + + + + io.helidon.tests.integration.dbclient.mysql.MySqlSuiteWithAnnotations$*IT + + + + + + + + + test + integration-test + + integration-test + verify + + + + + + + + diff --git a/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySqlSuite.java b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySqlSuite.java new file mode 100644 index 00000000000..9c276b8a989 --- /dev/null +++ b/tests/integration/dbclient/mysql/src/test/java/io/helidon/tests/integration/dbclient/mysql/MySqlSuite.java @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2023, 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.lang.reflect.Type; +import java.net.URI; +import java.net.URISyntaxException; +import java.sql.DriverManager; +import java.util.Map; + +import io.helidon.config.Config; +import io.helidon.config.ConfigSources; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbStatementType; +import io.helidon.dbclient.metrics.DbClientMetrics; +import io.helidon.tests.integration.dbclient.common.utils.InitUtils; +import io.helidon.tests.integration.junit5.AfterSuite; +import io.helidon.tests.integration.junit5.BeforeSuite; +import io.helidon.tests.integration.junit5.ConfigUtils; +import io.helidon.tests.integration.junit5.ContainerConfig; +import io.helidon.tests.integration.junit5.Suite; +import io.helidon.tests.integration.junit5.SuiteResolver; +import io.helidon.tests.integration.junit5.spi.SuiteProvider; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.utility.DockerImageName; + +public class MySqlSuite implements SuiteProvider, SuiteResolver { + + private static final System.Logger LOGGER = System.getLogger(MySqlSuite.class.getName()); + + private static final String CONFIG_FILE = "test.yaml"; + private static final int STARTUP_TIMEOUT = 60; + private static final int CONNECTION_CHECK_TIMEOUT = 1; + + private Config config; + private GenericContainer container; + private DbClient dbClient; + + public MySqlSuite() { + config = null; + container = null; + dbClient = null; + } + + @BeforeSuite + public void beforeSuite() { + config = Config.just(ConfigSources.classpath(CONFIG_FILE)); + // Build MySQL container configuration from config or use default values as fallback + URI uri = ConfigUtils.uriFromDbUrl( + config.get("db.connection.url") + .asString() + .orElse("jdbc:mysql://127.0.0.1:3306/pokemon?useSSL=false&allowPublicKeyRetrieval=true")); + ContainerConfig containerConfig = ContainerConfig.builder() + .image(config.get("db.container").asString().orElse("mysql:latest")) + .addEnvironment(Map.of( + "MYSQL_ROOT_PASSWORD", config.get("db.rootpw").asString().orElse("R00t_P4ssw0rd"), + "MYSQL_USER", config.get("db.connection.username").asString().orElse("user"), + "MYSQL_PASSWORD", config.get("db.connection.password").asString().orElse("p4ssw0rd"), + "MYSQL_DATABASE", ConfigUtils.dbNameFromUri(uri))) + .exposedPorts(new int[] {uri.getPort() >=0 ? uri.getPort() : 3306}) + .build(); + // Start MySQL container + container = new GenericContainer<>(DockerImageName.parse(containerConfig.image())); + containerConfig.environment().forEach(container::withEnv); + container.addExposedPorts(containerConfig.exposedPorts()); + LOGGER.log(System.Logger.Level.TRACE, + () -> String.format("Starting MySQL database from image %s", containerConfig.image())); + container.start(); + // Update config with current MySQL container configuration + int dbPort = container.getMappedPort(containerConfig.exposedPorts()[0]); + try { + URI newUri = new URI("mysql", + null, + uri.getHost(), + dbPort, + uri.getPath(), + uri.getQuery(), + uri.getFragment()); + config = Config.create( + ConfigSources.create( + Map.of( + "db.container", containerConfig.image(), + "db.rootpw", containerConfig.environment().get("MYSQL_ROOT_PASSWORD"), + "db.connection.username", containerConfig.environment().get("MYSQL_USER"), + "db.connection.password", containerConfig.environment().get("MYSQL_PASSWORD"), + "db.connection.url", "jdbc:" + newUri.toString())), + ConfigSources.create(config)); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + // Wait for MySQL database to start accepting JDBC connections + InitUtils.waitForStart( + () -> DriverManager.getConnection(config.get("db.connection.url").asString().get(), + config.get("db.connection.username").asString().get(), + config.get("db.connection.password").asString().get()), + STARTUP_TIMEOUT, + CONNECTION_CHECK_TIMEOUT); + // Create DbClient from updated configuration + dbClient = DbClient.builder(config.get("db")) + .addService(DbClientMetrics.counter() + .statementNames("select-pokemons", "insert-pokemon")) + .addService(DbClientMetrics.timer() + .statementTypes(DbStatementType.INSERT)) + .build(); + // Initialize the database + InitUtils.initSchema(dbClient); + InitUtils.initData(dbClient); + } + + @AfterSuite + public void afterSuite(DbClient dbClient) { + // Clean up the database + InitUtils.dropSchema(dbClient); + LOGGER.log(System.Logger.Level.TRACE, "Stopping MySQL database"); + // Stop MySQL container + container.stop(); + } + + @Override + public boolean supportsParameter(Type type) { + return Config.class.isAssignableFrom((Class) type) + || DbClient.class.isAssignableFrom((Class) type); + } + + @Override + public Object resolveParameter(Type type) { + if (Config.class.isAssignableFrom((Class) type)) { + return config; + } else if (DbClient.class.isAssignableFrom((Class) type)) { + return dbClient; + } + throw new IllegalArgumentException(String.format("Cannot resolve parameter Type %s", type.getTypeName())); + } + + @Suite(MySqlSuite.class) + public static class ExceptionalStmtIT extends io.helidon.tests.integration.dbclient.common.tests.ExceptionalStmtIT { + + public ExceptionalStmtIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class FlowControlIT extends io.helidon.tests.integration.dbclient.common.tests.FlowControlIT { + public FlowControlIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class GetStatementIT extends io.helidon.tests.integration.dbclient.common.tests.GetStatementIT { + + public GetStatementIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class HealthCheckIT extends io.helidon.tests.integration.dbclient.common.tests.HealthCheckIT { + + public HealthCheckIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class InterceptorIT extends io.helidon.tests.integration.dbclient.common.tests.InterceptorIT { + + public InterceptorIT(Config config) { + super(config); + } + + } + + @Suite(MySqlSuite.class) + public static class MapperIT extends io.helidon.tests.integration.dbclient.common.tests.MapperIT { + + public MapperIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class QueryStatementIT extends io.helidon.tests.integration.dbclient.common.tests.QueryStatementIT { + + public QueryStatementIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class ServerHealthCheckIT extends io.helidon.tests.integration.dbclient.common.tests.ServerHealthCheckIT { + + public ServerHealthCheckIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class ServerMetricsCheckIT extends io.helidon.tests.integration.dbclient.common.tests.ServerMetricsCheckIT { + + public ServerMetricsCheckIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleDeleteIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleDeleteIT { + + public SimpleDeleteIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleDmlIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleDmlIT { + + public SimpleDmlIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleGetIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleGetIT { + + public SimpleGetIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleInsertIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleInsertIT { + + public SimpleInsertIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleQueriesIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleQueriesIT { + + public SimpleQueriesIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class SimpleUpdateIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleUpdateIT { + + public SimpleUpdateIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class StatementDmlIT extends io.helidon.tests.integration.dbclient.common.tests.StatementDmlIT { + + public StatementDmlIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionDeleteIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionDeleteIT { + + public TransactionDeleteIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionExceptionalStmtIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionExceptionalStmtIT { + + public TransactionExceptionalStmtIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionGetIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionGetIT { + + public TransactionGetIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionInsertIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionInsertIT { + + public TransactionInsertIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionQueriesIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionQueriesIT { + + public TransactionQueriesIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(MySqlSuite.class) + public static class TransactionUpdateIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionUpdateIT { + + public TransactionUpdateIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + +} diff --git a/tests/integration/dbclient/pgsql/pom.xml b/tests/integration/dbclient/pgsql/pom.xml new file mode 100644 index 00000000000..de200056e89 --- /dev/null +++ b/tests/integration/dbclient/pgsql/pom.xml @@ -0,0 +1,163 @@ + + + + + 4.0.0 + + io.helidon.tests.integration.dbclient + helidon-tests-integration-dbclient-project + 4.0.0-SNAPSHOT + ../pom.xml + + helidon-tests-integration-dbclient-pgsql + Helidon Tests Integration Database Client PostgreSQL + + + true + + + + + io.helidon.tests.integration.dbclient + helidon-tests-integration-dbclient-common + ${project.version} + + + io.helidon.tests.integration + helidon-tests-integration-junit5 + ${project.version} + + + io.helidon.integrations.db + helidon-integrations-db-pgsql + ${project.version} + + + org.postgresql + postgresql + test + + + 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.platform + junit-platform-launcher + + + org.junit.jupiter + junit-jupiter-engine + + + org.junit.jupiter + junit-jupiter-api + test + + + org.hamcrest + hamcrest-all + test + + + org.testcontainers + jdbc + + + org.testcontainers + testcontainers + + + + + + + src/test/resources + true + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + org.apache.maven.plugins + maven-failsafe-plugin + + ${maven.test.redirectTestOutputToFile} + methods + 10 + + true + + + + io.helidon.tests.integration.dbclient.pgsql.PgSqlSuiteWithAnnotations$*IT + + + + + + + + + test + integration-test + + integration-test + verify + + + + + + + + diff --git a/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PgSqlSuite.java b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PgSqlSuite.java new file mode 100644 index 00000000000..8ccd8316c48 --- /dev/null +++ b/tests/integration/dbclient/pgsql/src/test/java/io/helidon/tests/integration/dbclient/pgsql/PgSqlSuite.java @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2023, 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.lang.reflect.Type; +import java.net.URI; +import java.net.URISyntaxException; +import java.sql.DriverManager; +import java.util.Map; + +import io.helidon.config.Config; +import io.helidon.config.ConfigSources; +import io.helidon.dbclient.DbClient; +import io.helidon.dbclient.DbStatementType; +import io.helidon.dbclient.metrics.DbClientMetrics; +import io.helidon.tests.integration.dbclient.common.utils.InitUtils; +import io.helidon.tests.integration.junit5.AfterSuite; +import io.helidon.tests.integration.junit5.BeforeSuite; +import io.helidon.tests.integration.junit5.ConfigUtils; +import io.helidon.tests.integration.junit5.ContainerConfig; +import io.helidon.tests.integration.junit5.Suite; +import io.helidon.tests.integration.junit5.SuiteResolver; +import io.helidon.tests.integration.junit5.spi.SuiteProvider; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.utility.DockerImageName; + +public class PgSqlSuite implements SuiteProvider, SuiteResolver { + private static final System.Logger LOGGER = System.getLogger(PgSqlSuite.class.getName()); + + private static final String CONFIG_FILE = "test.yaml"; + private static final int STARTUP_TIMEOUT = 60; + private static final int CONNECTION_CHECK_TIMEOUT = 1; + + private Config config; + private GenericContainer container; + private DbClient dbClient; + + public PgSqlSuite() { + config = null; + container = null; + dbClient = null; + } + + @BeforeSuite + public void beforeSuite() { + config = Config.just(ConfigSources.classpath(CONFIG_FILE)); + // Build MySQL container configuration from config or use default values as fallback + URI uri = ConfigUtils.uriFromDbUrl( + config.get("db.connection.url") + .asString() + .orElse("jdbc:postgresql://127.0.0.1:5432/pokemon")); + ContainerConfig containerConfig = ContainerConfig.builder() + .image(config.get("db.container").asString().orElse("postgres:latest")) + .addEnvironment(Map.of( + "POSTGRES_USER", config.get("db.connection.username").asString().orElse("user"), + "POSTGRES_PASSWORD", config.get("db.connection.password").asString().orElse("p4ssw0rd"), + "POSTGRES_DB", ConfigUtils.dbNameFromUri(uri))) + .exposedPorts(new int[] {uri.getPort() >=0 ? uri.getPort() : 5432}) + .build(); + // Start MySQL container + container = new GenericContainer<>(DockerImageName.parse(containerConfig.image())); + containerConfig.environment().forEach(container::withEnv); + container.addExposedPorts(containerConfig.exposedPorts()); + LOGGER.log(System.Logger.Level.TRACE, + () -> String.format("Starting PostgreSQL database from image %s", containerConfig.image())); + container.start(); + // Update config with current PostgreSQL container configuration + int dbPort = container.getMappedPort(containerConfig.exposedPorts()[0]); + try { + URI newUri = new URI("postgresql", + null, + uri.getHost(), + dbPort, + uri.getPath(), + uri.getQuery(), + uri.getFragment()); + config = Config.create( + ConfigSources.create( + Map.of( + "db.container", containerConfig.image(), + "db.connection.username", containerConfig.environment().get("POSTGRES_USER"), + "db.connection.password", containerConfig.environment().get("POSTGRES_PASSWORD"), + "db.connection.url", "jdbc:" + newUri.toString())), + ConfigSources.create(config)); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + // Wait for PostgreSQL database to start accepting JDBC connections + InitUtils.waitForStart( + () -> DriverManager.getConnection(config.get("db.connection.url").asString().get(), + config.get("db.connection.username").asString().get(), + config.get("db.connection.password").asString().get()), + STARTUP_TIMEOUT, + CONNECTION_CHECK_TIMEOUT); + // Create DbClient from updated configuration + dbClient = DbClient.builder(config.get("db")) + .addService(DbClientMetrics.counter() + .statementNames("select-pokemons", "insert-pokemon")) + .addService(DbClientMetrics.timer() + .statementTypes(DbStatementType.INSERT)) + .build(); + // Initialize the database + InitUtils.initSchema(dbClient); + InitUtils.initData(dbClient); + } + + @AfterSuite + public void afterSuite(DbClient dbClient) { + // Clean up the database + InitUtils.dropSchema(dbClient); + LOGGER.log(System.Logger.Level.TRACE, "Stopping PostgreSQL database"); + // Stop PostgreSQL container + container.stop(); + } + + @Override + public boolean supportsParameter(Type type) { + return Config.class.isAssignableFrom((Class) type) + || DbClient.class.isAssignableFrom((Class) type); + } + + @Override + public Object resolveParameter(Type type) { + if (Config.class.isAssignableFrom((Class) type)) { + return config; + } else if (DbClient.class.isAssignableFrom((Class) type)) { + return dbClient; + } + throw new IllegalArgumentException(String.format("Cannot resolve parameter Type %s", type.getTypeName())); + } + + @Suite(PgSqlSuite.class) + public static class ExceptionalStmtIT extends io.helidon.tests.integration.dbclient.common.tests.ExceptionalStmtIT { + + public ExceptionalStmtIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class FlowControlIT extends io.helidon.tests.integration.dbclient.common.tests.FlowControlIT { + public FlowControlIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class GetStatementIT extends io.helidon.tests.integration.dbclient.common.tests.GetStatementIT { + + public GetStatementIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class HealthCheckIT extends io.helidon.tests.integration.dbclient.common.tests.HealthCheckIT { + + public HealthCheckIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class InterceptorIT extends io.helidon.tests.integration.dbclient.common.tests.InterceptorIT { + + public InterceptorIT(Config config) { + super(config); + } + + } + + @Suite(PgSqlSuite.class) + public static class MapperIT extends io.helidon.tests.integration.dbclient.common.tests.MapperIT { + + public MapperIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class QueryStatementIT extends io.helidon.tests.integration.dbclient.common.tests.QueryStatementIT { + + public QueryStatementIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class ServerHealthCheckIT extends io.helidon.tests.integration.dbclient.common.tests.ServerHealthCheckIT { + + public ServerHealthCheckIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class ServerMetricsCheckIT extends io.helidon.tests.integration.dbclient.common.tests.ServerMetricsCheckIT { + + public ServerMetricsCheckIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleDeleteIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleDeleteIT { + + public SimpleDeleteIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleDmlIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleDmlIT { + + public SimpleDmlIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleGetIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleGetIT { + + public SimpleGetIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleInsertIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleInsertIT { + + public SimpleInsertIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleQueriesIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleQueriesIT { + + public SimpleQueriesIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class SimpleUpdateIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleUpdateIT { + + public SimpleUpdateIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class StatementDmlIT extends io.helidon.tests.integration.dbclient.common.tests.StatementDmlIT { + + public StatementDmlIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionDeleteIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionDeleteIT { + + public TransactionDeleteIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionExceptionalStmtIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionExceptionalStmtIT { + + public TransactionExceptionalStmtIT(DbClient dbClient) { + super(dbClient); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionGetIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionGetIT { + + public TransactionGetIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionInsertIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionInsertIT { + + public TransactionInsertIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionQueriesIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionQueriesIT { + + public TransactionQueriesIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + + @Suite(PgSqlSuite.class) + public static class TransactionUpdateIT extends io.helidon.tests.integration.dbclient.common.tests.TransactionUpdateIT { + + public TransactionUpdateIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + + } + +} diff --git a/tests/integration/dbclient/pom.xml b/tests/integration/dbclient/pom.xml index ee2f6b46711..0608fc521a0 100644 --- a/tests/integration/dbclient/pom.xml +++ b/tests/integration/dbclient/pom.xml @@ -26,18 +26,14 @@ 4.0.0-SNAPSHOT ../pom.xml + + io.helidon.tests.integration.dbclient helidon-tests-integration-dbclient-project pom Helidon Tests Integration Database Client A set of tests that validate Database Client - - common - h2 - app - - @@ -54,7 +50,9 @@ testcontainers - + mongodb + mysql + pgsql diff --git a/tests/integration/junit5/README.md b/tests/integration/junit5/README.md new file mode 100644 index 00000000000..5254286f0ea --- /dev/null +++ b/tests/integration/junit5/README.md @@ -0,0 +1,213 @@ +# Helidon jUnit 5 Test Suite + +Helidon jUnit 5 Test Suite provides environment for tests execution with +external resources. + +It supports following resources: + * Config from file + * Database container + - MySQL + - PosgreSQL + * DbClient + +Test suite represents set of jUnit testing classes with resources that are +available during the run of the whole suite. Suite provides its own +life-cycle handling and resource management. + +## Suite Definition + +Suite is Java implementation of `SuiteProvider` SPI interface. Suite has +no mandatory API, so it serves only to group jUnit testing classes by default. + +Suite supports two method annotations to handle its life-cycle: + * `@BeforeSuite` to initialize suite resources before tests will be executed + * `@AfterSuite` to clean up suite resources after tests were executed + +### Suite Attribute Resolver + +Suite class may optionally implement `SuiteResolver` interface to grant testing +classes access to its internal attributes. This interface is similar to jUnit +`ParameterResolver`. + +### Suite Resource Provider + +Resource provider adds specific resource to the suite. Resources may be +of the following types: + * Config + * Docker container + * DbClient + +Each provider is defined by its specific annotation and corresponding +SPI provider interface. + +#### Helidon Config Provider + +Adds Config support to the Suite class using `@TestConfig` annotation. +Provider has default SPI provider implementation so only config file has to be +specified in most of the cases. + +`@TestConfig` annotation arguments: + * `file` - configuration file, default value is `"test.yaml"` + * `provider` - Config support provider, default value is existing + `DefaultConfigProvider.class` + +Config support adds `@SetUpConfig` method annotation to customize stored +Config node. This method has access to the `Config.Builder` of this config node +during it's initialization phase. + +```java + @SetUpConfig + public void setupConfig(Config.Builder builder) { + builder. ... + } +``` + +#### Helidon Container Provider + +Adds Docker container support to the Suite class using `@ContainerTest` +annotation. Provider is defined by `@ContainerTest` annotation and +`ContainerProvider` interface implementation. + +`@ContainerTest` annotation arguments: + * `image` - docker image to run, default value is `""`, default value shall + be handled by corresponding provider implementation + * `provider` - specific Docker container support provider, currently there + are providers available for MySQL and PostgreSQL databases: + - `MySqlContainer.class` - for MySQL database, default image + is `mysql:latest` + - `PgSqlContainer.class` - for PostgreSQL database, default image + is `postgres:latest` + +Docker container support adds `@SetUpContainer` method annotation to customize +container setup. This method has access to the `ContainerConfig.Builder` +of this container during it's initialization phase. +Database container setup also have access to `DatabaseContainerConfig.Builder`. +Content of this method depends on specific provider implementation. + +```java + @SetUpContainer + public void setupContainer(Config config, DatabaseContainerConfig.Builder dbConfigBuilder, ContainerConfig.Builder builder) { + dbConfigBuilder. ... + builder. ... + } +``` + +#### Helidon DbClient Provider + +Adds DbClient support to the suite class using `@DbClientTest` annotation. +Provider has default SPI provider implementation so there is nothing to be +specified with the annotation. + +`@DbClientTest` annotation arguments: + * `provider` - DbClient support provider, default value is existing + `DefaultDbClientProvider.class` + +Docker container support adds `@SetUpDbClient` method annotation to customize +DbClient setup. This method has access to the `DbClient.Builder` +of this DbClient during it's initialization phase. +This method is executed after container startup so there is running container +information available, including container port mapping. + +```java + @SetUpDbClient + public void setupDbClient(Config config, ContainerInfo info, DbClient.Builder builder) { + builder. ... + } +``` + +### Suite Context + +Suite context interface `SuiteContext` may be passed to `@BeforeSuite`, +`@AfterSuite`, any `@SetUp...` annotated method and is also present in suite +resolver so any testing class constructor or test method may use it too. + +`SuiteContext` contains suite-wide storage space based on jUnit +`ExtensionContext.Store`. + +## Suite Example + +### Suite class + +```java +@TestConfig +@DbClientTest +@ContainerTest(provider = MySqlContainer.class, image = "mysql:8") +public class MySqlSuite implements SuiteProvider { + + @SetUpConfig + public void setupConfig(Config.Builder builder) { + // Any config customization + } + + @SetUpContainer + public void setupContainer(Config config, DatabaseContainerConfig.Builder dbConfigBuilder) { + // Example: setup database container using DbClient config node + config.get(DB_NODE + ".connection").asNode().ifPresent(dbConfigBuilder::dbClient); + } + + @SetUpDbClient + public void setupDbClient(Config config, ConfigUpdate update, ContainerInfo info, DbClient.Builder builder) { + // Merges ContainerInfo into DbClient config + Map updatedNodes = new HashMap<>(1); + config.get(DB_NODE + ".connection.url").as(String.class).ifPresent(value -> updatedNodes.put( + DB_NODE + ".connection.url", + DatabaseContainer.replacePortInUrl( + value, + info.portMappings().get(info.config().exposedPorts()[0])))); + Config containerConfig = Config.create(ConfigSources.create(updatedNodes), ConfigSources.create(config)); + // This replaces config stored by @TestConfig provider + update.config(containerConfig); + // Setup DbClient using updated config + builder.config(containerConfig.get(DB_NODE)); + } + + @BeforeSuite + public void beforeSuite(DbClient dbClient, Config config) { + // Example: database initialization + InitUtils.waitForStart( + () -> DriverManager.getConnection(config.get("db.connection.url").asString().get(), + config.get("db.connection.username").asString().get(), + config.get("db.connection.password").asString().get()), + 60, + 1); + InitUtils.initSchema(dbClient); + InitUtils.initData(dbClient); + } + + @AfterSuite + public void afterSuite(DbClient dbClient) { + // Example: database cleanup + InitUtils.dropSchema(dbClient); + } +} +``` + +### jUnit test class + +```java +@Suite(MySqlSuite.class) +class MyTest { + + @Test + void testSomething() { + // testing code + } + +} +``` + +### Maven surefire-plugin config + +Maven surefire or failsafe plugins must have extensions detection enabled + +```xml + + org.apache.maven.plugins + maven-surefire-plugin + + + true + + + +``` diff --git a/tests/integration/junit5/design.md b/tests/integration/junit5/design.md new file mode 100644 index 00000000000..1c447ac877f --- /dev/null +++ b/tests/integration/junit5/design.md @@ -0,0 +1,315 @@ +# jUnit 5 Test Suite Design + +## Suite + +Test suite represents set of jUnit test classes with defined life-cycle. + +### Suite life-cycle + +Suite life-cycle consists of three stages: +- suite setup +- tests execution +- suite cleanup + +Setup phase is responsible for testing environment initialization. This means +especially +- test clients (e.g. JDBC, DbClient) initialization and configuration + to be used with running contaienrs +- test containers (e.g. databases) startup + +Cleanup phase si responsible for freeing all resources acquired by testing +environment. All testing clients must be closed and running containers must +be stopped and deleted. + +Suite API is defined by `@Suite` annotation and `SuiteProvider` SPI interface. +Annotation defines `SuiteProvider` implementing class. + +```java +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@ExtendWith(SuiteJuit5Extension.class) +@Inherited +public @interface Suite { + + Class value(); + +} +``` + +`SuiteProvider` implementation class used as `@Suite` annotation should +be annotated with all required suite providers annotations. Those providers +will be applied on all test classes annotated with this `@Suite` annotation +with the same provider argument. +The only method of `SuiteProvider` +is `void suiteContext(SuiteContext suiteContext)` to retrieve shared suite +context. But it has default implementation, so it's not mandatory. + +Other optional methods are providers configuration hooks. Those methods +are annotated with corresponding setup annotation, e.g. `@SetUpContainer`. + +```java +@SetUpContainer +void setupContainer(ContainerConfig.Builder builder) { + // any builder calls +} +``` + +### Suite test classes grouping + +One suite is defined by the value of the `@Suite` annotation `provider`. +This value serves as suite unique ID. All test classes annotated +with the same `provider` form such a suite. +Each of the suites with unique `provider` has its own life-cycle and share +the same set of suite providers. + +## Suite with resources + +Testing environment may consist of several resources. Some of those resources +were already mentioned +- testing clients (HTTP client, DbClient) +- Docker containers, for example databases + +Each resource requires specific handling of its life-cycle. Suite resource +providers represent tools to achieve this goal. + +Suite resource is defined by annotation and suite resource +provider. + +### Test configuration provider + +Simple resource provider that reads Config from the file specified +in annotation. Annotation defines `ConfigProvider` implementing class +and source configuration file. + +```java +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface TestConfig { + + Class provider() default DefaultConfigProvider.class; + + String file() default "test.yaml"; + +} +``` + +`ConfigProvider` interface handles Config instance source, life-cycle and accessor. + +```java +/** + * Helidon integration tests configuration provider. + */ +public interface ConfigProvider extends SuiteExtensionProvider { + + /** + * Config file name from {@link io.helidon.tests.integration.junit5.TestConfig} + * annotation. + * + * @param file config file name to read from classpath + */ + void file(String file); + + /** + * Build configuration builder with default initial values. + */ + void setup(); + + /** + * Provide config builder to be used in setup hook. + * + * @return configuration builder with values from provided file. + */ + Config.Builder builder(); + + /** + * Start the existence of Config. + */ + void start(); + + /** + * Provide root {@link Config} instance for the tests. + */ + Config config(); + +} +``` + +### Test container provider + +Test container provider handles life-cycle of Docker container. This provider +is responsible for +- container startup +- providing configuration for related client (e.g. database URL for DbClient) +- container cleanup + +Container provider API is defined by `@TestContainer` annotation +and `ContainerProvider` SPI interface. Annotation defines `ContainerProvider` +implementing class and optional Docker image name of the container. + +```java +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface ContainerTest { + + Class provider(); + + String image() default ""; + +} +``` + +`ContainerProvider` interface handles container source image, life-cycle and builder accessor. + +```java +/** + * Helidon Database Client integration tests Docker container provider interface. + */ +public interface ContainerProvider extends SuiteExtensionProvider { + + /** + * Docker image from {@link io.helidon.tests.integration.junit5.ContainerTest} annotation. + * This method is called during {@link ContainerProvider} initialization phase. + * Implementing class must store this value and handle it properly. + * + * @param image name of the Docker image including label or {@link Optional#empty()} when not defined + */ + void image(Optional image); + + /** + * Build docker container configuration. + * Default container configuration must be set in this method. + * + * @return docker container configuration builder with default configuration set + */ + void setup(); + + /** + * Docker container configuration builder with default configuration set. + * This is the {@link ContainerConfig.Builder} instance passed + * to {@link io.helidon.tests.integration.junit5.SetUpContainer} annotated method + * in related {@link SuiteProvider} implementing class. + * + * @return container configuration builder with default configuration + */ + ContainerConfig.Builder builder(); + + /** + * Start Docker container. + * Calling this method may change provided value of Docker container configuration. + */ + void start(); + + /** + * Stop Docker container. + */ + void stop(); + +} +``` + +### Test DbClient provider + +This provider adds DbClient life-cycle handling. User code is responsible +for handling container port mapping manually. It must be done +in `@SetUpDbClient` annotated method. + +DbClient provider API is defined by `@DbClientTest` annotation +and `DbClientProvider` SPI interface. Annotation defines `DbClientProvider` +implementing class. + +```java +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface DbClientTest { + + Class provider() default DefaultDbClientProvider.class; + +} +``` + +`DbClientProvider` interface handles DbClient life-cycle, builder and instance accessor. + +```java +/** + * Helidon Database Client integration tests configuration provider interface. + */ +public interface DbClientProvider extends SuiteExtensionProvider { + + /** + * Build configuration builder with default initial values. + */ + void setup(); + + /** + * Provide config builder to be used in setup hook. + * + * @return configuration builder with values from provided file. + */ + DbClient.Builder builder(); + + /** + * Start the existence of {@link DbClient}. + */ + void start(); + + /** + * Provide root {@link DbClient} instance for the tests. + */ + DbClient dbClient(); + +} +``` + +### Resources initialization order + +Resources dependency: + * Config has no dependency + * Docker container depends on Config + * DbClient depends on both Config and Docker container + +This requires execution of all resources life-phases to be synchronized and in defined order: + +1. providers initialization phase + - `ConfigProvider.suiteContext`, `ContainerProvider.suiteContext` and `DbClientProvider.suiteContext` + - `ConfigProvider.file` + - `ContainerProvider.image` + +2. configuration initialization phase + - `ConfigProvider.setup` + - `ConfigProvider.builder` and suite `@SetUpConfig` annotated method + - `ConfigProvider.start` creates and stores config + +3. container configuration and startup + - `ContainerProvider.setup` + - `ContainerProvider.builder` and suite `@SetUpContainer` annotated method + - `ContainerProvider.start` stores container info + +4. `DbClient` configuration and startup + - `DbClientProvider.setup` + - `DbClientProvider.builder` and suite `@SetUpDbClient` annotated method + (responsible for config update) + - `DbClientProvider.start` + +5. tests execution + +6. suite Cleanup + - `DbClientProvider.stop` and `ContainerProvider.stop` + +### Annotated test classes + +Test class is annotated with `@Suite` annotation only. Provider `MySQLSuite` contains +both `@TestContainer` and `@DbClientTest` annotations. + +```java +@Suite(MySQLSuite.class) +public class SimpleDmlIT extends io.helidon.tests.integration.dbclient.common.tests.SimpleDmlIT { + + public SimpleDmlIT(DbClient dbClient, Config config) { + super(dbClient, config); + } + +} +``` diff --git a/tests/integration/junit5/pom.xml b/tests/integration/junit5/pom.xml new file mode 100644 index 00000000000..94ceb102ab6 --- /dev/null +++ b/tests/integration/junit5/pom.xml @@ -0,0 +1,198 @@ + + + + + 4.0.0 + + + io.helidon.tests.integration + helidon-tests-integration + 4.0.0-SNAPSHOT + ../pom.xml + + helidon-tests-integration-junit5 + Helidon Tests Integration jUnit 5 Extension + A set of jUnit 5 extensions for Helidon integration tests + + + true + + + + + io.helidon.common + helidon-common + + + io.helidon.config + helidon-config + + + io.helidon.config + helidon-config-metadata + + + io.helidon.dbclient + helidon-dbclient + + + org.junit.jupiter + junit-jupiter-api + + + org.testcontainers + testcontainers + + + io.helidon.config + helidon-config-yaml + test + + + io.helidon.dbclient + helidon-dbclient-jdbc + test + + + io.helidon.dbclient + helidon-dbclient-hikari + test + + + com.mysql + mysql-connector-j + test + + + org.postgresql + postgresql + test + + + org.hamcrest + hamcrest-all + test + + + + + + + io.helidon.build-tools + helidon-services-plugin + + false + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.helidon.common.features + helidon-common-features-processor + ${helidon.version} + + + io.helidon.config + helidon-config-metadata-processor + ${helidon.version} + + + io.helidon.builder + helidon-builder-processor + ${helidon.version} + + + io.helidon.inject.configdriven + helidon-inject-configdriven-processor + ${helidon.version} + + + io.helidon.common.processor + helidon-common-processor-helidon-copyright + ${helidon.version} + + + + + + io.helidon.builder + helidon-builder-processor + ${helidon.version} + + + io.helidon.config + helidon-config-metadata-processor + ${helidon.version} + + + io.helidon.inject.configdriven + helidon-inject-configdriven-processor + ${helidon.version} + + + io.helidon.common.processor + helidon-common-processor-helidon-copyright + ${helidon.version} + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + true + + ${maven.test.redirectTestOutputToFile} + + io.helidon.tests.integration.junit5.TestSimpleSuite + io.helidon.tests.integration.junit5.TestConfigSuite + + + + + + + + + + testcontainers + + + + org.apache.maven.plugins + maven-surefire-plugin + + + io.helidon.tests.integration.junit5.TestSimpleSuite + io.helidon.tests.integration.junit5.TestConfigSuite + io.helidon.tests.integration.junit5.TestMySqlSuite + io.helidon.tests.integration.junit5.TestPgSqlSuite + + + + + + + + + diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/AbstractContainer.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/AbstractContainer.java new file mode 100644 index 00000000000..5f1a6b9ea4f --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/AbstractContainer.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.reflect.Type; +import java.util.Optional; + +import io.helidon.tests.integration.junit5.spi.ContainerProvider; + +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.utility.DockerImageName; + +public abstract class AbstractContainer implements ContainerProvider, SuiteResolver { + + private static final System.Logger LOGGER = System.getLogger(AbstractContainer.class.getName()); + + /** @noinspection OptionalUsedAsFieldOrParameterType*/ + private Optional image; + /** @noinspection OptionalUsedAsFieldOrParameterType*/ + private ContainerConfig.Builder builder; + private ContainerConfig config; + private GenericContainer container; + private ContainerInfo info; + private SuiteContext suiteContext; + + protected AbstractContainer() { + image = Optional.empty(); + builder = null; + config = null; + container = null; + info = null; + suiteContext = null; + } + + @Override + public void image(Optional image) { + this.image = image; + } + + @Override + public void suiteContext(SuiteContext suiteContext) { + this.suiteContext = suiteContext; + } + + @Override + public ContainerConfig.Builder builder() { + return builder; + } + + protected Optional image() { + return image; + } + + protected ContainerConfig config() { + return config; + } + + protected GenericContainer container() { + return container; + } + + protected ContainerInfo info() { + return info; + } + + protected SuiteContext suiteContext() { + return suiteContext; + } + + @Override + public void setup() { + builder = ContainerConfig.builder(); + image.ifPresent(name -> builder.image(name)); + } + + /** + * Creates and stores container configuration from internal builder. + */ + protected void containerConfig() { + config = builder.build(); + } + + /** + * Creates and stores container from internal container config. + */ + protected void createContainer() { + if (config == null) { + containerConfig(); + } + container = new GenericContainer<>(DockerImageName.parse(config.image())); + config.environment().forEach(container::withEnv); + container.addExposedPorts(config.exposedPorts()); + } + + protected void containerInfo(ContainerInfo info) { + this.info = info; + } + + @Override + public void start() { + if (container == null) { + createContainer(); + } + LOGGER.log(System.Logger.Level.TRACE, () -> String.format("Starting the container %s", config.image())); + container.start(); + } + + @Override + public void stop() { + LOGGER.log(System.Logger.Level.TRACE, () -> String.format("Stopping the container %s", config.image())); + container.stop(); + } + + @Override + public boolean supportsParameter(Type type) { + return ContainerConfig.class.isAssignableFrom((Class) type) + || GenericContainer.class.isAssignableFrom((Class) type) + || ContainerInfo.class.isAssignableFrom((Class) type); + } + + @Override + public Object resolveParameter(Type type) { + if (ContainerConfig.class.isAssignableFrom((Class) type)) { + return config; + } else if (GenericContainer.class.isAssignableFrom((Class) type)) { + return container; + } else if (ContainerInfo.class.isAssignableFrom((Class) type)) { + return info; + } + throw new IllegalArgumentException(String.format("Cannot resolve parameter Type %s", type.getTypeName())); + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/AfterSuite.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/AfterSuite.java new file mode 100644 index 00000000000..ea3e30ced05 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/AfterSuite.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023, 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.junit5; + +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; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +@Inherited +public @interface AfterSuite { +} diff --git a/tests/integration/dbclient/h2/src/main/java/module-info.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/BeforeSuite.java similarity index 53% rename from tests/integration/dbclient/h2/src/main/java/module-info.java rename to tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/BeforeSuite.java index bec50ffe7ec..5610563391a 100644 --- a/tests/integration/dbclient/h2/src/main/java/module-info.java +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/BeforeSuite.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2023, 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,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package io.helidon.tests.integration.junit5; + +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; /** - * Helidon Database Client Integration Tests with H2 Database. + * Before {@link Suite} initialization method. */ -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 +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +@Inherited +public @interface BeforeSuite { +} diff --git a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/spi/SetupProvider.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ConfigUpdate.java similarity index 57% rename from tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/spi/SetupProvider.java rename to tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ConfigUpdate.java index d3c110cb658..122c86dd56d 100644 --- a/tests/integration/dbclient/common/src/main/java/io/helidon/tests/integration/dbclient/common/spi/SetupProvider.java +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ConfigUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2023, 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,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.tests.integration.dbclient.common.spi; +package io.helidon.tests.integration.junit5; import io.helidon.config.Config; -import io.helidon.dbclient.DbClient; -public interface SetupProvider { - - /** - * Provide root {@Config} instance for the tests. - */ - Config config(); +/** + * Provides an interface to update {@link Config} stored in actual + * {@link io.helidon.tests.integration.junit5.spi.ConfigProvider} + * of the {@link io.helidon.tests.integration.junit5.TestConfig} annotation. + */ +public interface ConfigUpdate { /** - * Provide {@link DbClient} instance for the tests. + * Update stored {@link Config} instance. * - * @return the {@link DbClient} instance + * @param config new {@link Config} */ - DbClient dbClient(); + void config(Config config); } diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ConfigUtils.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ConfigUtils.java new file mode 100644 index 00000000000..34d18f427eb --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ConfigUtils.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.net.URI; + +/** + * Configuration utilities. + */ +public class ConfigUtils { + + private ConfigUtils() { + throw new IllegalStateException("No instances of ConfigUtils are allowed"); + } + + /** + * Create {@link URI} from JDBC database URL. + * URI (URL) syntax shall match following scheme:

+ * {@code URI = scheme ":" ["//" authority] path ["?" query] ["#" fragment]}

+ * Unfortunately {@code scheme} element of JDBC database URL may contain multiple fields + * separated by {@code ':'} character. Only last of those fields can be passed to URI parser. + * To simplify the parsing, {@code "//" authority} element is considered as mandatory. + * + * @param url JDBC database URL + * @return {@link URI} from JDBC database URL + */ + public static URI uriFromDbUrl(String url) { + // Search for beginning of authority element which is considered as mandatory + int authIndex = url.indexOf("://"); + if (authIndex == -1) { + throw new IllegalArgumentException("Missing URI authorioty initial sequence \"://\""); + } + if (authIndex == 0) { + throw new IllegalArgumentException("Missing URI segment part"); + } + // Search for last sub-scheme separator ':' before "://", it may not exist + int separator = url.lastIndexOf(':', authIndex - 1); + if (separator >= 0) { + return URI.create(url.substring(separator + 1)); + } + return URI.create(url); + } + + /** + * Create database name from URI path element. + * Path element starts with {@code '/'} character as a consequence of having {@code "//" authority} element + * in the URL. Leading {@code '/'} character must be removed from the path if exists to get database name. + * + * @param dbUri source URI + * @return database name from URI path element + */ + public static String dbNameFromUri(URI dbUri) { + String dbPath = dbUri.getPath(); + if (dbPath.length() == 0) { + throw new IllegalArgumentException("Database name is empty"); + } + String dbName = dbPath.charAt(0) == '/' ? dbPath.substring(1) : dbPath; + if (dbName.length() == 0) { + throw new IllegalArgumentException("Database name is empty"); + } + return dbName; + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerConfigBlueprint.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerConfigBlueprint.java new file mode 100644 index 00000000000..4aabfa545b0 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerConfigBlueprint.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.time.Duration; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import io.helidon.builder.api.Option; +import io.helidon.builder.api.Prototype; +import io.helidon.config.metadata.Configured; +import io.helidon.config.metadata.ConfiguredOption; + +import org.testcontainers.containers.wait.strategy.WaitStrategy; + +/** + * Docker container configuration bean. + */ +@Prototype.Blueprint +@Configured +interface ContainerConfigBlueprint { + + /** + * Name of the Docker image including label. + * + * @return name of the image + */ + @ConfiguredOption + String image(); + + /** + * Environment variables to be set in the container. + * + * @return {@link Map} of environment variables + */ + @ConfiguredOption + Map environment(); + + /** + * Ports that container listens on. + * @return {@link List} of TCP ports + */ + @ConfiguredOption + int[] exposedPorts(); + + /** + * Working directory that the container should use on startup. + * + * @return path to the working directory inside the container + */ + @ConfiguredOption + Optional workingDirectory(); + + /** + * Command that should be run in the container. + * @return command in single string format + */ + @ConfiguredOption + Optional command(); + + /** + * Container startup timeout. + * @return startup timeout + */ + @ConfiguredOption("PT60S") + Duration startUpTimeout(); + + /** + * Specify the {@link WaitStrategy} to use to determine if the container is ready. + * @return {@link WaitStrategy} to use + */ + @Option.DefaultCode("ContainerConfigConstants.defaultWaitStrategy()") + WaitStrategy waitStrategy(); + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerConfigConstants.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerConfigConstants.java new file mode 100644 index 00000000000..d0a0e50a2aa --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerConfigConstants.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.containers.wait.strategy.WaitStrategy; + +// PKG only visible class with default builder values definition +class ContainerConfigConstants { + static final WaitStrategy defaultWaitStrategy() { + return Wait.forListeningPort(); + } +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerInfo.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerInfo.java new file mode 100644 index 00000000000..504f250ec04 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerInfo.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.util.Map; + +/** + * Container information. + * This class contains information about running container. It should be stored + * into suite shared context storage when requested. + */ +public record ContainerInfo( + /** + * Container configuration + */ + ContainerConfig config, + /** + * Port mapping: key is container port (mapping source), value is target host port (mapping target) + */ + Map portMappings, + /** + * Additional properties describing the container, e.g. the database URL. + */ + Map properties +) { +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerTest.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerTest.java new file mode 100644 index 00000000000..1412d9f091b --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/ContainerTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023, 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.junit5; + +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 io.helidon.tests.integration.junit5.spi.ContainerProvider; + +/** + * Test that requires database container. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface ContainerTest { + + /** + * Container provider class. + * + * @return container provider class + */ + Class provider(); + + /** + * Container image, may contain label, e.g. {@code "mysql"}, {@code "mysql:8.0"}. + * + * @return container image + */ + String image() default ""; + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DatabaseContainer.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DatabaseContainer.java new file mode 100644 index 00000000000..508cb64546d --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DatabaseContainer.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.reflect.Type; + +public abstract class DatabaseContainer extends AbstractContainer { + + private DatabaseContainerConfig.Builder dbConfigBuilder; + private DatabaseContainerConfig dbConfig; + + protected DatabaseContainer() { + super(); + dbConfigBuilder = null; + dbConfig = null; + } + + protected DatabaseContainerConfig dbConfig() { + return dbConfig; + } + + @Override + public void setup() { + super.setup(); + dbConfigBuilder = DatabaseContainerConfig.builder(); + } + + public void createDbConfig() { + dbConfig = dbConfigBuilder.build(); + } + + @Override + public boolean supportsParameter(Type type) { + return super.supportsParameter(type) + || DatabaseContainerConfig.Builder.class.isAssignableFrom((Class) type) + || DatabaseContainerConfig.class.isAssignableFrom((Class) type); + } + + @Override + public Object resolveParameter(Type type) { + if (super.supportsParameter(type)) { + return super.resolveParameter(type); + } else if (DatabaseContainerConfig.Builder.class.isAssignableFrom((Class) type)) { + return dbConfigBuilder; + } else if (DatabaseContainerConfig.class.isAssignableFrom((Class) type)) { + return dbConfig; + } + throw new IllegalArgumentException(String.format("Cannot resolve parameter Type %s", type.getTypeName())); + } + + /** + * Replace port value in provided URL. + * + * @param url source URL + * @param port new port value in returned URL + * @return source url with port replaced by {@code port} value. + */ + public static String replacePortInUrl(String url, int port) { + int begin = url.indexOf("://"); + if (begin >= 0) { + int end = url.indexOf('/', begin + 3); + int portBeg = url.indexOf(':', begin + 3); + // Found port position in URL + if (end > 0 && portBeg < end) { + String frontPart = url.substring(0, portBeg + 1); + String endPart = url.substring(end); + return frontPart + Integer.toString(port) + endPart; + } else { + throw new IllegalStateException( + String.format("URL %s does not contain host and port part \"://host:port/\"", url)); + } + } else { + throw new IllegalStateException( + String.format("Could not find host separator \"://\" in URL %s", url)); + } + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DatabaseContainerConfigBlueprint.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DatabaseContainerConfigBlueprint.java new file mode 100644 index 00000000000..b17892f1bde --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DatabaseContainerConfigBlueprint.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import io.helidon.builder.api.Option; +import io.helidon.builder.api.Prototype; +import io.helidon.config.Config; + +/** + * Docker database container configuration extension bean. + * This container configuration extension may be provided + * in {@link io.helidon.tests.integration.junit5.spi.SuiteProvider} method annotated + * with {@link io.helidon.tests.integration.junit5.SetUpContainer} annotation and having + * {@link DatabaseContainerConfig.Builder} method parameter. + */ +@Prototype.Blueprint +@Prototype.Configured +interface DatabaseContainerConfigBlueprint { + + /** + * Database configuration node matching structure of DbClient configuration. + * This should be the content of {@code "connection"} node:

    + *
  • url - the database connection URL without user name and password
  • + *
  • username - the database connection user name
  • + *
  • password - the database connection user password
  • + *
+ * + * @return DbClient {@link Config} sub-node matching {@code "connection"} key. + */ + @Option.Configured + @Option.DefaultCode("Config.empty()") + Config dbClient(); + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DbClientTest.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DbClientTest.java new file mode 100644 index 00000000000..7619758c017 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DbClientTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023, 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.junit5; + +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 io.helidon.tests.integration.junit5.spi.DbClientProvider; + +/** + * Test that requires {@link io.helidon.dbclient.DbClient}. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface DbClientTest { + + /** + * {@link io.helidon.dbclient.DbClient} provider class. + * Default value is {@code DefaultSetupProvider.class} + * + * @return setup provider class + */ + Class provider() default DefaultDbClientProvider.class; + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DefaultConfigProvider.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DefaultConfigProvider.java new file mode 100644 index 00000000000..bc136c19627 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DefaultConfigProvider.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.reflect.Type; + +import io.helidon.config.Config; +import io.helidon.config.ConfigSources; +import io.helidon.tests.integration.junit5.spi.ConfigProvider; + +/** + * Default {@link TestConfig} provider. + * Reads config file specified by the annotation and optionally stores it + * into {@link SuiteContext#storage()} using {@link TestConfig#key()}. + * This class also serves as {@link SuiteResolver} for stored {@link Config}. + */ +public class DefaultConfigProvider implements ConfigProvider, ConfigUpdate, SuiteResolver { + + private String fileName; + private SuiteContext suiteContext; + private Config config; + private Config.Builder builder; + + public DefaultConfigProvider() { + fileName = null; + suiteContext = null; + config = null; + builder = null; + } + + @Override + public void suiteContext(SuiteContext suiteContext) { + this.suiteContext = suiteContext; + } + + @Override + public void file(String fileName) { + this.fileName = fileName; + } + + @Override + public void setup() { + builder = Config.builder().addSource(ConfigSources.classpath(fileName)); + } + + @Override + public Config.Builder builder() { + return builder; + } + + @Override + public void start() { + config = builder.build(); + } + + @Override + public Config config() { + return config; + } + + @Override + public void config(Config config) { + this.config = config; + } + + @Override + public boolean supportsParameter(Type type) { + return Config.class.isAssignableFrom((Class) type) + || ConfigUpdate.class.isAssignableFrom((Class) type); + } + + @Override + public Object resolveParameter(Type type) { + if (Config.class.isAssignableFrom((Class)type)) { + return config; + } else if (ConfigUpdate.class.isAssignableFrom((Class) type)) { + return this; + } + + throw new IllegalArgumentException(String.format("Cannot resolve parameter Type %s", type.getTypeName())); + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DefaultDbClientProvider.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DefaultDbClientProvider.java new file mode 100644 index 00000000000..891a97965c5 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/DefaultDbClientProvider.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.System.Logger; +import java.lang.reflect.Type; + +import io.helidon.dbclient.DbClient; +import io.helidon.tests.integration.junit5.spi.DbClientProvider; + +public class DefaultDbClientProvider implements DbClientProvider, SuiteResolver { + + private static final Logger LOGGER = System.getLogger(DefaultDbClientProvider.class.getName()); + + private SuiteContext suiteContext; + private DbClient dbClient; + private DbClient.Builder builder; + public DefaultDbClientProvider() { + suiteContext = null; + dbClient = null; + builder = null; + } + + public void suiteContext(SuiteContext suiteContext) { + this.suiteContext = suiteContext; + } + + @Override + public void setup() { + builder = DbClient.builder(); + } + + @Override + public DbClient.Builder builder() { + return builder; + } + + @Override + public void start() { + dbClient = builder.build(); + } + + @Override + public DbClient dbClient() { + return dbClient; + } + + @Override + public boolean supportsParameter(Type type) { + return DbClient.class.isAssignableFrom((Class) type); + } + + @Override + public Object resolveParameter(Type type) { + if (DbClient.class.isAssignableFrom((Class)type)) { + return dbClient; + } + throw new IllegalArgumentException(String.format("Cannot resolve parameter Type %s", type.getTypeName())); + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/MySqlContainer.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/MySqlContainer.java new file mode 100644 index 00000000000..f6a998b1fc5 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/MySqlContainer.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import io.helidon.config.Config; +import io.helidon.config.ConfigValue; + +public class MySqlContainer extends DatabaseContainer { + + private static final Logger LOGGER = System.getLogger(MySqlContainer.class.getName()); + + private static final String DEFAULT_IMAGE = "mysql:latest"; + private static final String ROOT_PASSWORD = "R00t_P4ssw0rd"; + private static final String USER = "user"; + private static final String PASSWORD = "p4ssw0rd"; + private static final String DATABASE = "dbclient"; + private static final int PORT = 3306; + + public MySqlContainer() { + super(); + } + + @Override + public void setup() { + super.setup(); + // Set default image as fallback when no image was configured. + if (image().isEmpty()) { + builder().image(DEFAULT_IMAGE); + } + } + + @Override + public void start() { + createDbConfig(); + // Can't be null + Map environment = builder().environment(); + // Copy container configuration from DbClient "connection" Config node. + // Only replace values that are not already present (added by @SetUpContainer method) + dbConfig().dbClient().asNode().ifPresent(config -> { + config.get("url").asString().ifPresent(url -> { + URI uri = ConfigUtils.uriFromDbUrl(url); + if (!environment.containsKey("MYSQL_DATABASE")) { + environment.put("MYSQL_DATABASE", ConfigUtils.dbNameFromUri(uri)); + } + if (builder().exposedPorts() == null || builder().exposedPorts().length == 0) { + builder().exposedPorts(new int[] {uri.getPort()}); + } + }); + config.get("username").asString().ifPresent(user -> { + if (!environment.containsKey("MYSQL_USER")) { + environment.put("MYSQL_USER", user); + } + }); + config.get("password").asString().ifPresent(password -> { + if (!environment.containsKey("MYSQL_PASSWORD")) { + environment.put("MYSQL_PASSWORD", password); + } + }); + }); + // Provide default configuration values for all that are missing + if (!environment.containsKey("MYSQL_ROOT_PASSWORD")) { + environment.put("MYSQL_ROOT_PASSWORD", ROOT_PASSWORD); + } + if (!environment.containsKey("MYSQL_DATABASE")) { + environment.put("MYSQL_DATABASE", DATABASE); + } + if (!environment.containsKey("MYSQL_USER")) { + environment.put("MYSQL_USER", USER); + } + if (!environment.containsKey("MYSQL_PASSWORD")) { + environment.put("MYSQL_PASSWORD", PASSWORD); + } + if (builder().exposedPorts() == null || builder().exposedPorts().length == 0) { + builder().exposedPorts(new int[] {PORT}); + } + // Create container config and container from internal builder and start the container. + super.start(); + + LOGGER.log(Level.TRACE, + () -> String.format("MySQL database from image %s is running", config().image())); + LOGGER.log(Level.TRACE, + () -> String.format("Container configuration: %s", config().toString())); + // Store container info + Map portMappings = new HashMap<>(config().exposedPorts().length); + for (int port : config().exposedPorts()) { + Integer mappedPort = container().getMappedPort(port); + if (mappedPort != null) { + portMappings.put(port, mappedPort); + } + } + Map properties = new HashMap<>(3); + ConfigValue dbConfig = dbConfig().dbClient().asNode(); + String url = String.format("jdbc:mysql://127.0.0.1:3306/%s?useSSL=false&allowPublicKeyRetrieval=true", DATABASE); + if (dbConfig.isPresent()) { + ConfigValue urlValue = dbConfig.get().get("url").asString(); + if (urlValue.isPresent()) { + url = urlValue.get(); + } + } + properties.put("url", replacePortInUrl(url, portMappings.get(config().exposedPorts()[0]))); + properties.put("username", environment.get("MYSQL_USER")); + properties.put("password", environment.get("MYSQL_PASSWORD")); + properties.put("adminpw", environment.get("MYSQL_ROOT_PASSWORD")); + containerInfo(new ContainerInfo(config(), Map.copyOf(portMappings), Map.copyOf(properties))); + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/PgSqlContainer.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/PgSqlContainer.java new file mode 100644 index 00000000000..0ea8ca64caf --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/PgSqlContainer.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import io.helidon.config.Config; +import io.helidon.config.ConfigValue; + +public class PgSqlContainer extends DatabaseContainer { + + private static final System.Logger LOGGER = System.getLogger(MySqlContainer.class.getName()); + + private static final String DEFAULT_IMAGE = "postgres:latest"; + private static final String USER = "user"; + private static final String PASSWORD = "p4ssw0rd"; + private static final String DATABASE = "dbclient"; + private static final int PORT = 5432; + + public PgSqlContainer() { + super(); + } + + @Override + public void setup() { + super.setup(); + // Set default image as fallback when no image was configured. + if (image().isEmpty()) { + builder().image(DEFAULT_IMAGE); + } + } + + @Override + public void start() { + createDbConfig(); + // Can't be null + Map environment = builder().environment(); + // Copy container configuration from DbClient "connection" Config node. + // Only replace values that are not already present (added by @SetUpContainer method) + dbConfig().dbClient().asNode().ifPresent(config -> { + config.get("url").asString().ifPresent(url -> { + URI uri = ConfigUtils.uriFromDbUrl(url); + if (!environment.containsKey("POSTGRES_DB")) { + environment.put("POSTGRES_DB", ConfigUtils.dbNameFromUri(uri)); + } + if (builder().exposedPorts() == null || builder().exposedPorts().length == 0) { + builder().exposedPorts(new int[] {uri.getPort()}); + } + }); + config.get("username").asString().ifPresent(user -> { + if (!environment.containsKey("POSTGRES_USER")) { + environment.put("POSTGRES_USER", user); + } + }); + config.get("password").asString().ifPresent(password -> { + if (!environment.containsKey("POSTGRES_PASSWORD")) { + environment.put("POSTGRES_PASSWORD", password); + } + }); + }); + // Provide default configuration values for all that are missing + if (!environment.containsKey("POSTGRES_DB")) { + environment.put("POSTGRES_DB", DATABASE); + } + if (!environment.containsKey("POSTGRES_USER")) { + environment.put("POSTGRES_USER", USER); + } + if (!environment.containsKey("POSTGRES_PASSWORD")) { + environment.put("POSTGRES_PASSWORD", PASSWORD); + } + if (builder().exposedPorts() == null || builder().exposedPorts().length == 0) { + builder().exposedPorts(new int[] {PORT}); + } + // Create container config and container from internal builder and start the container. + super.start(); + + LOGGER.log(System.Logger.Level.TRACE, + () -> String.format("PostgreSQL database from image %s is running", config().image())); + LOGGER.log(System.Logger.Level.TRACE, + () -> String.format("Container configuration: %s", config().toString())); + // Store container info + Map portMappings = new HashMap<>(config().exposedPorts().length); + for (int port : config().exposedPorts()) { + Integer mappedPort = container().getMappedPort(port); + if (mappedPort != null) { + portMappings.put(port, mappedPort); + } + } + Map properties = new HashMap<>(3); + ConfigValue dbConfig = dbConfig().dbClient().asNode(); + String url = String.format("jdbc:postgresql://127.0.0.1:5432/%s", DATABASE); + if (dbConfig.isPresent()) { + ConfigValue urlValue = dbConfig.get().get("url").asString(); + if (urlValue.isPresent()) { + url = urlValue.get(); + } + } + properties.put("url", replacePortInUrl(url, portMappings.get(config().exposedPorts()[0]))); + properties.put("username", environment.get("POSTGRES_USER")); + properties.put("password", environment.get("POSTGRES_PASSWORD")); + properties.put("adminpw", environment.get("POSTGRES_PASSWORD")); + containerInfo(new ContainerInfo(config(), Map.copyOf(portMappings), Map.copyOf(properties))); + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpConfig.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpConfig.java new file mode 100644 index 00000000000..fc8ac2c06de --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpConfig.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023, 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.junit5; + +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; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +@Inherited +public @interface SetUpConfig { +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpContainer.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpContainer.java new file mode 100644 index 00000000000..894909c384e --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpContainer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023, 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.junit5; + +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; + +/** + * Docker container {@link Suite} configuration method. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +@Inherited +public @interface SetUpContainer { +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpDbClient.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpDbClient.java new file mode 100644 index 00000000000..ec80d8ac04b --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SetUpDbClient.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023, 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.junit5; + +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; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +@Inherited +public @interface SetUpDbClient { +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/Suite.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/Suite.java new file mode 100644 index 00000000000..b565c73fe17 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/Suite.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023, 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.junit5; + +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 io.helidon.tests.integration.junit5.spi.SuiteProvider; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Test suite annotation + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@ExtendWith(SuiteJuit5Extension.class) +@Inherited +public @interface Suite { + + /** + * Suite provider class. + * + * @return the provider class + */ + Class value(); + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteContext.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteContext.java new file mode 100644 index 00000000000..d82a0593eab --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteContext.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023, 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.junit5; + +public interface SuiteContext { + + interface Storage { + T get(String key, Class cls); + T getOrDefault(String key, Class cls, T defaultValue); + void putOrReplace(String key, Object value); + void put(String key, Object value); + } + + Storage storage(); + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteExtensionProvider.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteExtensionProvider.java new file mode 100644 index 00000000000..cbb02a54db4 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteExtensionProvider.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023, 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.junit5; + +/** + * Helidon integration tests Junit 5 extension provider. + * Common SPI extension base. + */ +public interface SuiteExtensionProvider { + + /** + * Cast Junit 5 extension provider to its implementing class. + * + * @param cls Junit 5 extension provider implementing class + * @return Junit 5 extension provider as its implementing class + * @param Junit 5 extension provider implementing class + * @throws java.lang.IllegalArgumentException when {@code cls} parameter does not match + * class implemented by the provider. + */ + default T as(Class cls) { + try { + return cls.cast(this); + } catch (ClassCastException e) { + throw new IllegalArgumentException( + String.format("Cannot cast this SuiteExtensionProvider implementation as %s", cls.getName()), e); + } + } + + /** + * Pass {@link Suite} context to the Junit 5 extension provider during initialization phase. + * This method is called before any other initialization method of the provider. + * + * @param suiteContext the {@link Suite} context + */ + default void suiteContext(SuiteContext suiteContext) { + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteJuit5Extension.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteJuit5Extension.java new file mode 100644 index 00000000000..f1e5233b610 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteJuit5Extension.java @@ -0,0 +1,654 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.function.Function; + +import io.helidon.common.HelidonServiceLoader; +import io.helidon.config.Config; +import io.helidon.dbclient.DbClient; +import io.helidon.tests.integration.junit5.spi.ConfigProvider; +import io.helidon.tests.integration.junit5.spi.ContainerProvider; +import io.helidon.tests.integration.junit5.spi.DbClientProvider; +import io.helidon.tests.integration.junit5.spi.SuiteProvider; + +import org.junit.jupiter.api.extension.BeforeAllCallback; +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 static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL; + +/** + * {@link Suite} jUnit 5 extension handler. + */ +public class SuiteJuit5Extension + implements BeforeAllCallback, ExtensionContext.Store.CloseableResource, ParameterResolver { + + private static final Logger LOGGER = System.getLogger(SuiteJuit5Extension.class.getName()); + + // Store all stored SuiteProvider instances keys to close them. + private static final Set PROVIDER_KEYS = new HashSet<>(); + + // Already loaded SuiteProvider instances are stored in jUnit 5 GLOBAL store. + // Store key is SuiteProvider implementing class fully qualified name. + private String storeKey; + private Suite suite; + private Class providerClass; + private SuiteDescriptor descriptor; + ExtensionContext.Store globalStore; + + public SuiteJuit5Extension() { + storeKey = null; + suite = null; + providerClass = null; + descriptor = null; + globalStore = null; + } + + @Override + public void beforeAll(ExtensionContext context) throws Exception { + if (context.getTestClass().isPresent()) { + LOGGER.log(Level.TRACE, + () -> String.format("Running beforeAll of %s test class", + context.getTestClass().get().getSimpleName())); + suite = suiteFromContext(context); + providerClass = suite.value(); + storeKey = providerClass.getName(); + globalStore = context.getRoot().getStore(GLOBAL); + descriptor = providerFromStore(globalStore, storeKey); + // Run the initialization just once for every suite provider + if (descriptor == null) { + descriptor = SuiteDescriptor.create(suite, context); + LOGGER.log(Level.TRACE, + () -> String.format("Initializing the Suite provider %s", providerClass.getSimpleName())); + descriptor.init(); + storeProvider(globalStore, storeKey, descriptor); + ensureThisInstanceIsStored(globalStore); + } + } else { + throw new IllegalStateException("Test class was not found in jUnit 5 extension context"); + } + } + + @Override + public void close() throws Throwable { + for (String key : PROVIDER_KEYS) { + SuiteDescriptor descriptor = globalStore.get(key, SuiteDescriptor.class); + LOGGER.log(Level.TRACE, + () -> String.format("Closing Suite provider %s", descriptor.provider.getClass().getSimpleName())); + descriptor.close(); + } + } + + @Override + public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) + throws ParameterResolutionException { + return descriptor.supportsParameterGlobal(parameterContext.getParameter().getType()); + } + + @Override + public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) + throws ParameterResolutionException { + return descriptor.resolveParameterGlobal(parameterContext.getParameter().getType()); + } + + private static SuiteDescriptor providerFromStore(ExtensionContext.Store globalStore, String storeKey) { + return globalStore.get(storeKey, SuiteDescriptor.class); + } + + private static void storeProvider(ExtensionContext.Store globalStore, String storeKey, SuiteDescriptor descriptor) { + globalStore.put(storeKey, descriptor); + PROVIDER_KEYS.add(storeKey); + } + + private void ensureThisInstanceIsStored(ExtensionContext.Store globalStore) { + if (globalStore.get(SuiteJuit5Extension.class.getName()) == null) { + globalStore.put(SuiteJuit5Extension.class.getName(), this); + } + } + + private static Suite suiteFromContext(ExtensionContext context) { + Class testClass = context.getTestClass().get(); + Suite suite = testClass.getAnnotation(Suite.class); + if (suite == null) { + throw new IllegalStateException( + String.format("Suite annotation was not found on %s class", testClass.getSimpleName())); + } + return suite; + } + + /** + * {@link Suite} and {@link SuiteProvider} internal descriptor. + */ + final static class SuiteDescriptor implements SuiteResolver, SuiteContext { + + // Helidon service loader for SuiteProvider instances + private static final HelidonServiceLoader LOADER = HelidonServiceLoader + .builder(ServiceLoader.load(SuiteProvider.class)) + .build(); + + private final SuiteProvider provider; + // Shared storage mapped to jUnit 5 global storage + private final Storage storage; + // Additional providers added by annotations on SuiteProvider class + private final Map, ProviderDescriptor> providers; + + private SuiteDescriptor(Suite suite, + SuiteProvider provider, + Map, ProviderDescriptor> providers, + ExtensionContext context) { + this.provider = provider; + // Isolate ExtensionContext.Store namespaces for individual providers (descriptors) + this.storage = new SuiteJunit5Storage( + context.getRoot().getStore( + ExtensionContext.Namespace.create(suite.value().getName()))); + this.providers = providers; + } + + @Override + public boolean supportsParameter(Type type) { + // SuiteProvider may also implement SuiteResolver + if (containsInterface(provider.getClass(), SuiteResolver.class) + && ((SuiteResolver)provider).supportsParameter(type)) { + return true; + } + // Always resolve SuiteContext as this + return SuiteContext.class.isAssignableFrom((Class)type); + } + + @Override + public Object resolveParameter(Type type) { + // SuiteProvider may also implement SuiteResolver + if (containsInterface(provider.getClass(), SuiteResolver.class) + && ((SuiteResolver)provider).supportsParameter(type)) { + return ((SuiteResolver)provider).resolveParameter(type); + } + // Always resolve SuiteContext as this + if (SuiteContext.class.isAssignableFrom((Class)type)) { + return this; + } + throw new IllegalArgumentException(String.format("Cannot resolve parameter Type %s", type.getTypeName())); + } + + // Resolve parameter globally (using suite provider and all suite extension providers) + private boolean supportsParameterGlobal(Class cls) { + if (supportsParameter(cls)) { + return true; + } + for (ProviderDescriptor provider : providers.values()) { + if (containsInterface(provider.provider().getClass(), SuiteResolver.class) + && ((SuiteResolver)provider.provider()).supportsParameter(cls)) { + return true; + } + } + return false; + } + + // Resolve parameter globally (using suite provider and all suite extension providers) + private Object resolveParameterGlobal(Class cls) { + if (supportsParameter(cls)) { + return resolveParameter(cls); + } + for (ProviderDescriptor provider : providers.values()) { + if (containsInterface(provider.provider().getClass(), SuiteResolver.class) + && ((SuiteResolver)provider.provider()).supportsParameter(cls)) { + return ((SuiteResolver)provider.provider()).resolveParameter(cls); + } + } + throw new IllegalArgumentException(String.format("Cannot resolve parameter Class %s", cls.getName())); + } + + @Override + public Storage storage() { + return storage; + } + + // Run suite initialization + private void init() { + // Pass suite context to all providers + provider.suiteContext(this); + providers.values().forEach(descriptor -> descriptor.provider().suiteContext(this)); + // Scan suite provider for method annotated for execution during initialization and startup phase + Method[] methods = provider.getClass().getMethods(); + Set added = new HashSet<>(); + List setUpConfig = new LinkedList<>(); + List setUpContainer = new LinkedList<>(); + List setUpDbClient = new LinkedList<>(); + List beforeSuite = new LinkedList<>(); + // Scan SuiteProvider methods for init annotations + for (Method method : methods) { + // @SetUpConfig annotated methods are called 1st + if (method.isAnnotationPresent(SetUpConfig.class)) { + if (!added.contains(method)) { + setUpConfig.add(method); + added.add(method); + } + } + // @SetUpContainer annotated methods are called 2nd + if (method.isAnnotationPresent(SetUpContainer.class)) { + if (!added.contains(method)) { + setUpContainer.add(method); + added.add(method); + } + } + // @SetUpDbClient annotated methods are called 3rd + if (method.isAnnotationPresent(SetUpDbClient.class)) { + if (!added.contains(method)) { + setUpDbClient.add(method); + added.add(method); + } + } + // @BeforeSuite annotated methods are called last + if (method.isAnnotationPresent(BeforeSuite.class)) { + if (!added.contains(method)) { + beforeSuite.add(method); + added.add(method); + } + } + } + initInternalProviders(); + setupConfig(setUpConfig); + setupContainer(setUpContainer); + setupDbClient(setUpDbClient); + // Run @BeforeSuite annotated method as last step + beforeSuite.forEach(this::callMethod); + } + + // Run suite cleanup + private void close() { + for (Method method : provider.getClass().getMethods()) { + if (method.isAnnotationPresent(AfterSuite.class)) { + callMethod(method); + } + } + closeContainer(); + } + + private void initInternalProviders() { + // TestConfig provider initialization + ProviderDescriptor testConfigProvider = providers.get(TestConfig.class); + if (testConfigProvider != null) { + TestConfig testConfig = provider.getClass().getAnnotation(TestConfig.class); + ConfigProvider configProvider = testConfigProvider.provider().as(ConfigProvider.class); + configProvider.file(testConfig.file()); + } + // ContainerTest provider initialization + ProviderDescriptor containerTestProvider = providers.get(ContainerTest.class); + if (containerTestProvider != null) { + ContainerTest containerTest = provider.getClass().getAnnotation(ContainerTest.class); + String image = containerTest.image(); + ContainerProvider containerProvider = containerTestProvider.provider().as(ContainerProvider.class); + containerProvider.image(image == null || image.isEmpty() ? Optional.empty() : Optional.of(image)); + } + } + + // Configuration is initialized first + private void setupConfig(List setUpConfig) { + // TestConfig provider setup + ProviderDescriptor descriptor = providers.get(TestConfig.class); + if (descriptor != null) { + ConfigProvider configProvider = descriptor.provider().as(ConfigProvider.class); + configProvider.setup(); + setUpConfig.forEach(method -> callSetUpConfig(method, descriptor)); + configProvider.start(); + } else { + setUpConfig.forEach(this::callMethod); + } + } + + // Container is initialized second + private void setupContainer(List setUpContainer) { + ProviderDescriptor descriptor = providers.get(ContainerTest.class); + if (descriptor != null) { + ContainerProvider containerProvider = descriptor.provider().as(ContainerProvider.class); + containerProvider.setup(); + setUpContainer.forEach(method -> callSetUpContainer(method, descriptor)); + containerProvider.start(); + } else { + setUpContainer.forEach(this::callMethod); + } + } + + // Container is the only one being closed + private void closeContainer() { + ProviderDescriptor descriptor = providers.get(ContainerTest.class); + if (descriptor != null) { + ContainerProvider containerProvider = descriptor.provider().as(ContainerProvider.class); + containerProvider.stop(); + } + } + + // DbClient is initialized third + private void setupDbClient(List setUpDbClient) { + ProviderDescriptor descriptor = providers.get(DbClientTest.class); + if (descriptor != null) { + DbClientProvider containerProvider = descriptor.provider().as(DbClientProvider.class); + containerProvider.setup(); + setUpDbClient.forEach(method -> callSetUpDbClient(method, descriptor)); + containerProvider.start(); + } else { + setUpDbClient.forEach(this::callMethod); + } + } + + // Call @SetUpConfig annotated method with additional Config.Builder resolver + private void callSetUpConfig(Method method, ProviderDescriptor descriptor) { + Type[] types = method.getGenericParameterTypes(); + int count = method.getParameterCount(); + Object[] parameters = new Object[count]; + for (int i = 0; i < count; i++) { + parameters[i] = resolveSetUpConfigParameter(types[i], descriptor); + } + invoke(method, parameters); + } + + // Call @SetUpContainer annotated method with additional ContainerConfig.Builder resolver + private void callSetUpContainer(Method method, ProviderDescriptor descriptor) { + Type[] types = method.getGenericParameterTypes(); + int count = method.getParameterCount(); + Object[] parameters = new Object[count]; + for (int i = 0; i < count; i++) { + parameters[i] = resolveSetUpContainerParameter(types[i], descriptor); + } + invoke(method, parameters); + } + + // Call @SetUpDbClient annotated method with additional DbClient.Builder resolver + private void callSetUpDbClient(Method method, ProviderDescriptor descriptor) { + Type[] types = method.getGenericParameterTypes(); + int count = method.getParameterCount(); + Object[] parameters = new Object[count]; + for (int i = 0; i < count; i++) { + parameters[i] = resolveSetUpDbClientParameter(types[i], descriptor); + } + invoke(method, parameters); + } + + // Extended resolver for @SetUpConfig annotated method + private Object resolveSetUpConfigParameter(Type type, ProviderDescriptor configProvider) { + // Resolver exception for Config.Builder which must be supplied by ConfigProvider's builder getter + if (configProvider != null + && Config.Builder.class.isAssignableFrom((Class)type)) { + return configProvider.provider().as(ConfigProvider.class).builder(); + } + return resolve(type); + } + + // Extended resolver for @SetUpContainer annotated method + private Object resolveSetUpContainerParameter(Type type, ProviderDescriptor containerProvider) { + // Resolver exception for Config.Builder which must be supplied by ConfigProvider's builder getter + if (containerProvider != null + && ContainerConfig.Builder.class.isAssignableFrom((Class)type)) { + return containerProvider.provider().as(ContainerProvider.class).builder(); + } + return resolve(type); + } + + // Extended resolver for @SetUpDbClient annotated method + private Object resolveSetUpDbClientParameter(Type type, ProviderDescriptor containerProvider) { + // Resolver exception for Config.Builder which must be supplied by ConfigProvider's builder getter + if (containerProvider != null + && DbClient.Builder.class.isAssignableFrom((Class)type)) { + return containerProvider.provider().as(DbClientProvider.class).builder(); + } + return resolve(type); + } + + /** + * Call method with resolved parameters. + * + * @param method method handler + */ + private void callMethod(Method method) { + Type[] types = method.getGenericParameterTypes(); + int count = method.getParameterCount(); + Object[] parameters = new Object[count]; + for (int i = 0; i < count; i++) { + parameters[i] = resolve(types[i]); + } + invoke(method, parameters); + } + + // Resolve single method parameter + private Object resolve(Type type) { + Function resolver = null; + // Suite resolver + if (supportsParameter(type)) { + resolver = this::resolveParameter; + } else { + for (ProviderDescriptor provider : providers.values()) { + if (containsInterface(provider.provider().getClass(), SuiteResolver.class) + && ((SuiteResolver) provider.provider()).supportsParameter(type)) { + resolver = ((SuiteResolver) provider.provider())::resolveParameter; + break; + } + } + } + if (resolver != null) { + return resolver.apply(type); + } else { + throw new IllegalArgumentException( + String.format("Cannot resolve parameter Type %s", type.getTypeName())); + } + } + + // Invoke provider's method + private void invoke(Method method, Object[] parameters) { + try { + method.invoke(provider, parameters); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException( + String.format("Could not invoke %s method %s", + provider.getClass().getSimpleName(), + method.getName()) + ,e); + } + } + + private static SuiteDescriptor create(Suite suite, ExtensionContext context) { + Class providerClass = suite.value(); + SuiteProvider provider = load(providerClass); + Map, ProviderDescriptor> providers = providers(providerClass); + return new SuiteDescriptor(suite, provider, providers, context); + } + + private static SuiteProvider load(Class providerClass) { + List loadedProviders = LOADER.stream() + .filter(providerClass::isInstance) + .toList(); + switch (loadedProviders.size()) { + case 0: + throw new IllegalStateException( + String.format("No SuiteProvider %s instance found on the classpath", + providerClass.getSimpleName())); + case 1: + return loadedProviders.getFirst(); + default: + throw new IllegalStateException( + String.format("Multiple SuiteProvider %s instances found on the classpath", + providerClass.getSimpleName())); + } + + } + + private static Map, ProviderDescriptor> providers ( + Class providerClass) { + Map, ProviderDescriptor> providers = new HashMap<>(); + for (Annotation annotation : providerClass.getAnnotations()) { + // Default supported annotation, use internal initialization + if (ProviderDescriptor.ANNOTATIONS.contains(annotation.annotationType())) { + if (annotation.annotationType().equals(TestConfig.class)) { + TestConfig testConfig = (TestConfig) annotation; + SuiteExtensionProvider provider = ProviderDescriptor.load(ConfigProvider.class, + testConfig.provider()); + providers.put(TestConfig.class, new ProviderDescriptor(provider)); + } + if (annotation.annotationType().equals(ContainerTest.class)) { + ContainerTest containerTest = (ContainerTest) annotation; + SuiteExtensionProvider provider = ProviderDescriptor.load(ContainerProvider.class, + containerTest.provider()); + providers.put(ContainerTest.class, new ProviderDescriptor(provider)); + } + if (annotation.annotationType().equals(DbClientTest.class)) { + DbClientTest dbClientTest = (DbClientTest) annotation; + SuiteExtensionProvider provider = ProviderDescriptor.load(DbClientProvider.class, + dbClientTest.provider()); + providers.put(DbClientTest.class, new ProviderDescriptor(provider)); + } + } + // External annotation, use ExternalInitializer + if (ProviderDescriptor.EXTERNAL_ANNOTATIONS.keySet().contains(annotation.annotationType())) { + ExternalInitializer initializer = ProviderDescriptor.EXTERNAL_ANNOTATIONS.get(annotation.annotationType()); + SuiteExtensionProvider provider = ProviderDescriptor.load(initializer.providerInterface(), + initializer.providerClass()); + providers.put(initializer.annotationClass(), new ProviderDescriptor(provider, Optional.of(initializer))); + } + } + return providers; + } + + // Search whether class or any of it's super class implements interface + private static boolean containsInterface(Class cls, Class interfaceCls) { + if (hasInterface(cls, interfaceCls)) { + return true; + } + Class superCls = cls.getSuperclass(); + while (superCls != null) { + if (hasInterface(superCls, interfaceCls)) { + return true; + } + superCls = superCls.getSuperclass(); + } + return false; + } + + + private static boolean hasInterface(Class cls, Class interfaceCls) { + Class[] interfaces = cls.getInterfaces(); + for (Class iface : interfaces) { + if (interfaceCls.equals(iface)) { + return true; + } + } + return false; + } + + } + + /** + * Additional {@link SuiteExtensionProvider} descriptors. + * Those are providers added by annotations on {@link SuiteProvider} class. + */ + final static class ProviderDescriptor { + + // Default supported annotations + private static final Set> ANNOTATIONS = Set.of( + TestConfig.class, + ContainerTest.class, + DbClientTest.class + ); + + // External registered annotations, not used in current version + private static final Map, + ExternalInitializer> EXTERNAL_ANNOTATIONS = new HashMap<>(); + + // Providers service loaders as Map of provider interface class to HelidonServiceLoader + private static final Map, + HelidonServiceLoader> LOADERS = new HashMap<>(); + + private final SuiteExtensionProvider provider; + + // External provider initializer, not used in current version + private final Optional initializer; + + private ProviderDescriptor(SuiteExtensionProvider provider) { + this(provider, Optional.empty()); + } + + private ProviderDescriptor(SuiteExtensionProvider provider, Optional initializer) { + this.provider = provider; + this.initializer = initializer; + } + + private SuiteExtensionProvider provider() { + return provider; + } + + /** + * Load additional {@link SuiteExtensionProvider} instance using service loader. + * + * @param providerInterface provider interface used in {@link HelidonServiceLoader} + * @param providerClass provider interface implementing class from {@link SuiteProvider} annotation + * @return loaded {@link SuiteExtensionProvider} instance + */ + private static SuiteExtensionProvider load(Class providerInterface, + Class providerClass) { + List loadedProviders = loader(providerInterface).stream() + .filter(providerClass::isInstance) + .toList(); + switch (loadedProviders.size()) { + case 0: + throw new IllegalStateException( + String.format("No Junit5ExtensionProvider %s instance found on the classpath", + providerClass.getSimpleName())); + case 1: + return loadedProviders.getFirst(); + default: + throw new IllegalStateException( + String.format("Multiple Junit5ExtensionProvider %s instances found on the classpath", + providerClass.getSimpleName())); + } + } + + private static HelidonServiceLoader loader(Class providerInterface) { + HelidonServiceLoader loader = LOADERS.get(providerInterface); + if (loader != null) { + return loader; + } else { + loader = HelidonServiceLoader + .builder(ServiceLoader.load(providerInterface)) + .build(); + LOADERS.put(providerInterface, loader); + return loader; + } + } + + } + + // Not used in current version + public interface ExternalInitializer { + Class annotationClass(); + Class providerInterface(); + Class providerClass(); + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteJunit5Storage.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteJunit5Storage.java new file mode 100644 index 00000000000..9f90f4744a2 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteJunit5Storage.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * {@link Suite} shared context storage mapped to jUnit 5 {@code GLOBAL} storage. + */ +public class SuiteJunit5Storage implements SuiteContext.Storage { + + // jUnit 5 GLOBAL storage + private final ExtensionContext.Store store; + + SuiteJunit5Storage(ExtensionContext.Store store) { + this.store = store; + } + + @Override + public T get(String key, Class cls) { + return store.get(key, cls); + } + + @Override + public T getOrDefault(String key, Class cls, T defaultValue) { + return store.getOrDefault(key, cls, defaultValue); + } + + @Override + public void putOrReplace(String key, Object value) { + if (store.get(key) != null) { + store.remove(key); + } + store.put(key, value); + } + + @Override + public void put(String key, Object value) { + store.put(key, value); + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteResolver.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteResolver.java new file mode 100644 index 00000000000..899f40c6087 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/SuiteResolver.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.reflect.Type; + +/** + * {@link SuiteResolver} defines API for suite extension providers + * to dynamically resolve arguments for constructors and methods at runtime. + */ +public interface SuiteResolver { + + /** + * Determine if this resolver supports resolving of provided parameter {@link Type}. + * + * @param type parameter {@link Type} to check + * @return value of {@code true} if this resolver supports provided type or {@code false} otherwise + */ + boolean supportsParameter(Type type); + + /** + * Resolve parameter of provided parameter {@link Type}. + * This method is only called if {@link #supportsParameter(Type)} previously returned {@code true} + * for the same {@link Type}. + * @param type {@link Type} of the parameter to resolve + * @return resolved parameter value + */ + Object resolveParameter(Type type); + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/TestConfig.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/TestConfig.java new file mode 100644 index 00000000000..ec5e23cc133 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/TestConfig.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023, 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.junit5; + +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 io.helidon.tests.integration.junit5.spi.ConfigProvider; + +/** + * Test {@link Suite} that requires configuration. + * Configuration is read from specified file on the classpath. Configuration may be optionally + * stored into {@link SuiteContext#storage()}. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface TestConfig { + + /** + * Test config provider class. + * Default value is {@link DefaultConfigProvider}.class + * + * @return config provider class + */ + Class provider() default DefaultConfigProvider.class; + + + /** + * Test config provider configuration file. + * Default value is {@code "test.yaml"} + * + * @return config file to read from classpath + */ + String file() default "test.yaml"; + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/ConfigProvider.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/ConfigProvider.java new file mode 100644 index 00000000000..a3a7581eec9 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/ConfigProvider.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023, 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.junit5.spi; + +import io.helidon.config.Config; +import io.helidon.tests.integration.junit5.SuiteExtensionProvider; + +/** + * Helidon integration tests configuration provider. + */ +public interface ConfigProvider extends SuiteExtensionProvider { + + /** + * Config file name from {@link io.helidon.tests.integration.junit5.TestConfig} + * annotation. + * + * @param file config file name to read from classpath + */ + void file(String file); + + /** + * Build configuration builder with default initial values. + */ + void setup(); + + /** + * Provide config builder to be used in setup hook. + * + * @return configuration builder with values from provided file. + */ + Config.Builder builder(); + + /** + * Start the existence of Config. + */ + void start(); + + /** + * Provide root {@link Config} instance for the tests. + */ + Config config(); + + /** + * Cast {@link io.helidon.tests.integration.junit5.SuiteExtensionProvider} as {@link ConfigProvider}. + * Implementing class should override this method and add itself. + * + * @param cls {@link io.helidon.tests.integration.junit5.SuiteExtensionProvider} child interface or implementing class + * @return this instance cast to {@link ConfigProvider} and optionally implementing class + * @param target casting type + */ + @Override + default T as(Class cls) { + if (cls == ConfigProvider.class) { + return cls.cast(this); + } + throw new IllegalArgumentException( + String.format("Cannot cast this ConfigProvider implementation as %s", cls.getName())); + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/ContainerProvider.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/ContainerProvider.java new file mode 100644 index 00000000000..72a0a8c2764 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/ContainerProvider.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2023, 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.junit5.spi; + +import java.util.Optional; + +import io.helidon.tests.integration.junit5.ContainerConfig; +import io.helidon.tests.integration.junit5.SuiteExtensionProvider; + +/** + * Helidon Database Client integration tests Docker container provider interface. + */ +public interface ContainerProvider extends SuiteExtensionProvider { + + /** + * Docker image from {@link io.helidon.tests.integration.junit5.ContainerTest} annotation. + * This method is called during {@link ContainerProvider} initialization phase. + * Implementing class must store this value and handle it properly. + * + * @param image name of the Docker image including label or {@link Optional#empty()} when not defined + */ + void image(Optional image); + + /** + * Build docker container configuration. + * Default container configuration must be set in this method. + * + * @return docker container configuration builder with default configuration set + */ + void setup(); + + /** + * Docker container configuration builder with default configuration set. + * This is the {@link ContainerConfig.Builder} instance passed + * to {@link io.helidon.tests.integration.junit5.SetUpContainer} annotated method + * in related {@link SuiteProvider} implementing class. + * + * @return container configuration builder with default configuration + */ + ContainerConfig.Builder builder(); + + /** + * Start Docker container. + * Calling this method may change provided value of Docker container configuration. + */ + void start(); + + /** + * Stop Docker container. + */ + void stop(); + + /** + * Cast {@link io.helidon.tests.integration.junit5.SuiteExtensionProvider} as {@link ContainerProvider}. + * Implementing class should override this method and add itself. + * + * @param cls {@link io.helidon.tests.integration.junit5.SuiteExtensionProvider} child interface or implementing class + * @return this instance cast to {@link ContainerProvider} and optionally implementing class + * @param target casting type + */ + @Override + default T as(Class cls) { + if (cls == ContainerProvider.class) { + return cls.cast(this); + } + throw new IllegalArgumentException( + String.format("Cannot cast this ContainerProvider implementation as %s", cls.getName())); + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/DbClientProvider.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/DbClientProvider.java new file mode 100644 index 00000000000..4f91dcef609 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/DbClientProvider.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023, 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.junit5.spi; + +import io.helidon.dbclient.DbClient; +import io.helidon.tests.integration.junit5.SuiteExtensionProvider; + +/** + * Helidon Database Client integration tests configuration provider interface. + */ +public interface DbClientProvider extends SuiteExtensionProvider { + + /** + * Build configuration builder with default initial values. + */ + void setup(); + + /** + * Provide config builder to be used in setup hook. + * + * @return configuration builder with values from provided file. + */ + DbClient.Builder builder(); + + /** + * Start the existence of {@link DbClient}. + */ + void start(); + + /** + * Provide root {@link DbClient} instance for the tests. + */ + DbClient dbClient(); + + /** + * Cast {@link io.helidon.tests.integration.junit5.SuiteExtensionProvider} as {@link DbClientProvider}. + * Implementing class should override this method and add itself. + * + * @param cls {@link io.helidon.tests.integration.junit5.SuiteExtensionProvider} child interface or implementing class + * @return this instance cast to {@link DbClientProvider} and optionally implementing class + * @param target casting type + */ + @Override + default T as(Class cls) { + if (cls == DbClientProvider.class) { + return cls.cast(this); + } + throw new IllegalArgumentException( + String.format("Cannot cast this DbClientProvider implementation as %s", cls.getName())); + } + +} diff --git a/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/SuiteProvider.java b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/SuiteProvider.java new file mode 100644 index 00000000000..10982037496 --- /dev/null +++ b/tests/integration/junit5/src/main/java/io/helidon/tests/integration/junit5/spi/SuiteProvider.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023, 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.junit5.spi; + +import io.helidon.tests.integration.junit5.SuiteExtensionProvider; + +/** + * Helidon integration tests suite provider. + */ +public interface SuiteProvider extends SuiteExtensionProvider { + + /** + * Cast {@link io.helidon.tests.integration.junit5.SuiteExtensionProvider} as {@link SuiteProvider}. + * Implementing class should override this method and add itself. + * + * @param cls {@link io.helidon.tests.integration.junit5.SuiteExtensionProvider} child interface or implementing class + * @return this instance cast to {@link SuiteProvider} and optionally implementing class + * @param target casting type + */ + @Override + default T as(Class cls) { + if (cls == SuiteProvider.class) { + return cls.cast(this); + } + throw new IllegalArgumentException( + String.format("Cannot cast this SuiteProvider implementation as %s", cls.getName())); + } + +} diff --git a/tests/integration/junit5/src/main/java/module-info.java b/tests/integration/junit5/src/main/java/module-info.java new file mode 100644 index 00000000000..1642d0a1b01 --- /dev/null +++ b/tests/integration/junit5/src/main/java/module-info.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +import io.helidon.tests.integration.junit5.DefaultDbClientProvider; + +/** + * Helidon Integration Tests jUnit5 Extension. + */ +module io.helidon.tests.integration.junit5 { + + requires org.junit.jupiter.api; + requires testcontainers; + + requires io.helidon.builder.api; + requires io.helidon.common; + requires io.helidon.config; + requires io.helidon.config.metadata; + requires io.helidon.dbclient; + + exports io.helidon.tests.integration.junit5; + exports io.helidon.tests.integration.junit5.spi; + + uses io.helidon.tests.integration.junit5.spi.SuiteProvider; + uses io.helidon.tests.integration.junit5.spi.ConfigProvider; + uses io.helidon.tests.integration.junit5.spi.ContainerProvider; + + provides io.helidon.tests.integration.junit5.spi.ConfigProvider + with io.helidon.tests.integration.junit5.DefaultConfigProvider; + provides io.helidon.tests.integration.junit5.spi.ContainerProvider + with io.helidon.tests.integration.junit5.MySqlContainer, + io.helidon.tests.integration.junit5.PgSqlContainer; + provides io.helidon.tests.integration.junit5.spi.DbClientProvider + with DefaultDbClientProvider; + +} diff --git a/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/ConfigSuite.java b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/ConfigSuite.java new file mode 100644 index 00000000000..8432f5b5cc2 --- /dev/null +++ b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/ConfigSuite.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.util.Map; + +import io.helidon.config.Config; +import io.helidon.config.ConfigSources; +import io.helidon.tests.integration.junit5.spi.SuiteProvider; + +@TestConfig +public class ConfigSuite implements SuiteProvider { + + private static final Logger LOGGER = System.getLogger(ConfigSuite.class.getName()); + + final static String BEFORE_KEY = "ConfigSuite.before"; + final static String AFTER_KEY = "ConfigSuite.after"; + final static String SETUP_CONFIG_KEY = "ConfigSuite.config"; + + private SuiteContext suiteContext; + + private int counter; + + public ConfigSuite() { + suiteContext = null; + counter = 1; + } + + // Store shared suite context when passed from suite initialization + @Override + public void suiteContext(SuiteContext suiteContext) { + this.suiteContext = suiteContext; + } + + // Validate that @BeforeSuite is executed + @BeforeSuite + public void beforeSuite() { + LOGGER.log(Level.TRACE, + String.format("Running beforeSuite of ConfigSuite test class, order %d", counter)); + suiteContext.storage().put(BEFORE_KEY, counter++); + } + + // Validate that @AfterSuite is executed + @AfterSuite + public void afterSuite() { + LOGGER.log(Level.TRACE, + String.format("Running afterSuite of ConfigSuite test class, order %d", counter)); + suiteContext.storage().put(AFTER_KEY, counter); + } + + @SetUpConfig + public void setupConfig(Config.Builder builder) { + LOGGER.log(Level.TRACE, + String.format("Running setupConfig of ConfigSuite test class, order %d", counter)); + // Modify target Config content with additional node + builder.addSource(ConfigSources.create(Map.of("id", "TEST"))); + suiteContext.storage().put(SETUP_CONFIG_KEY, counter++); + } + +} diff --git a/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/MySqlSuite.java b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/MySqlSuite.java new file mode 100644 index 00000000000..862a3c28748 --- /dev/null +++ b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/MySqlSuite.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.util.HashMap; +import java.util.Map; + +import io.helidon.config.Config; +import io.helidon.config.ConfigSources; +import io.helidon.dbclient.DbClient; +import io.helidon.tests.integration.junit5.spi.SuiteProvider; + +@DbClientTest +@TestConfig(file = "mysql.yaml") +@ContainerTest(provider = MySqlContainer.class, image = "mysql:8.0") +public class MySqlSuite implements SuiteProvider { + + private static final Logger LOGGER = System.getLogger(MySqlSuite.class.getName()); + + static final String BEFORE_KEY = "MySqlSuite.before"; + static final String AFTER_KEY = "MySqlSuite.after"; + static final String SETUP_CONFIG_KEY = "MySqlSuite.config"; + static final String SETUP_CONTAINER_KEY = "MySqlSuite.container"; + static final String SETUP_DBCLIENT_KEY = "MySqlSuite.dbClient"; + + static final String DB_NODE = "db"; + + private SuiteContext suiteContext; + private int counter; + + public MySqlSuite() { + suiteContext = null; + counter = 1; + } + + // Store shared suite context when passed from suite initialization + @Override + public void suiteContext(SuiteContext suiteContext) { + this.suiteContext = suiteContext; + } + + @SetUpConfig + public void setupConfig(Config.Builder builder) { + LOGGER.log(Level.TRACE, + () -> String.format("Running setupConfig of MySqlSuite test class, order %d", counter)); + // Modify target Config content with additional node + builder.addSource(ConfigSources.create(Map.of("id", "TEST"))); + suiteContext.storage().put(SETUP_CONFIG_KEY, counter++); + } + + @SetUpContainer + public void setupContainer(Config config, SuiteContext context, DatabaseContainerConfig.Builder dbConfigBuilder, ContainerConfig.Builder builder) { + LOGGER.log(Level.TRACE, + () -> String.format("Running setupContainer of MySqlSuite test class, order %d", counter)); + config.get(DB_NODE + ".connection").asNode().ifPresent(dbConfigBuilder::dbClient); + // Modify target ContainerConfig content with additional system variable + builder.environment().put("MY_VARIABLE", "myValue"); + suiteContext.storage().put(SETUP_CONTAINER_KEY, counter++); + } + + @SetUpDbClient + public void setupDbClient(Config config, SuiteContext context, ContainerInfo info, DbClient.Builder builder) { + LOGGER.log(Level.TRACE, + () -> String.format("Running setupDbClient of MySqlSuite test class, order %d", counter)); + Map updatedNodes = new HashMap<>(1); + config.get(DB_NODE + ".connection.url").as(String.class).ifPresent(value -> updatedNodes.put( + DB_NODE + ".connection.url", + DatabaseContainer.replacePortInUrl( + value, + info.portMappings().get(info.config().exposedPorts()[0])))); + Config updatedConfig = Config.create(ConfigSources.create(updatedNodes), ConfigSources.create(config)); + builder.config(updatedConfig.get("db")); + // Validate order of provider's methods execution + suiteContext.storage().put(SETUP_DBCLIENT_KEY, counter++); + } + + // Initialize database schema and data + // Validate that @BeforeSuite is executed + @BeforeSuite + public void beforeSuite(DbClient dbClient) { + LOGGER.log(Level.TRACE, + () -> String.format("Running beforeSuite of MySqlSuite test class, order %d", counter)); + // Database initialization goes here + // Validate order of provider's methods execution + suiteContext.storage().put(BEFORE_KEY, counter++); + } + + // Validate that @AfterSuite is executed + @AfterSuite + public void afterSuite() { + LOGGER.log(Level.TRACE, + () -> String.format("Running afterSuite of MySqlSuite test class, order %d", counter)); + suiteContext.storage().put(AFTER_KEY, counter); + } + +} diff --git a/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/PgSqlSuite.java b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/PgSqlSuite.java new file mode 100644 index 00000000000..6be976cad62 --- /dev/null +++ b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/PgSqlSuite.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.util.HashMap; +import java.util.Map; + +import io.helidon.config.Config; +import io.helidon.config.ConfigSources; +import io.helidon.dbclient.DbClient; +import io.helidon.tests.integration.junit5.spi.SuiteProvider; + +@DbClientTest +@TestConfig(file = "pgsql.yaml") +@ContainerTest(provider = PgSqlContainer.class, image = "postgres:16.0") +public class PgSqlSuite implements SuiteProvider { + + private static final Logger LOGGER = System.getLogger(PgSqlSuite.class.getName()); + + static final String BEFORE_KEY = "PgSqlSuite.before"; + static final String AFTER_KEY = "PgSqlSuite.after"; + static final String SETUP_CONFIG_KEY = "PgSqlSuite.config"; + static final String SETUP_CONTAINER_KEY = "PgSqlSuite.container"; + static final String SETUP_DBCLIENT_KEY = "PgSqlSuite.dbClient"; + + static final String DB_NODE = "db"; + + private SuiteContext suiteContext; + private int counter; + + public PgSqlSuite() { + suiteContext = null; + counter = 1; + } + + // Store shared suite context when passed from suite initialization + @Override + public void suiteContext(SuiteContext suiteContext) { + this.suiteContext = suiteContext; + } + + @SetUpConfig + public void setupConfig(Config.Builder builder) { + LOGGER.log(Level.TRACE, + () -> String.format("Running setupConfig of PgSqlSuite test class, order %d", counter)); + // Modify target Config content with additional node + builder.addSource(ConfigSources.create(Map.of("id", "TEST"))); + suiteContext.storage().put(SETUP_CONFIG_KEY, counter++); + } + + @SetUpContainer + public void setupContainer(Config config, SuiteContext context, DatabaseContainerConfig.Builder dbConfigBuilder, ContainerConfig.Builder builder) { + LOGGER.log(Level.TRACE, + () -> String.format("Running setupContainer of PgSqlSuite test class, order %d", counter)); + config.get(DB_NODE + ".connection").asNode().ifPresent(dbConfigBuilder::dbClient); + // Modify target ContainerConfig content with additional system variable + builder.environment().put("MY_VARIABLE", "myValue"); + suiteContext.storage().put(SETUP_CONTAINER_KEY, counter++); + } + + @SetUpDbClient + public void setupDbClient(Config config, SuiteContext context, ContainerInfo info, DbClient.Builder builder) { + LOGGER.log(Level.TRACE, + () -> String.format("Running setupDbClient of PgSqlSuite test class, order %d", counter)); + Map updatedNodes = new HashMap<>(1); + config.get(DB_NODE + ".connection.url").as(String.class).ifPresent(value -> updatedNodes.put( + DB_NODE + ".connection.url", + DatabaseContainer.replacePortInUrl( + value, + info.portMappings().get(info.config().exposedPorts()[0])))); + Config updatedConfig = Config.create(ConfigSources.create(updatedNodes), ConfigSources.create(config)); + builder.config(updatedConfig.get("db")); + // Validate order of provider's methods execution + suiteContext.storage().put(SETUP_DBCLIENT_KEY, counter++); + } + + // Initialize database schema and data + // Validate that @BeforeSuite is executed + @BeforeSuite + public void beforeSuite(DbClient dbClient) { + LOGGER.log(Level.TRACE, + () -> String.format("Running beforeSuite of PgSqlSuite test class, order %d", counter)); + // Database initialization goes here + // Validate order of provider's methods execution + suiteContext.storage().put(BEFORE_KEY, counter++); + } + + // Validate that @AfterSuite is executed + @AfterSuite + public void afterSuite() { + LOGGER.log(Level.TRACE, + () -> String.format("Running afterSuite of PgSqlSuite test class, order %d", counter)); + suiteContext.storage().put(AFTER_KEY, counter); + } + +} diff --git a/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/SimpleSuite.java b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/SimpleSuite.java new file mode 100644 index 00000000000..fdedf354ef0 --- /dev/null +++ b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/SimpleSuite.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import java.lang.System.Logger; +import java.lang.System.Logger.Level; + +import io.helidon.tests.integration.junit5.spi.SuiteProvider; + +/** + * Simple test suite to validate basic life-cycle. + */ +public class SimpleSuite implements SuiteProvider { + + private static final Logger LOGGER = System.getLogger(SimpleSuite.class.getName()); + + final static String BEFORE_KEY = "SimpleSuite.before"; + final static String AFTER_KEY = "SimpleSuite.after"; + final static String SETUP_CONFIG_KEY = "SimpleSuite.config"; + final static String SETUP_CONTAINER_KEY = "SimpleSuite.container"; + + private SuiteContext suiteContext; + private int counter; + + public SimpleSuite() { + suiteContext = null; + counter = 1; + } + + // Store shared suite context when passed from suite initialization + @Override + public void suiteContext(SuiteContext suiteContext) { + this.suiteContext = suiteContext; + } + + // Validate that @BeforeSuite is executed + @BeforeSuite + public void beforeSuite() { + LOGGER.log(Level.TRACE, + () -> String.format("Running beforeSuite of SimpleSuite test class, order %d", counter)); + suiteContext.storage().put(BEFORE_KEY, counter++); + } + + // Validate that @AfterSuite is executed + @AfterSuite + public void afterSuite() { + LOGGER.log(Level.TRACE, + () -> String.format("Running afterSuite of SimpleSuite test class, order %d", counter)); + suiteContext.storage().put(AFTER_KEY, counter); + } + + @SetUpConfig + public void setupConfig() { + LOGGER.log(Level.TRACE, + () -> String.format("Running setupConfig of SimpleSuite test class, order %d", counter)); + suiteContext.storage().put(SETUP_CONFIG_KEY, counter++); + } + + @SetUpContainer + public void setupContainer() { + LOGGER.log(Level.TRACE, + () -> String.format("Running setupContainer of SimpleSuite test class, order %d", counter)); + suiteContext.storage().put(SETUP_CONTAINER_KEY, counter++); + } + +} diff --git a/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestConfigSuite.java b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestConfigSuite.java new file mode 100644 index 00000000000..fd287038038 --- /dev/null +++ b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestConfigSuite.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import io.helidon.config.Config; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +@Suite(ConfigSuite.class) +public class TestConfigSuite { + + private final SuiteContext suiteContext; + private final Config config; + + public TestConfigSuite(SuiteContext suiteContext, Config config) { + this.suiteContext = suiteContext; + this.config = config; + } + + @Test + public void testInitializationOrder() { + assertThat(suiteContext, notNullValue()); + assertThat(suiteContext.storage().get(ConfigSuite.SETUP_CONFIG_KEY, Integer.class), is(1)); + assertThat(suiteContext.storage().get(ConfigSuite.BEFORE_KEY, Integer.class), is(2)); + } + + @Test + public void testResolvedConfig(Config config) { + assertThat(config.get("name").asString().isPresent(), is(true)); + assertThat(config.get("name").asString().get(), is("test")); + assertThat(config.get("id").asString().isPresent(), is(true)); + assertThat(config.get("id").asString().get(), is("TEST")); + } + + @Test + public void testConfigFromConstructor() { + assertThat(config.get("name").asString().isPresent(), is(true)); + assertThat(config.get("name").asString().get(), is("test")); + assertThat(config.get("id").asString().isPresent(), is(true)); + assertThat(config.get("id").asString().get(), is("TEST")); + } + + @Test + public void testStoredConfig(Config config) { + assertThat(config, notNullValue()); + assertThat(config.get("name").asString().isPresent(), is(true)); + assertThat(config.get("name").asString().get(), is("test")); + assertThat(config.get("id").asString().isPresent(), is(true)); + assertThat(config.get("id").asString().get(), is("TEST")); + } + +} diff --git a/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestMySqlSuite.java b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestMySqlSuite.java new file mode 100644 index 00000000000..40f84109324 --- /dev/null +++ b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestMySqlSuite.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import io.helidon.config.Config; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +@Suite(MySqlSuite.class) +public class TestMySqlSuite { + + private final SuiteContext suiteContext; + private final Config config; + + public TestMySqlSuite(SuiteContext suiteContext, Config config) { + this.suiteContext = suiteContext; + this.config = config; + } + + @Test + public void testInitializationOrder() { + assertThat(suiteContext, notNullValue()); + assertThat(suiteContext.storage().get(MySqlSuite.SETUP_CONFIG_KEY, Integer.class), is(1)); + assertThat(suiteContext.storage().get(MySqlSuite.SETUP_CONTAINER_KEY, Integer.class), is(2)); + assertThat(suiteContext.storage().get(MySqlSuite.SETUP_DBCLIENT_KEY, Integer.class), is(3)); + assertThat(suiteContext.storage().get(MySqlSuite.BEFORE_KEY, Integer.class), is(4)); + } + + @Test + public void testConfigFromConstructor() { + assertThat(config.get("db").asNode().isPresent(), is(true)); + assertThat(config.get("id").asString().isPresent(), is(true)); + assertThat(config.get("id").asString().get(), is("TEST")); + } + +} diff --git a/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestPgSqlSuite.java b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestPgSqlSuite.java new file mode 100644 index 00000000000..253580b7e1a --- /dev/null +++ b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestPgSqlSuite.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import io.helidon.config.Config; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +@Suite(PgSqlSuite.class) +public class TestPgSqlSuite { + + private final SuiteContext suiteContext; + private final Config config; + + public TestPgSqlSuite(SuiteContext suiteContext, Config config) { + this.suiteContext = suiteContext; + this.config = config; + } + + @Test + public void testInitializationOrder() { + assertThat(suiteContext, notNullValue()); + assertThat(suiteContext.storage().get(PgSqlSuite.SETUP_CONFIG_KEY, Integer.class), is(1)); + assertThat(suiteContext.storage().get(PgSqlSuite.SETUP_CONTAINER_KEY, Integer.class), is(2)); + assertThat(suiteContext.storage().get(PgSqlSuite.SETUP_DBCLIENT_KEY, Integer.class), is(3)); + assertThat(suiteContext.storage().get(PgSqlSuite.BEFORE_KEY, Integer.class), is(4)); + } + + @Test + public void testConfigFromConstructor() { + assertThat(config.get("db").asNode().isPresent(), is(true)); + assertThat(config.get("id").asString().isPresent(), is(true)); + assertThat(config.get("id").asString().get(), is("TEST")); + } + +} diff --git a/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestSimpleSuite.java b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestSimpleSuite.java new file mode 100644 index 00000000000..aedd16db9fc --- /dev/null +++ b/tests/integration/junit5/src/test/java/io/helidon/tests/integration/junit5/TestSimpleSuite.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023, 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.junit5; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +@Suite(SimpleSuite.class) +public class TestSimpleSuite { + + private final SuiteContext suiteContext; + + public TestSimpleSuite(SuiteContext suiteContext) { + this.suiteContext = suiteContext; + } + + // Validate that shared suite context is set and @BeforeSuite, @SetUpConfig and @SetUpContainer + // annotated method were executed in proper order + @Test + public void testBeforeSuite() { + assertThat(suiteContext, notNullValue()); + assertThat(suiteContext.storage().get(SimpleSuite.SETUP_CONFIG_KEY, Integer.class), is(1)); + assertThat(suiteContext.storage().get(SimpleSuite.SETUP_CONTAINER_KEY, Integer.class), is(2)); + assertThat(suiteContext.storage().get(SimpleSuite.BEFORE_KEY, Integer.class), is(3)); + } + +} diff --git a/tests/integration/junit5/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider b/tests/integration/junit5/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider new file mode 100644 index 00000000000..312a579bf74 --- /dev/null +++ b/tests/integration/junit5/src/test/resources/META-INF/services/io.helidon.tests.integration.junit5.spi.SuiteProvider @@ -0,0 +1,20 @@ +# +# Copyright (c) 2023, 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. +# + +io.helidon.tests.integration.junit5.SimpleSuite +io.helidon.tests.integration.junit5.ConfigSuite +io.helidon.tests.integration.junit5.MySqlSuite +io.helidon.tests.integration.junit5.PgSqlSuite diff --git a/tests/integration/dbclient/app/src/main/resources/logging.properties b/tests/integration/junit5/src/test/resources/logging-test.properties similarity index 55% rename from tests/integration/dbclient/app/src/main/resources/logging.properties rename to tests/integration/junit5/src/test/resources/logging-test.properties index e1b27ef2055..1d56f633f64 100644 --- a/tests/integration/dbclient/app/src/main/resources/logging.properties +++ b/tests/integration/junit5/src/test/resources/logging-test.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2020, 2023 Oracle and/or its affiliates. +# Copyright (c) 2023, 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,13 +13,10 @@ # 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 +handlers=java.util.logging.ConsoleHandler +java.util.logging.ConsoleHandler.level=FINEST +java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter +java.util.logging.SimpleFormatter.format=%1$tH:%1$tM:%1$tS %4$s %3$s %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 +.level=INFO +io.helidon.tests.integration.junit5.level=FINEST diff --git a/tests/integration/junit5/src/test/resources/mysql.yaml b/tests/integration/junit5/src/test/resources/mysql.yaml new file mode 100644 index 00000000000..be076ece246 --- /dev/null +++ b/tests/integration/junit5/src/test/resources/mysql.yaml @@ -0,0 +1,25 @@ +# +# Copyright (c) 2023, 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://127.0.0.1:3306/dbclient?useSSL=false&allowPublicKeyRetrieval=true + username: user + password: p4ssw0rd + health-check: + type: query + statement: "SELECT 0" + statements: diff --git a/tests/integration/junit5/src/test/resources/pgsql.yaml b/tests/integration/junit5/src/test/resources/pgsql.yaml new file mode 100644 index 00000000000..80f77e6c7bf --- /dev/null +++ b/tests/integration/junit5/src/test/resources/pgsql.yaml @@ -0,0 +1,25 @@ +# +# Copyright (c) 2023, 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://127.0.0.1:5432/dbclient + username: user + password: p4ssw0rd + health-check: + type: query + statement: "SELECT 0" + statements: diff --git a/tests/integration/dbclient/app/src/main/resources/common.yaml b/tests/integration/junit5/src/test/resources/test.yaml similarity index 86% rename from tests/integration/dbclient/app/src/main/resources/common.yaml rename to tests/integration/junit5/src/test/resources/test.yaml index a9d5230bb30..412ea571533 100644 --- a/tests/integration/dbclient/app/src/main/resources/common.yaml +++ b/tests/integration/junit5/src/test/resources/test.yaml @@ -1,5 +1,5 @@ # -# Copyright (c) 2023 Oracle and/or its affiliates. +# Copyright (c) 2023, 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,4 @@ # limitations under the License. # -server: - port: 0 - host: 0.0.0.0 +name: test diff --git a/tests/integration/oidc/.helidon-oidc-secret b/tests/integration/oidc/.helidon-oidc-secret new file mode 100644 index 00000000000..dd06a158a67 --- /dev/null +++ b/tests/integration/oidc/.helidon-oidc-secret @@ -0,0 +1 @@ +9108dc0b-f309-48d0-bc0e-50c0391692bb \ No newline at end of file diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml index 128661f8593..e3ee9431b30 100644 --- a/tests/integration/pom.xml +++ b/tests/integration/pom.xml @@ -38,7 +38,7 @@ config - dbclient + junit5 harness health jep290