Skip to content

Commit

Permalink
Upgrade to java 17, spring boot 3.x and jakarta persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
rpost committed May 29, 2024
1 parent ebe9ac2 commit 4dd03f2
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 39 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -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(":")
}
2 changes: 1 addition & 1 deletion spring-boot-tests/h2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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(":")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.cronn.testutils.h2.app;

import javax.transaction.Transactional;
import jakarta.transaction.Transactional;

public class TransactionUtil {

Expand Down
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion spring-boot-tests/h2/tests-h2-1.4.x/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
6 changes: 5 additions & 1 deletion spring-boot-tests/h2/tests-h2-2.0.x/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
6 changes: 5 additions & 1 deletion spring-boot-tests/h2/tests-h2-2.1.x/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
6 changes: 5 additions & 1 deletion spring-boot-tests/h2/tests-h2-2.2.x/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
7 changes: 4 additions & 3 deletions src/main/java/de/cronn/testutils/h2/H2Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
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;
import org.slf4j.LoggerFactory;
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);
Expand Down

0 comments on commit 4dd03f2

Please sign in to comment.