tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject [2/7] tomee git commit: Repaired PersistenceTest by adding embedded TransactionBean to assist with transaction management
Date Mon, 10 Dec 2018 13:32:18 GMT
Repaired PersistenceTest by adding embedded TransactionBean to assist with transaction management


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/5d6822ee
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/5d6822ee
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/5d6822ee

Branch: refs/heads/master
Commit: 5d6822ee014f1361741ed377cac6d20727ab3792
Parents: a0665a1
Author: Josh Juneau <juneau@fnal.gov>
Authored: Sun Dec 9 01:18:20 2018 -0600
Committer: Josh Juneau <juneau@fnal.gov>
Committed: Sun Dec 9 01:18:20 2018 -0600

----------------------------------------------------------------------
 .../test/persistence/PersistenceTest.java       | 40 ++++++++++++++++++--
 1 file changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/5d6822ee/examples/arquillian-jpa/src/test/java/org/superbiz/arquillian/test/persistence/PersistenceTest.java
----------------------------------------------------------------------
diff --git a/examples/arquillian-jpa/src/test/java/org/superbiz/arquillian/test/persistence/PersistenceTest.java
b/examples/arquillian-jpa/src/test/java/org/superbiz/arquillian/test/persistence/PersistenceTest.java
index 2cb01e3..3152177 100644
--- a/examples/arquillian-jpa/src/test/java/org/superbiz/arquillian/test/persistence/PersistenceTest.java
+++ b/examples/arquillian-jpa/src/test/java/org/superbiz/arquillian/test/persistence/PersistenceTest.java
@@ -16,6 +16,11 @@
  */
 package org.superbiz.arquillian.test.persistence;
 
+import java.util.concurrent.Callable;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.arquillian.persistence.ShouldMatchDataSet;
@@ -47,17 +52,44 @@ public class PersistenceTest {
 
     @PersistenceContext
     private EntityManager em;
+    
+    @EJB
+    private Caller transactionalCaller;
 
+    
+    public void seriouslyYouAlreadyForgotOpenEJB_questionMark() throws Exception {
+        
+        final User user = em.find(User.class, 2L);
+        assertNotNull(user);
+        
+        user.setName("OpenEJB"); // @Transactional(TransactionMode.COMMIT) will commit it
and datasets/expected-users.yml will check it
+    }
+    
     @Test
     @Transactional(TransactionMode.COMMIT) // default with persistence extension
     @UsingDataSet("datasets/users.yml")
     @ShouldMatchDataSet("datasets/expected-users.yml")
-    public void seriouslyYouAlreadyForgotOpenEJB_questionMark() throws Exception {
+    public void testWithTransaction() throws Exception {
         assertEquals(2, em.createQuery("select count(e) from User e", Number.class).getSingleResult().intValue());
 
-        final User user = em.find(User.class, 2L);
-        assertNotNull(user);
+        transactionalCaller.call(new Callable() {
+            public Object call() throws Exception {
+                seriouslyYouAlreadyForgotOpenEJB_questionMark();
+                return null;
+            }
+        });
+    }
+    
+    public static interface Caller {
+        public <V> V call(Callable<V> callable) throws Exception;
+    }
+    
+    @Stateless
+    @TransactionAttribute(REQUIRES_NEW)
+    public static class TransactionBean implements Caller {
 
-        user.setName("OpenEJB"); // @Transactional(TransactionMode.COMMIT) will commit it
and datasets/expected-users.yml will check it
+        public <V> V call(Callable<V> callable) throws Exception {
+            return callable.call();
+        }
     }
 }


Mime
View raw message