Skip to content

Conversation

@mbellade
Copy link
Member

@mbellade mbellade commented Oct 17, 2025

https://hibernate.atlassian.net/browse/HHH-19871

Drafting a possible migration path for Envers tests from JUnit 4 -> 6. This approach is the "least invasive", adding on top of the existing hibernate-testing annotations like @Jpa adding only the required Envers machinery, while relying on existing JUnit 6 features like @ClassTemplates to run tests with multiple audit strategies.

Migrated the following test packages:

  • org.hibernate.orm.test.envers.integration.query
  • org.hibernate.orm.test.envers.integration.accesstype
  • org.hibernate.orm.test.envers.integration.auditReader
  • org.hibernate.orm.test.envers.integration.basic
  • org.hibernate.orm.test.envers.integration.blob
  • org.hibernate.orm.test.envers.integration.cache
  • org.hibernate.orm.test.envers.integration.collection
  • org.hibernate.orm.test.envers.integration.components
  • org.hibernate.orm.test.envers.integration.customtype
  • org.hibernate.orm.test.envers.integration.data
  • org.hibernate.orm.test.envers.integration.dynamic
  • org.hibernate.orm.test.envers.integration.dynamicmodel
  • org.hibernate.orm.test.envers.integration.entityNames
  • org.hibernate.orm.test.envers.integration.flush
  • org.hibernate.orm.test.envers.integration.generated

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Oct 17, 2025

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@marko-bekhta
Copy link
Member

marko-bekhta commented Oct 17, 2025

Only downside is, we cannot use @BeforeAll/@afterall methods to set-up / tear-down test data

have you tried this one:
https://docs.junit.org/current/api/org.junit.jupiter.params/org/junit/jupiter/params/BeforeParameterizedClassInvocation.html

(Last time I've played around with this it had some strange behavior, but I don't remember the sepcifics anymore 🙂)

@mbellade
Copy link
Member Author

mbellade commented Oct 17, 2025

Hey @marko-bekhta, yes I saw that (there's also this) but I'm not sure how that would help - @BeforeAll/@AfterAll annotated methods would still only be executed once for @ClassTemplates, per JUnit's API.

@marko-bekhta
Copy link
Member

Ah I meant to use the other pair of anotations in the evnerse test classes rather than @BeforeAll/@AfterAll. Or you mean the problem is that the callbacks are implemented in the extensions and that's where the problem comes from ?

@mbellade
Copy link
Member Author

As discussed offline, there are a few alternatives to improve on the @Order restriction - I'll update the PR once we've determined which one we'd prefer for envers.

@mbellade mbellade force-pushed the envers-junit branch 2 times, most recently from dfd4d86 to 798f410 Compare October 22, 2025 14:29
Comment on lines +112 to +114
List<?> revisionInfos = AuditReaderFactory.get( em ).createQuery()
.forRevisionsOfEntity( NotAuditedTestEntity.class, false )
.getResultList();

Check notice

Code scanning / CodeQL

Unread local variable Note test

Variable 'List<?> revisionInfos' is never read.
final var domainModel = scope.getDomainModel();

assertThrows( AssertionFailedError.class, () -> {
final Long expectedDefaultLength = new Long( DEFAULT_LENGTH );

Check notice

Code scanning / CodeQL

Inefficient primitive constructor Note test

Inefficient constructor for long value, use Long.valueOf(...) instead.

final org.hibernate.mapping.Column colDef = auditTable.getColumn( toIdentifier( "columnWithDefinition" ) );
assertEquals( "varchar(10)", colDef.getSqlType() );
assertEquals( new Long( 10 ), colDef.getLength() );

Check notice

Code scanning / CodeQL

Inefficient primitive constructor Note test

Inefficient constructor for long value, use Long.valueOf(...) instead.
public void blockTest() {
final AuditReader reader = getAuditReader();
public void blockTest(EntityManagerFactoryScope scope) {
final AuditReader reader = scope.fromEntityManager( em -> AuditReaderFactory.get( em ) );

Check notice

Code scanning / CodeQL

Unread local variable Note test

Variable 'AuditReader reader' is never read.
@mbellade mbellade force-pushed the envers-junit branch 3 times, most recently from ab22c63 to fd09d92 Compare October 22, 2025 16:19
em.getTransaction().commit();
scope.inTransaction( em -> {
ComponentTestEntity cte1 = em.find( ComponentTestEntity.class, id1 );
ComponentTestEntity cte2 = em.find( ComponentTestEntity.class, id2 );

Check notice

Code scanning / CodeQL

Unread local variable Note test

Variable 'ComponentTestEntity cte2' is never read.
@@ -222,4 +226,33 @@
entityManager.close();
}
}

public static AuditStrategy getAuditStrategy(EntityManager entityManager) {

Check notice

Code scanning / CodeQL

Confusing overloading of methods Note test

Method EnversEntityManagerFactoryScope.getAuditStrategy(..) could be confused with overloaded method
getAuditStrategy
, since dispatch depends on static types.

private void assertEnumProperty(Class<?> entityClass, Class<?> typeClass, String propertyName, EnumType expectedType) {
doInJPA( this::entityManagerFactory, entityManager -> {
private void assertEnumProperty(EntityManagerFactoryScope scope, Class<?> entityClass, Class<?> typeClass, String propertyName, EnumType expectedType) {

Check notice

Code scanning / CodeQL

Useless parameter Note test

The parameter 'expectedType' is never used.

private void checkEntities() {

private void checkEntities(SessionImplementor session, AuditReader auditReader) {

Check notice

Code scanning / CodeQL

Useless parameter Note test

The parameter 'session' is never used.

private void checkEntities() {

private void checkEntities(SessionImplementor session, AuditReader auditReader) {

Check notice

Code scanning / CodeQL

Useless parameter Note test

The parameter 'auditReader' is never used.
- Extension hooks and hibernate-testing changes
- org.hibernate.orm.test.envers.integration.query`
- `org.hibernate.orm.test.envers.integration.accesstype`
- `org.hibernate.orm.test.envers.integration.auditReader`
- `org.hibernate.orm.test.envers.integration.basic`
- `org.hibernate.orm.test.envers.integration.blob`
- `org.hibernate.orm.test.envers.integration.cache`
- `org.hibernate.orm.test.envers.integration.collection`
- `org.hibernate.orm.test.envers.integration.components`
- `org.hibernate.orm.test.envers.integration.customtype`
- `org.hibernate.orm.test.envers.integration.data`
- `org.hibernate.orm.test.envers.integration.dynamic`
- `org.hibernate.orm.test.envers.integration.dynamicmodel`
- `org.hibernate.orm.test.envers.integration.entityNames`
- `org.hibernate.orm.test.envers.integration.generated`
- `org.hibernate.orm.test.envers.integration.flush`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants