From ae9a927c6f1b4147bf34b354dbfe4686a6cfcf61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kraus?= Date: Fri, 30 Sep 2022 16:44:50 +0200 Subject: [PATCH 1/2] Issue 4740 - JPA integration tests should run on every build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Kraus --- tests/integration/jpa/appl/pom.xml | 112 ++++++++---------- .../tests/integration/jpa/appl/JdbcApiIT.java | 8 +- .../tests/integration/jpa/appl/UpdateIT.java | 3 +- .../src/main/resources/hibernate.properties | 3 +- .../jpa/appl/test/LifeCycleExtension.java | 8 +- .../tests/integration/jpa/model/Pokemon.java | 13 +- .../integration/jpa/model/Settlement.java | 5 +- .../tests/integration/jpa/model/Stadium.java | 10 +- .../tests/integration/jpa/model/Trainer.java | 10 +- tests/integration/jpa/pom.xml | 68 +++++++++++ tests/integration/jpa/simple/pom.xml | 24 +++- .../integration/jpa/simple/test/UpdateIT.java | 3 +- .../jpa/src/main/resources/h2.properties | 23 ++++ tests/integration/pom.xml | 2 +- 14 files changed, 182 insertions(+), 110 deletions(-) create mode 100644 tests/integration/jpa/src/main/resources/h2.properties diff --git a/tests/integration/jpa/appl/pom.xml b/tests/integration/jpa/appl/pom.xml index 9d4a5ec28a0..b21fc680a29 100644 --- a/tests/integration/jpa/appl/pom.xml +++ b/tests/integration/jpa/appl/pom.xml @@ -107,7 +107,7 @@ org.jboss - jboss-transaction-spi + jboss-transaction-spi-jakarta runtime @@ -125,13 +125,6 @@ - - ${basedir}/src/main/resources - - META-INF/microprofile-config.properties - META-INF/persistence.xml - - ${basedir}/src/main/resources/META-INF META-INF @@ -141,6 +134,13 @@ true + + ${basedir}/src/main/resources + + META-INF/microprofile-config.properties + META-INF/persistence.xml + + @@ -324,10 +324,11 @@ io.fabric8 docker-maven-plugin + start - pre-integration-test + package start @@ -344,32 +345,45 @@ + + h2 - - h2 - + + ${basedir}/../target/h2.properties + - - 9092 - localhost - pokemon - sa - - root - jdbc:h2:tcp://${db.host}:${db.port}/test - org.hibernate.dialect.H2Dialect - org.h2.jdbcx.JdbcDataSource - io.helidon.integrations.db h2 + + com.h2database + h2 + runtime + + + org.codehaus.mojo + properties-maven-plugin + + + initialize + + read-project-properties + + + + ${basedir}/../target/h2.properties + + + + + org.apache.maven.plugins maven-failsafe-plugin @@ -382,57 +396,28 @@ - org.codehaus.mojo - exec-maven-plugin + org.codehaus.gmaven + groovy-maven-plugin - start-db - pre-integration-test + validate - exec + execute - java - - -classpath - ${project.build.directory}/libs/h2-${version.lib.h2}.jar - ${mainClassH2} - -tcp - -tcpPassword - ${h2.db.password} - -tcpPort - ${h2.db.port} - -baseDir - ${project.build.directory}/h2 - -ifNotExists - - true - - - - stop-db - post-integration-test - - exec - - - java - - -classpath - ${project.build.directory}/libs/h2-${version.lib.h2}.jar - ${mainClassH2} - -tcpShutdown - tcp://localhost:${h2.db.port} - -tcpPassword - ${h2.db.password} - + + log.info('Running tests with in memory H2 database:') + log.info(' - URL=${db.url}') + log.info(' - ${basedir}/../target/h2.properties') + - + + mysql @@ -516,6 +501,7 @@ + pgsql diff --git a/tests/integration/jpa/appl/src/main/java/io/helidon/tests/integration/jpa/appl/JdbcApiIT.java b/tests/integration/jpa/appl/src/main/java/io/helidon/tests/integration/jpa/appl/JdbcApiIT.java index 947c102d473..598f5966065 100644 --- a/tests/integration/jpa/appl/src/main/java/io/helidon/tests/integration/jpa/appl/JdbcApiIT.java +++ b/tests/integration/jpa/appl/src/main/java/io/helidon/tests/integration/jpa/appl/JdbcApiIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,13 +56,13 @@ public TestResult setup(TestResult result) { final String dbPassword = config.getProperty("javax.sql.DataSource.test.dataSource.password"); final String dbUrl = config.getProperty("javax.sql.DataSource.test.dataSource.url"); if (dbUser == null) { - throw new IllegalStateException("Database user name was not set!"); + throw new IllegalStateException("Database user name was not set, check javax.sql.DataSource.test.dataSource.user property! "); } if (dbPassword == null) { - throw new IllegalStateException("Database user password was not set!"); + throw new IllegalStateException("Database user password was not set, check javax.sql.DataSource.test.dataSource.password property!"); } if (dbUrl == null) { - throw new IllegalStateException("Database URL was not set!"); + throw new IllegalStateException("Database URL was not set, check javax.sql.DataSource.test.dataSource.url property!"); } try { conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword); diff --git a/tests/integration/jpa/appl/src/main/java/io/helidon/tests/integration/jpa/appl/UpdateIT.java b/tests/integration/jpa/appl/src/main/java/io/helidon/tests/integration/jpa/appl/UpdateIT.java index c9aff1eb3a1..96cec511ad8 100644 --- a/tests/integration/jpa/appl/src/main/java/io/helidon/tests/integration/jpa/appl/UpdateIT.java +++ b/tests/integration/jpa/appl/src/main/java/io/helidon/tests/integration/jpa/appl/UpdateIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -193,7 +193,6 @@ public TestResult testUpdateSaffron(TestResult result) { City city = em.find(City.class, cities[0].getId()); stadium = city.getStadium(); Trainer trainer = stadium.getTrainer(); - em.refresh(trainer); pokemons = trainer.getPokemons(); result.assertEquals(trainer.getName(), "Janine"); for (Pokemon pokemon : pokemons) { diff --git a/tests/integration/jpa/appl/src/main/resources/hibernate.properties b/tests/integration/jpa/appl/src/main/resources/hibernate.properties index 5d0d4b0e120..a86b25d6136 100644 --- a/tests/integration/jpa/appl/src/main/resources/hibernate.properties +++ b/tests/integration/jpa/appl/src/main/resources/hibernate.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Oracle and/or its affiliates. +# Copyright (c) 2020, 2022 Oracle and/or its affiliates. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,4 +17,3 @@ # Byte code for JPA must be generated at compile time. # This is a limitation of native image hibernate.bytecode.provider=none - diff --git a/tests/integration/jpa/appl/src/test/java/io/helidon/tests/integration/jpa/appl/test/LifeCycleExtension.java b/tests/integration/jpa/appl/src/test/java/io/helidon/tests/integration/jpa/appl/test/LifeCycleExtension.java index e160e799488..923d1855890 100644 --- a/tests/integration/jpa/appl/src/test/java/io/helidon/tests/integration/jpa/appl/test/LifeCycleExtension.java +++ b/tests/integration/jpa/appl/src/test/java/io/helidon/tests/integration/jpa/appl/test/LifeCycleExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -103,13 +103,13 @@ public static void waitForDatabase() { final String dbUrl = System.getProperty("db.url"); boolean connected = false; if (dbUser == null) { - throw new IllegalStateException("Database user name was not set!"); + throw new IllegalStateException("Database user name was not set, check db.user property!"); } if (dbPassword == null) { - throw new IllegalStateException("Database user password was not set!"); + throw new IllegalStateException("Database user password was not set, check db.password property!"); } if (dbUrl == null) { - throw new IllegalStateException("Database URL was not set!"); + throw new IllegalStateException("Database URL was not set, check db.url property"); } long endTm = 1000 * TIMEOUT + System.currentTimeMillis(); while (true) { diff --git a/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Pokemon.java b/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Pokemon.java index 693fac352e9..6d4799464aa 100644 --- a/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Pokemon.java +++ b/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Pokemon.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,14 +21,7 @@ import java.util.Objects; import java.util.logging.Logger; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.JoinTable; -import jakarta.persistence.ManyToMany; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.UniqueConstraint; +import jakarta.persistence.*; /** * Pokemon entity. @@ -39,7 +32,7 @@ public class Pokemon implements Serializable { private static final Logger LOGGER = Logger.getLogger(Pokemon.class.getName()); @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.TABLE) private int id; @ManyToOne diff --git a/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Settlement.java b/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Settlement.java index ca89bc3d157..eb4c0749482 100644 --- a/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Settlement.java +++ b/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Settlement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import java.util.Objects; import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; @@ -28,7 +29,7 @@ public class Settlement { @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String name; diff --git a/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Stadium.java b/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Stadium.java index ac1fa64ea3d..f3932403e2d 100644 --- a/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Stadium.java +++ b/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Stadium.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,7 @@ import java.util.Objects; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import jakarta.persistence.*; /** * Pokemon stadium. @@ -30,7 +26,7 @@ public class Stadium { @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String name; diff --git a/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Trainer.java b/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Trainer.java index 5bc94901829..2e79bbf7e8a 100644 --- a/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Trainer.java +++ b/tests/integration/jpa/model/src/main/java/io/helidon/tests/integration/jpa/model/Trainer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,7 @@ import java.util.List; import java.util.Objects; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; +import jakarta.persistence.*; /** * Trainer entity. @@ -32,7 +28,7 @@ public class Trainer implements Serializable { @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String name; diff --git a/tests/integration/jpa/pom.xml b/tests/integration/jpa/pom.xml index 4fe302f86e0..6b5abcaea03 100644 --- a/tests/integration/jpa/pom.xml +++ b/tests/integration/jpa/pom.xml @@ -43,4 +43,72 @@ appl + + + + h2 + + true + + + 9092 + localhost + test + sa + + jdbc:h2:mem:test;INIT=SET TRACE_LEVEL_FILE=4 + org.hibernate.dialect.H2Dialect + org.h2.jdbcx.JdbcDataSource + + + + + org.apache.maven.plugins + maven-resources-plugin + + + trigger-h2 + generate-resources + + copy-resources + + + + + ${basedir}/src/main/resources + + h2.properties + + true + + + ${project.build.directory} + + + + + + org.codehaus.gmaven + groovy-maven-plugin + + + validate + + execute + + + + log.info('Running tests with in memory H2 database:') + log.info(' - URL=${db.url}') + + + + + + + + + + + diff --git a/tests/integration/jpa/simple/pom.xml b/tests/integration/jpa/simple/pom.xml index 5b09f8e15ee..690d172c080 100644 --- a/tests/integration/jpa/simple/pom.xml +++ b/tests/integration/jpa/simple/pom.xml @@ -97,12 +97,6 @@ jakarta.validation-api - - com.h2database - h2 - test - - org.junit.jupiter junit-jupiter-api @@ -181,4 +175,22 @@ + + + + + h2 + + true + + + + com.h2database + h2 + test + + + + + diff --git a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/UpdateIT.java b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/UpdateIT.java index b811069fa1f..64602f097b2 100644 --- a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/UpdateIT.java +++ b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/UpdateIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -195,7 +195,6 @@ public void testUpdateSaffron() { City city = em.find(City.class, cities[0].getId()); Stadium stadium = city.getStadium(); Trainer trainer = stadium.getTrainer(); - em.refresh(trainer); List pokemons = trainer.getPokemons(); assertEquals(trainer.getName(), "Janine"); for (Pokemon pokemon : pokemons) { diff --git a/tests/integration/jpa/src/main/resources/h2.properties b/tests/integration/jpa/src/main/resources/h2.properties new file mode 100644 index 00000000000..e78c3fc15b3 --- /dev/null +++ b/tests/integration/jpa/src/main/resources/h2.properties @@ -0,0 +1,23 @@ +# +# Copyright (c) 2022 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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.port=${db.port} +db.host=${db.host} +db.database=${db.database} +db.user=${db.user} +db.password=${db.password} +db.url=${db.url} +hibernate.dialect=${hibernate.dialect} +db.datasource=${db.datasource} diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml index 10ca7106a9e..44ee55582f4 100644 --- a/tests/integration/pom.xml +++ b/tests/integration/pom.xml @@ -51,6 +51,7 @@ mp-gh-4123 mp-gh-4654 kafka + jpa jms config jep290 @@ -65,7 +66,6 @@ true - jpa native-image From fb0c9d8894a73f457a6f244036601f239c9ad326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kraus?= Date: Tue, 4 Oct 2022 12:28:59 +0200 Subject: [PATCH 2/2] Issue 4740 - POM profiles activartion redesigned. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Kraus --- tests/integration/jpa/appl/pom.xml | 113 +++++------------- tests/integration/jpa/pom.xml | 68 ----------- tests/integration/jpa/simple/pom.xml | 28 +---- .../integration/jpa/simple/init/InitIT.java | 48 -------- .../integration/jpa/simple/test/DeleteIT.java | 6 +- .../integration/jpa/simple/test/InsertIT.java | 36 +----- .../integration/jpa/simple/test/QueryIT.java | 18 +-- .../integration/jpa/simple/test/UpdateIT.java | 10 +- .../jpa/src/main/resources/h2.properties | 23 ---- 9 files changed, 53 insertions(+), 297 deletions(-) delete mode 100644 tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/init/InitIT.java delete mode 100644 tests/integration/jpa/src/main/resources/h2.properties diff --git a/tests/integration/jpa/appl/pom.xml b/tests/integration/jpa/appl/pom.xml index b21fc680a29..597099e30b3 100644 --- a/tests/integration/jpa/appl/pom.xml +++ b/tests/integration/jpa/appl/pom.xml @@ -232,6 +232,9 @@ 10 true + ${db.user} + ${db.password} + ${db.url} @@ -346,14 +349,24 @@ - + h2 - - ${basedir}/../target/h2.properties - + + !db + + + 9092 + localhost + test + sa + + jdbc:h2:mem:test;INIT=SET TRACE_LEVEL_FILE=4 + org.hibernate.dialect.H2Dialect + org.h2.jdbcx.JdbcDataSource + io.helidon.integrations.db @@ -365,64 +378,13 @@ runtime - - - - org.codehaus.mojo - properties-maven-plugin - - - initialize - - read-project-properties - - - - ${basedir}/../target/h2.properties - - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - ${db.user} - ${db.password} - ${db.url} - - - - - org.codehaus.gmaven - groovy-maven-plugin - - - validate - - execute - - - - log.info('Running tests with in memory H2 database:') - log.info(' - URL=${db.url}') - log.info(' - ${basedir}/../target/h2.properties') - - - - - - - - mysql - mysql + db + mysql @@ -434,7 +396,7 @@ password root jdbc:mysql://${db.host}:${db.port}/${db.database}?${db.args} - org.hibernate.dialect.MySQL5Dialect + org.hibernate.dialect.MySQL8Dialect com.mysql.cj.jdbc.MysqlDataSource com.mysql.cj.jdbc.Driver @@ -452,17 +414,6 @@ - - org.apache.maven.plugins - maven-failsafe-plugin - - - ${db.user} - ${db.password} - ${db.url} - - - io.fabric8 docker-maven-plugin @@ -483,13 +434,14 @@ ${db.host}:${db.port}:3306 - + + MySQL init process done. Ready for start up. @@ -501,12 +453,12 @@ - pgsql - pgsql + db + pgsql @@ -516,8 +468,8 @@ user password jdbc:postgresql://${db.host}:${db.port}/${db.database} - org.hibernate.dialect.PostgreSQL10Dialect - org.postgresql.jdbc3.Jdbc3PoolingDataSource + org.hibernate.dialect.PostgreSQLDialect + org.postgresql.ds.PGSimpleDataSource org.postgresql.Driver @@ -534,17 +486,6 @@ - - org.apache.maven.plugins - maven-failsafe-plugin - - - ${db.user} - ${db.password} - ${db.url} - - - io.fabric8 docker-maven-plugin diff --git a/tests/integration/jpa/pom.xml b/tests/integration/jpa/pom.xml index 6b5abcaea03..4fe302f86e0 100644 --- a/tests/integration/jpa/pom.xml +++ b/tests/integration/jpa/pom.xml @@ -43,72 +43,4 @@ appl - - - - h2 - - true - - - 9092 - localhost - test - sa - - jdbc:h2:mem:test;INIT=SET TRACE_LEVEL_FILE=4 - org.hibernate.dialect.H2Dialect - org.h2.jdbcx.JdbcDataSource - - - - - org.apache.maven.plugins - maven-resources-plugin - - - trigger-h2 - generate-resources - - copy-resources - - - - - ${basedir}/src/main/resources - - h2.properties - - true - - - ${project.build.directory} - - - - - - org.codehaus.gmaven - groovy-maven-plugin - - - validate - - execute - - - - log.info('Running tests with in memory H2 database:') - log.info(' - URL=${db.url}') - - - - - - - - - - - diff --git a/tests/integration/jpa/simple/pom.xml b/tests/integration/jpa/simple/pom.xml index 690d172c080..5ba6054b677 100644 --- a/tests/integration/jpa/simple/pom.xml +++ b/tests/integration/jpa/simple/pom.xml @@ -97,6 +97,11 @@ jakarta.validation-api + + com.h2database + h2 + test + org.junit.jupiter junit-jupiter-api @@ -107,7 +112,6 @@ hamcrest-all test - org.jboss jandex @@ -156,16 +160,14 @@ 10 - - test + test-run integration-test integration-test - io.helidon.tests.integration.jpa.simple.init.*IT io.helidon.tests.integration.jpa.simple.test.*IT @@ -175,22 +177,4 @@ - - - - - h2 - - true - - - - com.h2database - h2 - test - - - - - diff --git a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/init/InitIT.java b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/init/InitIT.java deleted file mode 100644 index 169c0836ed5..00000000000 --- a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/init/InitIT.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.helidon.tests.integration.jpa.simple.init; - -import io.helidon.tests.integration.jpa.simple.DbUtils; -import io.helidon.tests.integration.jpa.simple.PU; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -/** - * Initialize tests. - */ -public class InitIT { - - private static PU pu; - - @BeforeAll - public static void setup() { - pu = PU.getInstance(); - } - - @AfterAll - public static void destroy() { - pu = null; - } - - - @Test - public void testInsertData() { - pu.tx(pu -> DbUtils.dbInit(pu)); - } - -} diff --git a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/DeleteIT.java b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/DeleteIT.java index e7e3ef9acb5..b4c956cf88f 100644 --- a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/DeleteIT.java +++ b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/DeleteIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ import java.util.List; +import io.helidon.tests.integration.jpa.simple.DbUtils; import jakarta.persistence.EntityManager; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaDelete; @@ -67,12 +68,13 @@ private static void dbDeleteMisty() { @BeforeAll public static void setup() { pu = PU.getInstance(); + pu.tx(pu -> DbUtils.dbInit(pu)); dbInsertMisty(); } @AfterAll public static void destroy() { - dbDeleteMisty(); + pu.tx(pu -> DbUtils.dbCleanup(pu)); pu = null; } diff --git a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/InsertIT.java b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/InsertIT.java index 6f73b557f20..fb38a7974a9 100644 --- a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/InsertIT.java +++ b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/InsertIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import java.util.List; import java.util.Set; +import io.helidon.tests.integration.jpa.simple.DbUtils; import jakarta.persistence.EntityManager; import io.helidon.tests.integration.jpa.model.Pokemon; @@ -51,41 +52,12 @@ public class InsertIT { @BeforeAll public static void setup() { pu = PU.getInstance(); + pu.tx(pu -> DbUtils.dbInit(pu)); } @AfterAll public static void destroy() { - pu.tx(pu -> { - final EntityManager em = pu.getEm(); - // testInsertType cleanup - em.createQuery("DELETE FROM Type t WHERE t.id = :id") - .setParameter("id", 20) - .executeUpdate(); - // Towns cleanup - DELETE_TOWNS.forEach((id) -> { - em.createQuery("DELETE FROM City c WHERE c.id = :id") - .setParameter("id", id) - .executeUpdate(); - }); - // Stadiums cleanup - DELETE_STADIUMS.forEach((id) -> { - em.createQuery("DELETE FROM Stadium s WHERE s.id = :id") - .setParameter("id", id) - .executeUpdate(); - }); - // Pokemons cleanup - DELETE_POKEMONS.forEach((id) -> { - em.createQuery("DELETE FROM Pokemon p WHERE p.id = :id") - .setParameter("id", id) - .executeUpdate(); - }); - // Trainers cleanup - DELETE_TRAINERS.forEach((id) -> { - em.createQuery("DELETE FROM Trainer t WHERE t.id = :id") - .setParameter("id", id) - .executeUpdate(); - }); - }); + pu.tx(pu -> DbUtils.dbCleanup(pu)); pu = null; } diff --git a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/QueryIT.java b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/QueryIT.java index 2267e66f25a..347f8abd70d 100644 --- a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/QueryIT.java +++ b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/QueryIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,12 +20,10 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; -import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Root; import io.helidon.tests.integration.jpa.model.City; import io.helidon.tests.integration.jpa.model.Pokemon; -import io.helidon.tests.integration.jpa.model.Stadium; import io.helidon.tests.integration.jpa.model.Trainer; import io.helidon.tests.integration.jpa.simple.DbUtils; import io.helidon.tests.integration.jpa.simple.PU; @@ -42,16 +40,18 @@ * Verify query operations of ORM. */ public class QueryIT { - + private static PU pu; @BeforeAll public static void setup() { pu = PU.getInstance(); + pu.tx(pu -> DbUtils.dbInit(pu)); } @AfterAll public static void destroy() { + pu.tx(pu -> DbUtils.dbCleanup(pu)); pu = null; } @@ -77,7 +77,7 @@ public void testQueryJPQL() { pu.tx(pu -> { final EntityManager em = pu.getCleanEm(); Trainer ash = em.createQuery( - "SELECT t FROM Trainer t JOIN FETCH t.pokemons p WHERE t.id = :id", Trainer.class) + "SELECT t FROM Trainer t JOIN FETCH t.pokemons p WHERE t.id = :id", Trainer.class) .setParameter("id", DbUtils.ASH_ID) .getSingleResult(); List pokemons = ash.getPokemons(); @@ -113,10 +113,10 @@ public void testQueryCeladonJPQL() { pu.tx(pu -> { final EntityManager em = pu.getCleanEm(); City city = em.createQuery( - "SELECT c FROM City c " - + "JOIN FETCH c.stadium s " - + "JOIN FETCH s.trainer t " - + "WHERE c.name = :name", City.class) + "SELECT c FROM City c " + + "JOIN FETCH c.stadium s " + + "JOIN FETCH s.trainer t " + + "WHERE c.name = :name", City.class) .setParameter("name", "Celadon City") .getSingleResult(); assertEquals(city.getName(), "Celadon City"); diff --git a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/UpdateIT.java b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/UpdateIT.java index 64602f097b2..ec593021522 100644 --- a/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/UpdateIT.java +++ b/tests/integration/jpa/simple/src/test/java/io/helidon/tests/integration/jpa/simple/test/UpdateIT.java @@ -27,7 +27,6 @@ import jakarta.persistence.criteria.Root; import io.helidon.tests.integration.jpa.dao.Create; -import io.helidon.tests.integration.jpa.dao.Delete; import io.helidon.tests.integration.jpa.model.City; import io.helidon.tests.integration.jpa.model.Pokemon; import io.helidon.tests.integration.jpa.model.Stadium; @@ -54,6 +53,7 @@ public static void setup() { pu = PU.getInstance(); pu.tx(pu -> { final EntityManager em = pu.getEm(); + DbUtils.dbInit(pu); Create.dbInsertBrock(em); Create.dbInsertSaffron(em); }); @@ -61,12 +61,8 @@ public static void setup() { @AfterAll public static void destroy() { - pu.tx(pu -> { - final EntityManager em = pu.getEm(); - Delete.dbDeleteBrock(em); - Delete.dbDeleteSaffron(em); - pu = null; - }); + pu.tx(pu -> DbUtils.dbCleanup(pu)); + pu = null; } /** diff --git a/tests/integration/jpa/src/main/resources/h2.properties b/tests/integration/jpa/src/main/resources/h2.properties deleted file mode 100644 index e78c3fc15b3..00000000000 --- a/tests/integration/jpa/src/main/resources/h2.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2022 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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.port=${db.port} -db.host=${db.host} -db.database=${db.database} -db.user=${db.user} -db.password=${db.password} -db.url=${db.url} -hibernate.dialect=${hibernate.dialect} -db.datasource=${db.datasource}