From 8ece1b145cf8e462a343c6088b4a75af67ea1b89 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 22 Apr 2015 21:35:33 +0200 Subject: [PATCH] Introduce failing/ignored tests for SPR-12738 Issue: SPR-12738 --- .../TransactionalEventListenerTests.java | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/spring-tx/src/test/java/org/springframework/transaction/event/TransactionalEventListenerTests.java b/spring-tx/src/test/java/org/springframework/transaction/event/TransactionalEventListenerTests.java index 8ef57bbf606..e8b5cfb4038 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/event/TransactionalEventListenerTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/event/TransactionalEventListenerTests.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import org.junit.After; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -40,6 +41,8 @@ import org.springframework.context.event.EventListener; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import org.springframework.tests.transaction.CallCountingTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.TransactionSynchronizationAdapter; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.transaction.support.TransactionTemplate; @@ -147,6 +150,20 @@ public class TransactionalEventListenerTests { getEventCollector().assertTotalEventsCount(1); // After rollback not invoked } + // TODO [SPR-12738] Enable test. + @Ignore("Disabled until SPR-12738 is resolved") + @Test + public void afterCommitWithTransactionalComponentListenerProxiedViaDynamicProxy() { + load(TransactionalConfiguration.class, TransactionalComponentAfterCommitTestListener.class); + this.transactionTemplate.execute(status -> { + getContext().publishEvent("SKIP"); + getEventCollector().assertNoEventReceived(); + return null; + + }); + getEventCollector().assertNoEventReceived(); + } + @Test public void afterRollback() { load(AfterCompletionExplicitTestListener.class); @@ -307,6 +324,16 @@ public class TransactionalEventListenerTests { } } + @EnableTransactionManagement + @Configuration + static class TransactionalConfiguration { + + @Bean + public CallCountingTransactionManager transactionManager() { + return new CallCountingTransactionManager(); + } + } + protected EventCollector getEventCollector() { return eventCollector; @@ -359,8 +386,8 @@ public class TransactionalEventListenerTests { } for (String phase : phases) { List eventsForPhase = getEvents(phase); - assertEquals("Expected no event for phase '" + phase + "' " + - "but got " + eventsForPhase, 0, eventsForPhase.size()); + assertEquals("Expected no events for phase '" + phase + "' " + + "but got " + eventsForPhase + ":", 0, eventsForPhase.size()); } } @@ -431,6 +458,23 @@ public class TransactionalEventListenerTests { } } + @Transactional + @Component + static interface TransactionalComponentAfterCommitTestListenerInterface { + + @TransactionalEventListener(phase = AFTER_COMMIT, condition = "!'SKIP'.equals(#data)") + void handleAfterCommit(String data); + } + + static class TransactionalComponentAfterCommitTestListener extends BaseTransactionalTestListener implements + TransactionalComponentAfterCommitTestListenerInterface { + + @Override + public void handleAfterCommit(String data) { + handleEvent(EventCollector.AFTER_COMMIT, data); + } + } + @Component static class BeforeCommitTestListener extends BaseTransactionalTestListener {