From ec2b5684fe7ea6b0133b4013e7dd3acf4c5e081c Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Mon, 11 Aug 2025 22:16:46 -0400 Subject: [PATCH 1/3] make use of @ParameterizedClass feature (since JUnit 5.13) to simplify tests --- gradle/libs.versions.toml | 4 +-- .../ArrayAndCollectionIntegrationTests.java | 11 ------- ...ongoPreparedStatementIntegrationTests.java | 11 ++++++- ...atementWithAutoCommitIntegrationTests.java | 30 ------------------- .../jdbc/MongoStatementIntegrationTests.java | 11 ++++++- ...atementWithAutoCommitIntegrationTests.java | 27 ----------------- 6 files changed, 22 insertions(+), 72 deletions(-) delete mode 100644 src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementWithAutoCommitIntegrationTests.java delete mode 100644 src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementWithAutoCommitIntegrationTests.java diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2e091a53..14ad16d2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,12 +13,12 @@ # limitations under the License. [versions] -junit-jupiter = "5.11.4" +junit-jupiter = "5.13.4" assertj = "3.27.3" google-errorprone-core = "2.36.0" nullaway = "0.12.4" jspecify = "1.0.0" -hibernate-orm = "6.6.9.Final" +hibernate-orm = "6.6.25.Final" mongo-java-driver-sync = "5.3.1" slf4j-api = "2.0.16" logback-classic = "1.5.16" diff --git a/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java index 868bb9c8..e9c31d51 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java @@ -597,17 +597,6 @@ static class ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingA @Nested class Unsupported { - /** - * The {@link ClassCastException} caught here manifests a Hibernate ORM bug. The issue goes away if the - * {@link ItemWithBoxedBytesArrayValue#bytes} field is removed. Otherwise, the behavior of this test should have - * been equivalent to {@link #testBytesCollectionValue()}. - */ - @Test - void testBoxedBytesArrayValue() { - var item = new ItemWithBoxedBytesArrayValue(1, new byte[] {1}, new Byte[] {2}); - assertThatThrownBy(() -> sessionFactoryScope.inTransaction(session -> session.persist(item))) - .isInstanceOf(ClassCastException.class); - } @Test void testBytesCollectionValue() { diff --git a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java index 84148316..90db460a 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java @@ -50,8 +50,13 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.ValueSource; @ExtendWith(MongoExtension.class) +@ParameterizedClass +@ValueSource(booleans = {true, false}) class MongoPreparedStatementIntegrationTests { @AutoClose @@ -63,6 +68,9 @@ class MongoPreparedStatementIntegrationTests { @AutoClose private Session session; + @Parameter + private boolean autoCommit; + @BeforeAll static void beforeAll() { sessionFactory = new Configuration().buildSessionFactory(); @@ -405,6 +413,7 @@ private void doWorkAwareOfAutoCommit(Work work) { } void doAwareOfAutoCommit(Connection connection, SqlExecutable work) throws SQLException { - doWithSpecifiedAutoCommit(false, connection, () -> doAndTerminateTransaction(connection, work)); + doWithSpecifiedAutoCommit( + autoCommit, connection, autoCommit ? work : () -> doAndTerminateTransaction(connection, work)); } } diff --git a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementWithAutoCommitIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementWithAutoCommitIntegrationTests.java deleted file mode 100644 index a636b015..00000000 --- a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementWithAutoCommitIntegrationTests.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2024-present MongoDB, Inc. - * - * 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 com.mongodb.hibernate.jdbc; - -import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.doWithSpecifiedAutoCommit; - -import com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.SqlExecutable; -import java.sql.Connection; -import java.sql.SQLException; - -class MongoPreparedStatementWithAutoCommitIntegrationTests extends MongoPreparedStatementIntegrationTests { - @Override - void doAwareOfAutoCommit(Connection connection, SqlExecutable work) throws SQLException { - doWithSpecifiedAutoCommit(true, connection, work); - } -} diff --git a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementIntegrationTests.java index fc220a61..b16fd2fc 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementIntegrationTests.java @@ -41,8 +41,13 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.ValueSource; @ExtendWith(MongoExtension.class) +@ParameterizedClass +@ValueSource(booleans = {true, false}) class MongoStatementIntegrationTests { @AutoClose @@ -54,6 +59,9 @@ class MongoStatementIntegrationTests { @AutoClose private Session session; + @Parameter + boolean autoCommit; + @BeforeAll static void beforeAll() { sessionFactory = new Configuration().buildSessionFactory(); @@ -278,7 +286,8 @@ private void doWorkAwareOfAutoCommit(Work work) { } void doAwareOfAutoCommit(Connection connection, SqlExecutable work) throws SQLException { - doWithSpecifiedAutoCommit(false, connection, () -> doAndTerminateTransaction(connection, work)); + doWithSpecifiedAutoCommit( + autoCommit, connection, autoCommit ? work : () -> doAndTerminateTransaction(connection, work)); } static void doWithSpecifiedAutoCommit(boolean autoCommit, Connection connection, SqlExecutable work) diff --git a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementWithAutoCommitIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementWithAutoCommitIntegrationTests.java deleted file mode 100644 index 10bae994..00000000 --- a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementWithAutoCommitIntegrationTests.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2025-present MongoDB, Inc. - * - * 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 com.mongodb.hibernate.jdbc; - -import java.sql.Connection; -import java.sql.SQLException; - -class MongoStatementWithAutoCommitIntegrationTests extends MongoStatementIntegrationTests { - @Override - void doAwareOfAutoCommit(Connection connection, SqlExecutable work) throws SQLException { - doWithSpecifiedAutoCommit(true, connection, work); - } -} From 64e032f925b04290bfae42c32c689f68ce3547cb Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Thu, 14 Aug 2025 13:01:04 -0400 Subject: [PATCH 2/3] add back deleted testing case by accident --- .../hibernate/ArrayAndCollectionIntegrationTests.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java index 03287cc0..6c2b743d 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java @@ -595,6 +595,13 @@ static class ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingA @Nested class Unsupported { + @Test + void testBoxedBytesArrayValue() { + var item = new ItemWithBoxedBytesArrayValue(1, new byte[] {1}, new Byte[] {2}); + assertThatThrownBy(() -> sessionFactoryScope.inTransaction(session -> session.persist(item))) + .hasCauseInstanceOf(SQLFeatureNotSupportedException.class); + } + @Test void testBytesCollectionValue() { var item = new ItemWithBytesCollectionValue(1, List.of((byte) 2)); From 80c99ba8bcab13108ddecb818d7b9fa6d69d605b Mon Sep 17 00:00:00 2001 From: Valentin Kovalenko Date: Thu, 28 Aug 2025 00:00:52 -0600 Subject: [PATCH 3/3] Improve the proposed changed --- ...ongoPreparedStatementIntegrationTests.java | 11 ++-------- .../jdbc/MongoStatementIntegrationTests.java | 22 ++++++++++++------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java index 90db460a..5c826838 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoPreparedStatementIntegrationTests.java @@ -17,8 +17,7 @@ package com.mongodb.hibernate.jdbc; import static com.mongodb.hibernate.internal.MongoConstants.ID_FIELD_NAME; -import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.doAndTerminateTransaction; -import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.doWithSpecifiedAutoCommit; +import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.doWorkWithSpecifiedAutoCommit; import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.insertTestData; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -30,7 +29,6 @@ import com.mongodb.client.MongoCollection; import com.mongodb.client.model.Sorts; -import com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.SqlExecutable; import com.mongodb.hibernate.junit.InjectMongoCollection; import com.mongodb.hibernate.junit.MongoExtension; import java.math.BigDecimal; @@ -409,11 +407,6 @@ private void assertExecuteUpdate( } private void doWorkAwareOfAutoCommit(Work work) { - session.doWork(connection -> doAwareOfAutoCommit(connection, () -> work.execute(connection))); - } - - void doAwareOfAutoCommit(Connection connection, SqlExecutable work) throws SQLException { - doWithSpecifiedAutoCommit( - autoCommit, connection, autoCommit ? work : () -> doAndTerminateTransaction(connection, work)); + doWorkWithSpecifiedAutoCommit(autoCommit, session, work); } } diff --git a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementIntegrationTests.java b/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementIntegrationTests.java index b16fd2fc..c1746193 100644 --- a/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementIntegrationTests.java +++ b/src/integrationTest/java/com/mongodb/hibernate/jdbc/MongoStatementIntegrationTests.java @@ -60,7 +60,7 @@ class MongoStatementIntegrationTests { private Session session; @Parameter - boolean autoCommit; + private boolean autoCommit; @BeforeAll static void beforeAll() { @@ -282,15 +282,20 @@ static void insertTestData(Session session, String insertMql) { } private void doWorkAwareOfAutoCommit(Work work) { - session.doWork(connection -> doAwareOfAutoCommit(connection, () -> work.execute(connection))); + doWorkWithSpecifiedAutoCommit(autoCommit, session, work); } - void doAwareOfAutoCommit(Connection connection, SqlExecutable work) throws SQLException { - doWithSpecifiedAutoCommit( - autoCommit, connection, autoCommit ? work : () -> doAndTerminateTransaction(connection, work)); + static void doWorkWithSpecifiedAutoCommit(boolean autoCommit, Session session, Work work) { + session.doWork(connection -> { + SqlExecutable executable = () -> work.execute(connection); + doWithSpecifiedAutoCommit( + autoCommit, + connection, + autoCommit ? executable : () -> doAndTerminateTransaction(connection, executable)); + }); } - static void doWithSpecifiedAutoCommit(boolean autoCommit, Connection connection, SqlExecutable work) + private static void doWithSpecifiedAutoCommit(boolean autoCommit, Connection connection, SqlExecutable work) throws SQLException { var originalAutoCommit = connection.getAutoCommit(); connection.setAutoCommit(autoCommit); @@ -301,7 +306,8 @@ static void doWithSpecifiedAutoCommit(boolean autoCommit, Connection connection, } } - static void doAndTerminateTransaction(Connection connectionNoAutoCommit, SqlExecutable work) throws SQLException { + private static void doAndTerminateTransaction(Connection connectionNoAutoCommit, SqlExecutable work) + throws SQLException { Throwable primaryException = null; try { work.execute(); @@ -320,7 +326,7 @@ static void doAndTerminateTransaction(Connection connectionNoAutoCommit, SqlExec } } - interface SqlExecutable { + private interface SqlExecutable { void execute() throws SQLException; } }