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.


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
@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.
@mbellade mbellade force-pushed the envers-junit branch 2 times, most recently from 9d5369c to 72e1f20 Compare October 24, 2025 14:49
@mbellade mbellade marked this pull request as ready for review November 4, 2025 13:08
@mbellade
Copy link
Member Author

mbellade commented Nov 4, 2025

Marking as ready for review, there are more tests to work on but we can start merging the JUnit extension work and what has already been migrated so far.

- Created new envers-junit hooks and hibernate-testing changes
- Migrated the `org.hibernate.orm.test.envers.integration` package
return true;
}
if ( object == null | getClass() != object.getClass() ) {
if (object == null | getClass() != object.getClass()) {

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning test

Variable
object
may be null at this access as suggested by
this
null guard.
return true;
}
if ( object == null | getClass() != object.getClass() ) {
if (object == null | getClass() != object.getClass()) {

Check warning

Code scanning / CodeQL

Dangerous non-short-circuit logic Warning test

Possibly dangerous use of non-short circuit logic.
}

@Test
public void testInterceptorInvocations(EntityManagerFactoryScope scope) {

Check notice

Code scanning / CodeQL

Useless parameter Note test

The parameter 'scope' is never used.
}

@AfterClassTemplate
public void cleanupData(EntityManagerFactoryScope scope) throws Exception {

Check notice

Code scanning / CodeQL

Useless parameter Note test

The parameter 'scope' is never used.
// Revision 1
Root m1 = new Root();
DetailSubclass det1 = new DetailSubclass2();
DetailSubclass det2 = new DetailSubclass2();

Check notice

Code scanning / CodeQL

Unread local variable Note test

Variable 'DetailSubclass det2' is never read.
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.

3 participants