|
27 | 27 | import java.util.Map;
|
28 | 28 |
|
29 | 29 | import org.junit.After;
|
| 30 | +import org.junit.Ignore; |
30 | 31 | import org.junit.Rule;
|
31 | 32 | import org.junit.Test;
|
32 | 33 | import org.junit.rules.ExpectedException;
|
|
40 | 41 | import org.springframework.core.annotation.Order;
|
41 | 42 | import org.springframework.stereotype.Component;
|
42 | 43 | import org.springframework.tests.transaction.CallCountingTransactionManager;
|
| 44 | +import org.springframework.transaction.annotation.EnableTransactionManagement; |
| 45 | +import org.springframework.transaction.annotation.Transactional; |
43 | 46 | import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
44 | 47 | import org.springframework.transaction.support.TransactionSynchronizationManager;
|
45 | 48 | import org.springframework.transaction.support.TransactionTemplate;
|
@@ -147,6 +150,20 @@ public void afterCommit() {
|
147 | 150 | getEventCollector().assertTotalEventsCount(1); // After rollback not invoked
|
148 | 151 | }
|
149 | 152 |
|
| 153 | + // TODO [SPR-12738] Enable test. |
| 154 | + @Ignore("Disabled until SPR-12738 is resolved") |
| 155 | + @Test |
| 156 | + public void afterCommitWithTransactionalComponentListenerProxiedViaDynamicProxy() { |
| 157 | + load(TransactionalConfiguration.class, TransactionalComponentAfterCommitTestListener.class); |
| 158 | + this.transactionTemplate.execute(status -> { |
| 159 | + getContext().publishEvent("SKIP"); |
| 160 | + getEventCollector().assertNoEventReceived(); |
| 161 | + return null; |
| 162 | + |
| 163 | + }); |
| 164 | + getEventCollector().assertNoEventReceived(); |
| 165 | + } |
| 166 | + |
150 | 167 | @Test
|
151 | 168 | public void afterRollback() {
|
152 | 169 | load(AfterCompletionExplicitTestListener.class);
|
@@ -307,6 +324,16 @@ public EventCollector eventCollector() {
|
307 | 324 | }
|
308 | 325 | }
|
309 | 326 |
|
| 327 | + @EnableTransactionManagement |
| 328 | + @Configuration |
| 329 | + static class TransactionalConfiguration { |
| 330 | + |
| 331 | + @Bean |
| 332 | + public CallCountingTransactionManager transactionManager() { |
| 333 | + return new CallCountingTransactionManager(); |
| 334 | + } |
| 335 | + } |
| 336 | + |
310 | 337 |
|
311 | 338 | protected EventCollector getEventCollector() {
|
312 | 339 | return eventCollector;
|
@@ -359,8 +386,8 @@ public void assertNoEventReceived(String... phases) {
|
359 | 386 | }
|
360 | 387 | for (String phase : phases) {
|
361 | 388 | List<Object> eventsForPhase = getEvents(phase);
|
362 |
| - assertEquals("Expected no event for phase '" + phase + "' " + |
363 |
| - "but got " + eventsForPhase, 0, eventsForPhase.size()); |
| 389 | + assertEquals("Expected no events for phase '" + phase + "' " + |
| 390 | + "but got " + eventsForPhase + ":", 0, eventsForPhase.size()); |
364 | 391 | }
|
365 | 392 | }
|
366 | 393 |
|
@@ -431,6 +458,23 @@ public void handleAfterRollback(String data) {
|
431 | 458 | }
|
432 | 459 | }
|
433 | 460 |
|
| 461 | + @Transactional |
| 462 | + @Component |
| 463 | + static interface TransactionalComponentAfterCommitTestListenerInterface { |
| 464 | + |
| 465 | + @TransactionalEventListener(phase = AFTER_COMMIT, condition = "!'SKIP'.equals(#data)") |
| 466 | + void handleAfterCommit(String data); |
| 467 | + } |
| 468 | + |
| 469 | + static class TransactionalComponentAfterCommitTestListener extends BaseTransactionalTestListener implements |
| 470 | + TransactionalComponentAfterCommitTestListenerInterface { |
| 471 | + |
| 472 | + @Override |
| 473 | + public void handleAfterCommit(String data) { |
| 474 | + handleEvent(EventCollector.AFTER_COMMIT, data); |
| 475 | + } |
| 476 | + } |
| 477 | + |
434 | 478 | @Component
|
435 | 479 | static class BeforeCommitTestListener extends BaseTransactionalTestListener {
|
436 | 480 |
|
|
0 commit comments