diff --git a/README.md b/README.md index d11b978..885053c 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,9 @@ Empty state is defined as: - empty tables, sequences restarted for `resetDatabase()` - empty database schema for `dropAllObjects()` -Warning: H2Util requires JPA, Spring and H2 dependencies which are defined as optional in library: you have to provide them on your own. +Warnings: + - H2Util requires JPA, Spring and H2 dependencies which are defined as optional in library: you have to provide them on your own. + - Hibernate can cache sequence values in advance. You might want to disable that by setting [`hibernate.id.optimizer.pooled.preferred`](https://docs.jboss.org/hibernate/orm/6.5/userguide/html_single/Hibernate_User_Guide.html#settings-mapping) to `NONE` (for example by adding `spring.jpa.properties.hibernate.id.optimizer.pooled.preferred=NONE` spring property) ### TestClock TestClock is an implementation of the abstract class `Clock`, and provides features useful for testing. If not specified it is initialized with a fixed Instant in the past. Its time is fixed, this clock will not run. Therefore, it also provides features to manipulate its time. diff --git a/build.gradle b/build.gradle index e7529ae..eca4bd2 100644 --- a/build.gradle +++ b/build.gradle @@ -10,8 +10,8 @@ allprojects { group "de.cronn" version = System.env.ARTIFACT_VERSION ?: "SNAPSHOT" - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 compileJava.options.encoding = 'UTF-8' @@ -42,7 +42,7 @@ test { dependencyManagement { imports { - mavenBom "org.springframework.boot:spring-boot-dependencies:2.6.14" + mavenBom "org.springframework.boot:spring-boot-dependencies:3.2.6" } generatedPomCustomization { enabled = false diff --git a/spring-boot-tests/build.gradle b/spring-boot-tests/build.gradle index 9d7994f..ea3d75c 100644 --- a/spring-boot-tests/build.gradle +++ b/spring-boot-tests/build.gradle @@ -1,5 +1,5 @@ dependencies { - implementation platform("org.springframework.boot:spring-boot-dependencies:2.6.14") + implementation platform("org.springframework.boot:spring-boot-dependencies:3.2.6") testImplementation "org.springframework.boot:spring-boot-starter-test" testImplementation project(":") } diff --git a/spring-boot-tests/h2/build.gradle b/spring-boot-tests/h2/build.gradle index c31d5f7..ec1e23f 100644 --- a/spring-boot-tests/h2/build.gradle +++ b/spring-boot-tests/h2/build.gradle @@ -3,7 +3,7 @@ plugins { } dependencies { - api platform("org.springframework.boot:spring-boot-dependencies:2.6.14") + api platform("org.springframework.boot:spring-boot-dependencies:3.2.6") api "org.springframework.boot:spring-boot-starter-test" api "org.springframework.boot:spring-boot-starter-data-jpa" implementation project(":") diff --git a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/H2UtilTest.java b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/H2UtilTest.java index 12a25b0..d13c79d 100644 --- a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/H2UtilTest.java +++ b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/H2UtilTest.java @@ -2,8 +2,6 @@ import java.util.regex.Pattern; -import javax.persistence.EntityManager; - import org.assertj.core.api.SoftAssertions; import org.assertj.core.api.junit.jupiter.InjectSoftAssertions; import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension; @@ -24,6 +22,7 @@ import de.cronn.testutils.h2.app.SecondSchemaEntity; import de.cronn.testutils.h2.app.SequenceUsingEntity; import de.cronn.testutils.h2.app.TransactionUtil; +import jakarta.persistence.EntityManager; @ExtendWith(SoftAssertionsExtension.class) @TestMethodOrder(MethodOrderer.MethodName.class) diff --git a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/EntityWithIdentityId.java b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/EntityWithIdentityId.java index 070e606..e67b994 100644 --- a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/EntityWithIdentityId.java +++ b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/EntityWithIdentityId.java @@ -1,9 +1,9 @@ package de.cronn.testutils.h2.app; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; @Entity public class EntityWithIdentityId { diff --git a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SampleEntity.java b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SampleEntity.java index add0743..f9f938e 100644 --- a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SampleEntity.java +++ b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SampleEntity.java @@ -1,8 +1,8 @@ package de.cronn.testutils.h2.app; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; @Entity public class SampleEntity { diff --git a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SampleTableGeneratedEntity.java b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SampleTableGeneratedEntity.java index e27a7b0..a1657ef 100644 --- a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SampleTableGeneratedEntity.java +++ b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SampleTableGeneratedEntity.java @@ -1,10 +1,10 @@ package de.cronn.testutils.h2.app; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.TableGenerator; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.TableGenerator; @Entity public class SampleTableGeneratedEntity { diff --git a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SecondSchemaEntity.java b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SecondSchemaEntity.java index 6bac876..9176d12 100644 --- a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SecondSchemaEntity.java +++ b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SecondSchemaEntity.java @@ -1,11 +1,11 @@ package de.cronn.testutils.h2.app; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.TableGenerator; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.persistence.TableGenerator; @Table(schema = "second_schema") @Entity diff --git a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SequenceUsingEntity.java b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SequenceUsingEntity.java index 0e0fadd..8ac8716 100644 --- a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SequenceUsingEntity.java +++ b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/SequenceUsingEntity.java @@ -1,10 +1,10 @@ package de.cronn.testutils.h2.app; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.SequenceGenerator; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.SequenceGenerator; @Entity public class SequenceUsingEntity { diff --git a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/TransactionUtil.java b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/TransactionUtil.java index b79f89f..3c284cb 100644 --- a/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/TransactionUtil.java +++ b/spring-boot-tests/h2/src/main/java/de/cronn/testutils/h2/app/TransactionUtil.java @@ -1,6 +1,6 @@ package de.cronn.testutils.h2.app; -import javax.transaction.Transactional; +import jakarta.transaction.Transactional; public class TransactionUtil { diff --git a/spring-boot-tests/h2/src/main/resources/application.properties b/spring-boot-tests/h2/src/main/resources/application.properties index 5c64d01..f7cf243 100644 --- a/spring-boot-tests/h2/src/main/resources/application.properties +++ b/spring-boot-tests/h2/src/main/resources/application.properties @@ -1 +1,2 @@ spring.datasource.url=jdbc:h2:mem:testdb;INIT=CREATE SCHEMA IF NOT EXISTS SECOND_SCHEMA +spring.jpa.properties.hibernate.id.optimizer.pooled.preferred=NONE diff --git a/spring-boot-tests/h2/tests-h2-1.4.x/build.gradle b/spring-boot-tests/h2/tests-h2-1.4.x/build.gradle index e73a1ba..dc6cfa6 100644 --- a/spring-boot-tests/h2/tests-h2-1.4.x/build.gradle +++ b/spring-boot-tests/h2/tests-h2-1.4.x/build.gradle @@ -1,4 +1,8 @@ dependencies { implementation project(":spring-boot-tests:h2") - runtimeOnly "com.h2database:h2:1.4.200" + runtimeOnly("com.h2database:h2") { + version { + strictly "1.4.200" + } + } } diff --git a/spring-boot-tests/h2/tests-h2-2.0.x/build.gradle b/spring-boot-tests/h2/tests-h2-2.0.x/build.gradle index e7cf637..55f4da4 100644 --- a/spring-boot-tests/h2/tests-h2-2.0.x/build.gradle +++ b/spring-boot-tests/h2/tests-h2-2.0.x/build.gradle @@ -1,4 +1,8 @@ dependencies { implementation project(":spring-boot-tests:h2") - runtimeOnly "com.h2database:h2:2.0.206" + runtimeOnly("com.h2database:h2") { + version { + strictly "2.0.206" + } + } } diff --git a/spring-boot-tests/h2/tests-h2-2.1.x/build.gradle b/spring-boot-tests/h2/tests-h2-2.1.x/build.gradle index bcbec6f..807a4bc 100644 --- a/spring-boot-tests/h2/tests-h2-2.1.x/build.gradle +++ b/spring-boot-tests/h2/tests-h2-2.1.x/build.gradle @@ -1,4 +1,8 @@ dependencies { implementation project(":spring-boot-tests:h2") - runtimeOnly "com.h2database:h2:2.1.214" + runtimeOnly("com.h2database:h2") { + version { + strictly "2.1.214" + } + } } diff --git a/spring-boot-tests/h2/tests-h2-2.2.x/build.gradle b/spring-boot-tests/h2/tests-h2-2.2.x/build.gradle index 139c04e..6416869 100644 --- a/spring-boot-tests/h2/tests-h2-2.2.x/build.gradle +++ b/spring-boot-tests/h2/tests-h2-2.2.x/build.gradle @@ -1,4 +1,8 @@ dependencies { implementation project(":spring-boot-tests:h2") - runtimeOnly "com.h2database:h2:2.2.224" + runtimeOnly("com.h2database:h2") { + version { + strictly "2.2.224" + } + } } diff --git a/src/main/java/de/cronn/testutils/h2/H2Util.java b/src/main/java/de/cronn/testutils/h2/H2Util.java index b9d2206..d942667 100644 --- a/src/main/java/de/cronn/testutils/h2/H2Util.java +++ b/src/main/java/de/cronn/testutils/h2/H2Util.java @@ -18,9 +18,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import javax.persistence.EntityManager; -import javax.persistence.TableGenerator; -import javax.persistence.metamodel.EntityType; import javax.sql.DataSource; import org.slf4j.Logger; @@ -28,6 +25,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.Assert; +import jakarta.persistence.EntityManager; +import jakarta.persistence.TableGenerator; +import jakarta.persistence.metamodel.EntityType; + public class H2Util { private static final Logger log = LoggerFactory.getLogger(H2Util.class);