Revert "TAP5-2588: JPA patches provided by Dmitris Zenios"
authorThiago H. de Paula Figueiredo <thiago@arsmachina.com.br>
Thu, 6 Dec 2018 01:43:22 +0000 (23:43 -0200)
committerThiago H. de Paula Figueiredo <thiago@arsmachina.com.br>
Thu, 6 Dec 2018 01:43:22 +0000 (23:43 -0200)
It caused test failures, so reverting these changes for now.
This reverts commit 3c28f94a4814f3294ff4e8179109c72ffa7f0722.

15 files changed:
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AnnotationAccessImpl.java
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/AspectDecoratorImpl.java
tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/CommitAfterWorker.java
tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityTransactionManagerImpl.java
tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/JpaAdvisorProvider.java [deleted file]
tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/JpaAdvisorProviderImpl.java [deleted file]
tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/JpaInternalUtils.java
tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/JpaTransactionAdvisorImpl.java
tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceContextSpecificEntityTransactionManager.java
tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/modules/JpaModule.java
tapestry-jpa/src/test/conf/testng.xml
tapestry-jpa/src/test/java/org/apache/tapestry5/internal/jpa/JpaTransactionAdvisorImplTest.java
tapestry-jpa/src/test/java/org/example/app5/services/AppModule.java
tapestry-runner/build.gradle
tapestry-runner/src/main/java/org/apache/tapestry5/test/TomcatRunner.java

index f8c6155..b088cb9 100644 (file)
 
 package org.apache.tapestry5.ioc.internal;
 
-import org.apache.tapestry5.func.F;
-import org.apache.tapestry5.func.Flow;
-import org.apache.tapestry5.func.Mapper;
 import org.apache.tapestry5.ioc.AnnotationAccess;
 import org.apache.tapestry5.ioc.AnnotationProvider;
-import org.apache.tapestry5.ioc.internal.services.AnnotationProviderChain;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 
-import java.lang.reflect.Method;
-
 /**
- * Standard AnnotationAccess for an array of classes
+ * Standard AnnotationAccess for a specific type.
  * 
  * @since 5.3
  */
 public class AnnotationAccessImpl implements AnnotationAccess
 {
-    private final Class[] classes;
+    private final Class type;
 
-    public AnnotationAccessImpl(Class ...types)
+    public AnnotationAccessImpl(Class type)
     {
-        this.classes = types;
+        this.type = type;
     }
 
     @Override
     public AnnotationProvider getClassAnnotationProvider()
     {
-        return AnnotationProviderChain.create(F.flow(classes).removeNulls().map(InternalUtils.CLASS_TO_AP_MAPPER).toList());
+        return InternalUtils.toAnnotationProvider(type);
     }
 
     @Override
-    public AnnotationProvider getMethodAnnotationProvider(String methodName, Class... parameterTypes) {
-        Flow<Class> searchClasses = F.flow(classes).removeNulls();
-        return AnnotationProviderChain.create(searchClasses.map(new Mapper<Class, Method>() {
-            @Override
-            public Method map(Class element) {
-                return InternalUtils.findMethod(element, methodName, parameterTypes);
-            }
-        }).map(InternalUtils.METHOD_TO_AP_MAPPER).toList());
+    public AnnotationProvider getMethodAnnotationProvider(String methodName, Class... parameterTypes)
+    {
+        return InternalUtils.toAnnotationProvider(InternalUtils.findMethod(type, methodName, parameterTypes));
     }
 
 }
index f37770e..18aa888 100644 (file)
@@ -39,7 +39,7 @@ public class AspectDecoratorImpl implements AspectDecorator
     @Override
     public <T> AspectInterceptorBuilder<T> createBuilder(Class<T> serviceInterface, final T delegate, String description)
     {
-        return createBuilder(serviceInterface, delegate, new AnnotationAccessImpl(delegate.getClass(),serviceInterface), description);
+        return createBuilder(serviceInterface, delegate, new AnnotationAccessImpl(delegate.getClass()), description);
     }
 
     @Override
index 7c1d63c..30046e8 100644 (file)
 
 package org.apache.tapestry5.internal.jpa;
 
+import java.util.HashMap;
+import java.util.Map;
 
+import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 
+import org.apache.tapestry5.jpa.EntityManagerManager;
+import org.apache.tapestry5.jpa.EntityTransactionManager;
 import org.apache.tapestry5.jpa.annotations.CommitAfter;
 import org.apache.tapestry5.model.MutableComponentModel;
+import org.apache.tapestry5.plastic.MethodAdvice;
 import org.apache.tapestry5.plastic.PlasticClass;
 import org.apache.tapestry5.plastic.PlasticMethod;
 import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
@@ -26,22 +32,27 @@ import org.apache.tapestry5.services.transform.TransformationSupport;
 
 public class CommitAfterWorker implements ComponentClassTransformWorker2
 {
-    private final JpaAdvisorProvider jpaAdvisorProvider;
+    private final Map<String, MethodAdvice> methodAdvices;
 
-    public CommitAfterWorker(JpaAdvisorProvider jpaAdvisorProvider)
+    public CommitAfterWorker(EntityManagerManager manager,
+            EntityTransactionManager transactionManager)
     {
-        this.jpaAdvisorProvider = jpaAdvisorProvider;
+        methodAdvices = new HashMap<>(manager.getEntityManagers().size());
+        for (Map.Entry<String, EntityManager> entry : manager.getEntityManagers().entrySet())
+            methodAdvices.put(entry.getKey(),
+                    new CommitAfterMethodAdvice(transactionManager, entry.getKey()));
+        methodAdvices.put(null, new CommitAfterMethodAdvice(transactionManager, null));
     }
 
     @Override
     public void transform(PlasticClass plasticClass, TransformationSupport support,
-                          MutableComponentModel model)
+            MutableComponentModel model)
     {
         for (final PlasticMethod method : plasticClass.getMethodsWithAnnotation(CommitAfter.class))
         {
             PersistenceContext annotation = method.getAnnotation(PersistenceContext.class);
 
-            method.addAdvice(jpaAdvisorProvider.getAdvice(annotation));
+            method.addAdvice(methodAdvices.get(annotation == null ? null : annotation.unitName()));
         }
     }
 }
index 28500c4..c0c639d 100644 (file)
@@ -16,6 +16,8 @@ package org.apache.tapestry5.internal.jpa;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.persistence.EntityManager;
+
 import org.apache.tapestry5.ioc.Invokable;
 import org.apache.tapestry5.ioc.ScopeConstants;
 import org.apache.tapestry5.ioc.annotations.Scope;
@@ -36,8 +38,28 @@ public class EntityTransactionManagerImpl implements EntityTransactionManager
     {
         this.logger = logger;
         this.entityManagerManager = entityManagerManager;
-        this.transactionManagerMap = new HashMap<>(entityManagerManager.getEntityManagers().size());
+        transactionManagerMap = new HashMap<>(entityManagerManager.getEntityManagers().size());
+    }
+
+    private EntityManager getEntityManager(String unitName)
+    {
+        // EntityManager em = JpaInternalUtils.getEntityManager(entityManagerManager, unitName);
+        // FIXME we should simply incorporate the logic in JpaInternalUtils.getEntityManager to
+        // EntityManagerManager.getEntityManager(unitName)
+        if (unitName != null)
+            return entityManagerManager.getEntityManager(unitName);
+        else
+        {
+            Map<String, EntityManager> entityManagers = entityManagerManager.getEntityManagers();
+            if (entityManagers.size() == 1)
+                return entityManagers.values().iterator().next();
+            else
+                throw new RuntimeException(
+                        "Unable to locate a single EntityManager. "
+                                + "You must provide the persistence unit name as defined in the persistence.xml using the @PersistenceContext annotation.");
+        }
     }
+
     /*
      * (non-Javadoc)
      * @see net.satago.tapestry5.jpa.EntityTransactionManager#runInTransaction(java.lang.String,
@@ -69,7 +91,7 @@ public class EntityTransactionManagerImpl implements EntityTransactionManager
         if (!transactionManagerMap.containsKey(unitName))
         {
             PersistenceContextSpecificEntityTransactionManager transactionManager = new PersistenceContextSpecificEntityTransactionManager(
-                    logger, JpaInternalUtils.getEntityManager(entityManagerManager,unitName));
+                    logger, getEntityManager(unitName));
             transactionManagerMap.put(unitName, transactionManager);
             return transactionManager;
         }
diff --git a/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/JpaAdvisorProvider.java b/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/JpaAdvisorProvider.java
deleted file mode 100644 (file)
index 108d55f..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.apache.tapestry5.internal.jpa;
-
-import org.apache.tapestry5.plastic.MethodAdvice;
-
-import javax.persistence.PersistenceContext;
-
-public interface JpaAdvisorProvider {
-    MethodAdvice getAdvice(PersistenceContext context);
-}
diff --git a/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/JpaAdvisorProviderImpl.java b/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/JpaAdvisorProviderImpl.java
deleted file mode 100644 (file)
index 51b50b4..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.tapestry5.internal.jpa;
-
-import org.apache.tapestry5.jpa.EntityTransactionManager;
-import org.apache.tapestry5.plastic.MethodAdvice;
-
-import javax.persistence.PersistenceContext;
-
-public class JpaAdvisorProviderImpl implements JpaAdvisorProvider {
-    private final MethodAdvice shared;
-    private final EntityTransactionManager transactionManager;
-
-    public JpaAdvisorProviderImpl(EntityTransactionManager transactionManager) {
-        this.shared = new CommitAfterMethodAdvice(transactionManager, null);
-        this.transactionManager = transactionManager;
-    }
-    @Override
-    public MethodAdvice getAdvice(PersistenceContext context) {
-        return context == null ? shared : new CommitAfterMethodAdvice(transactionManager,context.unitName());
-    }
-}
index aff8e21..d612e74 100644 (file)
@@ -78,15 +78,10 @@ public class JpaInternalUtils
     }
 
     public static EntityManager getEntityManager(EntityManagerManager entityManagerManager,
-                                                 PersistenceContext annotation) {
+                                                 PersistenceContext annotation)
+    {
         String unitName = annotation == null ? null : annotation.unitName();
-        return getEntityManager(entityManagerManager, unitName);
-    }
-
 
-    public static EntityManager getEntityManager(EntityManagerManager entityManagerManager,
-                                                 String unitName)
-    {
         if (InternalUtils.isNonBlank(unitName))
             return entityManagerManager.getEntityManager(unitName);
 
index 7d7437c..1803722 100644 (file)
 package org.apache.tapestry5.internal.jpa;
 
 import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
 
+import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 
 import org.apache.tapestry5.ioc.MethodAdviceReceiver;
-
+import org.apache.tapestry5.jpa.EntityManagerManager;
+import org.apache.tapestry5.jpa.EntityTransactionManager;
 import org.apache.tapestry5.jpa.JpaTransactionAdvisor;
 import org.apache.tapestry5.jpa.annotations.CommitAfter;
+import org.apache.tapestry5.plastic.MethodAdvice;
 
 public class JpaTransactionAdvisorImpl implements JpaTransactionAdvisor
 {
-    private final JpaAdvisorProvider jpaAdvisorProvider;
+    private final Map<String, MethodAdvice> methodAdvices;
 
-    public JpaTransactionAdvisorImpl(JpaAdvisorProvider jpaAdvisorProvider)
+    public JpaTransactionAdvisorImpl(EntityManagerManager manager,
+            EntityTransactionManager transactionManager)
     {
-        this.jpaAdvisorProvider = jpaAdvisorProvider;
+        methodAdvices = new HashMap<>(manager.getEntityManagers().size());
+        for (Map.Entry<String, EntityManager> entry : manager.getEntityManagers().entrySet())
+            methodAdvices.put(entry.getKey(),
+                    new CommitAfterMethodAdvice(transactionManager, entry.getKey()));
+        methodAdvices.put(null, new CommitAfterMethodAdvice(transactionManager, null));
     }
 
     @Override
@@ -39,8 +49,11 @@ public class JpaTransactionAdvisorImpl implements JpaTransactionAdvisor
         {
             if (m.getAnnotation(CommitAfter.class) != null)
             {
-                PersistenceContext annotation = receiver.getMethodAnnotation(m, PersistenceContext.class);
-                receiver.adviseMethod(m, jpaAdvisorProvider.getAdvice(annotation));
+                PersistenceContext annotation = receiver.getMethodAnnotation(m,
+                        PersistenceContext.class);
+
+                receiver.adviseMethod(m,
+                        methodAdvices.get(annotation == null ? null : annotation.unitName()));
             }
         }
     }
index 43405f2..ed53f2b 100644 (file)
@@ -67,7 +67,6 @@ public class PersistenceContextSpecificEntityTransactionManager
 
     public <T> T invokeInTransaction(Invokable<T> invokable)
     {
-        final EntityTransaction transaction = getTransaction();
         if (transactionBeingCommitted)
         {
             // happens for example if you try to run a transaction in @PostCommit hook. We can only
@@ -80,7 +79,7 @@ public class PersistenceContextSpecificEntityTransactionManager
             }
             else
             {
-                rollbackTransaction(transaction);
+                rollbackTransaction(getTransaction());
                 throw new RuntimeException(
                         "Current transaction is already being committed. Transactions started @PostCommit are not allowed to return a value");
             }
@@ -96,6 +95,7 @@ public class PersistenceContextSpecificEntityTransactionManager
             }
         }
 
+        final EntityTransaction transaction = getTransaction();
         try
         {
             T result = invokable.invoke();
@@ -104,11 +104,15 @@ public class PersistenceContextSpecificEntityTransactionManager
             {
                 // Success or checked exception:
 
-                boolean isActive = transaction.isActive();
-                if (isActive)
+                if (transaction.isActive())
                 {
                     invokeBeforeCommit(transaction);
-                    // FIXME check if we are still on top
+                }
+
+                // FIXME check if we are still on top
+
+                if (transaction.isActive())
+                {
                     transactionBeingCommitted = true;
                     transaction.commit();
                     transactionBeingCommitted = false;
index f78b71c..723b38a 100644 (file)
@@ -23,7 +23,17 @@ import javax.persistence.spi.PersistenceUnitInfo;
 
 import org.apache.tapestry5.ValueEncoder;
 import org.apache.tapestry5.internal.InternalConstants;
-import org.apache.tapestry5.internal.jpa.*;
+import org.apache.tapestry5.internal.jpa.CommitAfterWorker;
+import org.apache.tapestry5.internal.jpa.EntityApplicationStatePersistenceStrategy;
+import org.apache.tapestry5.internal.jpa.EntityManagerManagerImpl;
+import org.apache.tapestry5.internal.jpa.EntityManagerObjectProvider;
+import org.apache.tapestry5.internal.jpa.EntityManagerSourceImpl;
+import org.apache.tapestry5.internal.jpa.EntityPersistentFieldStrategy;
+import org.apache.tapestry5.internal.jpa.EntityTransactionManagerImpl;
+import org.apache.tapestry5.internal.jpa.JpaTransactionAdvisorImpl;
+import org.apache.tapestry5.internal.jpa.JpaValueEncoder;
+import org.apache.tapestry5.internal.jpa.PackageNamePersistenceUnitConfigurer;
+import org.apache.tapestry5.internal.jpa.PersistenceContextWorker;
 import org.apache.tapestry5.internal.services.PersistentFieldManager;
 import org.apache.tapestry5.ioc.Configuration;
 import org.apache.tapestry5.ioc.LoggerSource;
@@ -74,7 +84,6 @@ public class JpaModule
         binder.bind(PersistenceUnitConfigurer.class, PackageNamePersistenceUnitConfigurer.class).withSimpleId();
         binder.bind(EntityManagerSource.class, EntityManagerSourceImpl.class);
         binder.bind(EntityTransactionManager.class, EntityTransactionManagerImpl.class);
-        binder.bind(JpaAdvisorProvider.class,JpaAdvisorProviderImpl.class);
 
     }
 
index 9267615..025f946 100644 (file)
@@ -8,49 +8,47 @@
        the specific language governing permissions and limitations under the License. -->
 
 <suite name="Tapestry JPA" parallel="false" thread-count="10"
-          annotations="1.5" verbose="2">
-       <test name="Tapestry JPA Integration Tests" enabled="true">
-               <parameter name="tapestry.web-app-folder" value="src/test/app1" />
-               <packages>
-                       <package name="org.apache.tapestry5.jpa.integration.app1" />
-               </packages>
-       </test>
+       annotations="1.5" verbose="2">
+<!--   <test name="Tapestry JPA Integration Tests" enabled="true"> -->
+<!--           <parameter name="tapestry.web-app-folder" value="src/test/app1" /> -->
+<!--           <packages> -->
+<!--                   <package name="org.apache.tapestry5.jpa.integration.app1" /> -->
+<!--           </packages> -->
+<!--   </test> -->
 
-       <test name="Single Persistence Unit Integration Tests" enabled="true">
-               <parameter name="tapestry.web-app-folder" value="src/test/app2" />
-               <packages>
-                       <package name="org.apache.tapestry5.jpa.integration.app2" />
-               </packages>
-       </test>
+<!--   <test name="Single Persistence Unit Integration Tests" enabled="true"> -->
+<!--           <parameter name="tapestry.web-app-folder" value="src/test/app2" /> -->
+<!--           <packages> -->
+<!--                   <package name="org.apache.tapestry5.jpa.integration.app2" /> -->
+<!--           </packages> -->
+<!--   </test> -->
 
-       <test name="JNDI DataSource Integration Tests" enabled="true">
-               <parameter name="tapestry.web-app-folder" value="src/test/app3" />
-               <parameter name="tapestry.servlet-container" value="tomcat6" />
-               <packages>
-                       <package name="org.apache.tapestry5.jpa.integration.app3" />
-               </packages>
-       </test>
+<!--   <test name="JNDI DataSource Integration Tests" enabled="true"> -->
+<!--           <parameter name="tapestry.web-app-folder" value="src/test/app3" /> -->
+<!--           <parameter name="tapestry.servlet-container" value="tomcat6" /> -->
+<!--           <packages> -->
+<!--                   <package name="org.apache.tapestry5.jpa.integration.app3" /> -->
+<!--           </packages> -->
+<!--   </test> -->
 
+<!--   <test name="Explicit Provider Class Name In Persistence Unit Integration Tests" enabled="true"> -->
+<!--           <parameter name="tapestry.web-app-folder" value="src/test/app5" /> -->
+<!--           <packages> -->
+<!--                   <package name="org.apache.tapestry5.jpa.integration.app5" /> -->
+<!--           </packages> -->
+<!--   </test> -->
+
+<!--   <test name="Tapestry JPA Unit Tests" enabled="false"> -->
+<!--           <packages> -->
+<!--                   <package name="org.apache.tapestry5.internal.jpa" /> -->
+<!--           </packages> -->
+<!--   </test> -->
+       
        <test name="Tapestry JPA Integration Tests with Annotations in Service Implementation" enabled="true">
                <parameter name="tapestry.web-app-folder" value="src/test/app6" />
                <packages>
                        <package name="org.apache.tapestry5.jpa.integration.app6" />
                </packages>
        </test>
-
-       <test name="Tapestry JPA Unit Tests" enabled="true">
-               <packages>
-                       <package name="org.apache.tapestry5.internal.jpa" />
-               </packages>
-       </test>
-
-       <!-- Put this last since it modifies
-    PersistenceProviderResolverHolder.setPersistenceProviderResolver
-    which affects other test suites -->
-       <test name="Explicit Provider Class Name In Persistence Unit Integration Tests" enabled="true">
-               <parameter name="tapestry.web-app-folder" value="src/test/app5" />
-               <packages>
-                       <package name="org.apache.tapestry5.jpa.integration.app5" />
-               </packages>
-       </test>
+       
 </suite>
index 92ffd33..6d3eb40 100644 (file)
@@ -32,7 +32,6 @@ import org.apache.tapestry5.jpa.EntityManagerManager;
 import org.apache.tapestry5.jpa.EntityTransactionManager;
 import org.apache.tapestry5.jpa.JpaTransactionAdvisor;
 import org.apache.tapestry5.jpa.annotations.CommitAfter;
-import org.slf4j.LoggerFactory;
 import org.testng.Assert;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
@@ -67,9 +66,10 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     public void undecorated()
     {
         final VoidService delegate = newMock(VoidService.class);
+        final EntityManagerManager manager = newMock(EntityManagerManager.class);
         final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
+
         final AspectInterceptorBuilder<VoidService> builder = aspectDecorator.createBuilder(
                 VoidService.class, delegate, "foo.Bar");
 
@@ -87,20 +87,14 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     @Test
     public void persistence_unit_name_missing()
     {
+        final VoidService delegate = newMock(VoidService.class);
+        final EntityManagerManager manager = newMock(EntityManagerManager.class);
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         Map<String, EntityManager> managers = CollectionFactory.newMap();
         managers.put("A", newMock(EntityManager.class));
         managers.put("B", newMock(EntityManager.class));
 
-        final VoidService delegate = newMock(VoidService.class);
-        final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(managers);
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
         final AspectInterceptorBuilder<VoidService> builder = aspectDecorator.createBuilder(
                 VoidService.class, delegate, "foo.Bar");
 
@@ -127,23 +121,14 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     @Test
     public void persistence_unit_name_missing_single_unit_configured()
     {
-        EntityManager em = newMock(EntityManager.class);
-        Map<String, EntityManager> managers = CollectionFactory.newMap();
-        managers.put("A", em);
-
         final VoidService delegate = newMock(VoidService.class);
         final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(managers);
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
-
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         final EntityTransaction transaction = newMock(EntityTransaction.class);
-
+        EntityManager em = newMock(EntityManager.class);
+        Map<String, EntityManager> managers = CollectionFactory.newMap();
+        managers.put("A", em);
 
         final AspectInterceptorBuilder<VoidService> builder = aspectDecorator.createBuilder(
                 VoidService.class, delegate, "foo.Bar");
@@ -165,23 +150,14 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     @Test
     public void persistence_unit_missing()
     {
+        final VoidService delegate = newMock(VoidService.class);
+        final EntityManagerManager manager = newMock(EntityManagerManager.class);
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         Map<String, EntityManager> managers = CollectionFactory.newMap();
         managers.put("A", newMock(EntityManager.class));
         managers.put("B", newMock(EntityManager.class));
 
-        final VoidService delegate = newMock(VoidService.class);
-        final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(managers);
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
-
-
         final AspectInterceptorBuilder<VoidService> builder = aspectDecorator.createBuilder(
                 VoidService.class, delegate, "foo.Bar");
 
@@ -208,20 +184,14 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     @Test
     public void persistence_unit_missing_single_unit_configured()
     {
-        EntityManager em = newMock(EntityManager.class);
-        Map<String, EntityManager> managers = CollectionFactory.newMap();
-        managers.put("A", em);
         final VoidService delegate = newMock(VoidService.class);
         final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(managers);
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         final EntityTransaction transaction = newMock(EntityTransaction.class);
+        EntityManager em = newMock(EntityManager.class);
+        Map<String, EntityManager> managers = CollectionFactory.newMap();
+        managers.put("A", em);
 
         final AspectInterceptorBuilder<VoidService> builder = aspectDecorator.createBuilder(
                 VoidService.class, delegate, "foo.Bar");
@@ -245,14 +215,8 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     {
         final VoidService delegate = newMock(VoidService.class);
         final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(CollectionFactory.newMap());
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         final EntityManager entityManager = newMock(EntityManager.class);
         final EntityTransaction transaction = newMock(EntityTransaction.class);
 
@@ -279,14 +243,8 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     {
         final VoidService delegate = newMock(VoidService.class);
         final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(CollectionFactory.newMap());
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         final EntityManager entityManager = newMock(EntityManager.class);
         final EntityTransaction transaction = newMock(EntityTransaction.class);
 
@@ -313,14 +271,8 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     {
         final VoidService delegate = newMock(VoidService.class);
         final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(CollectionFactory.newMap());
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         final EntityManager entityManager = newMock(EntityManager.class);
         final EntityTransaction transaction = newMock(EntityTransaction.class);
 
@@ -345,14 +297,8 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     {
         final Performer delegate = newMock(Performer.class);
         final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(CollectionFactory.newMap());
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         final EntityManager entityManager = newMock(EntityManager.class);
         final EntityTransaction transaction = newMock(EntityTransaction.class);
         final RuntimeException re = new RuntimeException("Unexpected.");
@@ -387,14 +333,8 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     {
         final Performer delegate = newMock(Performer.class);
         final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(CollectionFactory.newMap());
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         final EntityManager entityManager = newMock(EntityManager.class);
         final EntityTransaction transaction = newMock(EntityTransaction.class);
         final SQLException se = new SQLException("Checked.");
@@ -434,14 +374,8 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     {
         final ReturnTypeService delegate = newTestService();
         final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(CollectionFactory.newMap());
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         final EntityManager entityManager = newMock(EntityManager.class);
         final EntityTransaction transaction = newMock(EntityTransaction.class);
 
@@ -466,14 +400,8 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
     {
         final ReturnTypeService delegate = newTestService();
         final EntityManagerManager manager = newMock(EntityManagerManager.class);
-        expect(manager.getEntityManagers()).andReturn(CollectionFactory.newMap());
-
-        replay();
-        final EntityTransactionManager transactionManager = new EntityTransactionManagerImpl(
-                LoggerFactory.getLogger(EntityTransactionManagerImpl.class),manager);
-        verify();
-        final JpaAdvisorProvider provider = new JpaAdvisorProviderImpl(transactionManager);
-        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(provider);
+        final EntityTransactionManager transactionManager = newMock(EntityTransactionManager.class);
+        final JpaTransactionAdvisor advisor = newJpaTransactionAdvisor(manager, transactionManager);
         final EntityManager entityManager = newMock(EntityManager.class);
         final EntityTransaction transaction = newMock(EntityTransaction.class);
 
@@ -534,9 +462,10 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
         transaction.rollback();
     }
 
-    private JpaTransactionAdvisor newJpaTransactionAdvisor(final JpaAdvisorProvider provider)
+    private JpaTransactionAdvisor newJpaTransactionAdvisor(final EntityManagerManager manager,
+            EntityTransactionManager transactionManager)
     {
-        return new JpaTransactionAdvisorImpl(provider);
+        return new JpaTransactionAdvisorImpl(manager, transactionManager);
     }
 
     private ReturnTypeService newTestService()
@@ -604,4 +533,20 @@ public class JpaTransactionAdvisorImplTest extends IOCTestCase
         @PersistenceContext(unitName = UNIT_NAME)
         void perform() throws SQLException;
     }
+
+    public interface Service
+    {
+       void perform();
+    }
+
+    public class ServiceImpl implements Service {
+       @Override
+       @CommitAfter
+       @PersistenceContext(unitName = UNIT_NAME)
+        public void perform()
+       {
+
+       }
+    }
+
 }
index e3f380a..05d2488 100644 (file)
@@ -34,7 +34,6 @@ public class AppModule
     static
     {
 
-        //This will also affect test suites run after this one.Its better to run this suite last
         PersistenceProviderResolverHolder.setPersistenceProviderResolver(
                 new PersistenceProviderResolver()
                 {
index 3f7a6ff..f905c70 100644 (file)
@@ -10,7 +10,6 @@ dependencies {
 
     compile "org.apache.tomcat:tomcat-catalina:${versions.tomcat}"
     compile "org.apache.tomcat:tomcat-coyote:${versions.tomcat}"
-    compile "org.apache.tomcat:tomcat-jasper:${versions.tomcat}"
 
     compile "org.apache.tomcat:tomcat-dbcp:${versions.tomcat}"
     compile "commons-cli:commons-cli:1.2"
index a37b580..f382330 100644 (file)
@@ -15,6 +15,7 @@
 package org.apache.tapestry5.test;
 
 import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
 
 import java.io.File;
@@ -49,11 +50,8 @@ public class TomcatRunner implements ServletContainerRunner
         if (!tmpDir.endsWith(fileSeparator))
             tmpDir = tmpDir + fileSeparator;
         tomcatServer.setBaseDir(tmpDir + "tomcat");
-        tomcatServer.setPort(port);
-        tomcatServer.addWebapp("/", expandedPath);
 
-        //Enable jndi lookups
-        tomcatServer.enableNaming();
+        tomcatServer.addWebapp("/", expandedPath);
 
         tomcatServer.getConnector().setAllowTrace(true);
 
@@ -70,7 +68,6 @@ public class TomcatRunner implements ServletContainerRunner
         }
 
         tomcatServer.start();
-        startDaemonAwaitThread();
     }
 
     /**
@@ -85,7 +82,6 @@ public class TomcatRunner implements ServletContainerRunner
         {
             // Stop immediately and not gracefully.
             tomcatServer.stop();
-            tomcatServer.destroy();
         }
         catch (Exception ex)
         {
@@ -121,19 +117,4 @@ public class TomcatRunner implements ServletContainerRunner
         return new File(TapestryRunnerConstants.MODULE_BASE_DIR, moduleLocalPath).getPath();
     }
 
-    // Unlike Jetty, all Tomcat threads are daemon threads. We create a
-    // blocking non-daemon to stop immediate shutdown
-    private void startDaemonAwaitThread() {
-        Thread awaitThread = new Thread() {
-
-            @Override
-            public void run() {
-                TomcatRunner.this.tomcatServer.getServer().await();
-            }
-
-        };
-        awaitThread.setContextClassLoader(getClass().getClassLoader());
-        awaitThread.setDaemon(false);
-        awaitThread.start();
-    }
 }