This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch CAUSEWAY-3654
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/CAUSEWAY-3654 by this push:
     new f462168e5a CAUSEWAY-3654: fixes JPA integ test
f462168e5a is described below

commit f462168e5a7a30d9509039306c23e74dcdd0d875
Author: danhaywood <d...@haywood-associates.co.uk>
AuthorDate: Tue Dec 12 09:47:08 2023 +0000

    CAUSEWAY-3654: fixes JPA integ test
---
 .../transaction/TransactionServiceSpring.java          |  7 ++++++-
 .../persistence/jdo/JdoExceptionTranslationTest.java   | 13 +++++--------
 .../persistence/jpa/JpaExceptionTranslationTest.java   | 18 ++++++++----------
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git 
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/transaction/TransactionServiceSpring.java
 
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/transaction/TransactionServiceSpring.java
index af7b7149ac..db06ce6363 100644
--- 
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/transaction/TransactionServiceSpring.java
+++ 
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/transaction/TransactionServiceSpring.java
@@ -129,7 +129,12 @@ implements
             registerTransactionSynchronizations(txStatus);
 
 
-            result = Try.call(callable)
+            result = Try.call(() -> {
+                        final T callResult = callable.call();
+                        // we flush here to ensure that the result captures 
any exception, eg from a declarative constraint violation
+                        txStatus.flush();
+                        return callResult;
+                    })
                     .mapFailure(ex->translateExceptionIfPossible(ex, 
platformTransactionManager));
 
 //            if(tx.isNewTransaction()) {
diff --git 
a/regressiontests/stable-persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoExceptionTranslationTest.java
 
b/regressiontests/stable-persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoExceptionTranslationTest.java
index c8ac7f895c..2f31e0a0db 100644
--- 
a/regressiontests/stable-persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoExceptionTranslationTest.java
+++ 
b/regressiontests/stable-persistence-jdo/src/test/java/org/apache/causeway/testdomain/persistence/jdo/JdoExceptionTranslationTest.java
@@ -21,24 +21,22 @@ package org.apache.causeway.testdomain.persistence.jdo;
 import java.sql.SQLException;
 
 import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.dao.DataAccessException;
-import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.TestPropertySources;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.dao.DataAccessException;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.TestPropertySources;
+
 import org.apache.causeway.core.config.presets.CausewayPresets;
 import org.apache.causeway.testdomain.conf.Configuration_usingJdo;
 import org.apache.causeway.testdomain.jdo.RegressionTestWithJdoFixtures;
 import org.apache.causeway.testdomain.jdo.entities.JdoInventory;
 
-import org.springframework.transaction.annotation.Transactional;
-
 import lombok.val;
 
 @SpringBootTest(
@@ -60,7 +58,6 @@ class JdoExceptionTranslationTest extends 
RegressionTestWithJdoFixtures {
         // Util_H2Console.main(null);
     }
 
-    // @Disabled // CAUSEWAY-3654
     @Test
     void booksUniqueByIsbn_whenViolated_shouldThrowTranslatedException() {
 
diff --git 
a/regressiontests/stable-persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaExceptionTranslationTest.java
 
b/regressiontests/stable-persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaExceptionTranslationTest.java
index ed487ed662..f8afe0c294 100644
--- 
a/regressiontests/stable-persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaExceptionTranslationTest.java
+++ 
b/regressiontests/stable-persistence-jpa/src/test/java/org/apache/causeway/testdomain/persistence/jpa/JpaExceptionTranslationTest.java
@@ -22,15 +22,17 @@ import java.sql.SQLException;
 
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.dao.DataAccessException;
-import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.TestPropertySources;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.dao.DataAccessException;
+import org.springframework.dao.DuplicateKeyException;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.TestPropertySources;
+
 import org.apache.causeway.core.config.presets.CausewayPresets;
 import org.apache.causeway.testdomain.conf.Configuration_usingJpa;
 import org.apache.causeway.testdomain.jpa.RegressionTestWithJpaFixtures;
@@ -44,12 +46,11 @@ import lombok.val;
         },
         properties = {
                 
"spring.datasource.url=jdbc:h2:mem:JpaExceptionTranslationTest",
-        })
+        }
+)
 @TestPropertySources({
     @TestPropertySource(CausewayPresets.UseLog4j2Test)
 })
-//@Transactional ... we manage transaction ourselves
-//@DirtiesContext
 class JpaExceptionTranslationTest extends RegressionTestWithJpaFixtures {
 
     @BeforeAll
@@ -61,7 +62,6 @@ class JpaExceptionTranslationTest extends 
RegressionTestWithJpaFixtures {
     @Test
     void booksUniqueByIsbn_whenViolated_shouldThrowTranslatedException() {
 
-
         // when adding a book for which one with same ISBN already exists in 
the database,
         // we expect to see a Spring recognized DataAccessException been thrown
 
@@ -102,7 +102,5 @@ class JpaExceptionTranslationTest extends 
RegressionTestWithJpaFixtures {
             testFixtures.assertInventoryHasBooks(inventory.getProducts(), 1, 
2, 3);
         });
 
-
     }
-
 }

Reply via email to