|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2014 the original author or authors. |
| 2 | + * Copyright 2012-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 |
|
21 | 21 | import org.junit.Test;
|
22 | 22 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
| 23 | +import org.springframework.context.annotation.Bean; |
| 24 | +import org.springframework.context.annotation.Configuration; |
23 | 25 | import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
| 26 | +import org.springframework.transaction.PlatformTransactionManager; |
24 | 27 | import org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration;
|
25 | 28 | import org.springframework.transaction.annotation.EnableTransactionManagement;
|
26 | 29 |
|
27 | 30 | import static org.junit.Assert.assertEquals;
|
28 | 31 | import static org.junit.Assert.assertNotNull;
|
| 32 | +import static org.mockito.Mockito.mock; |
29 | 33 |
|
30 | 34 | /**
|
31 | 35 | * Tests for {@link DataSourceTransactionManagerAutoConfiguration}.
|
32 | 36 | *
|
33 | 37 | * @author Dave Syer
|
| 38 | + * @author Stephane Nicoll |
34 | 39 | */
|
35 | 40 | public class DataSourceTransactionManagerAutoConfigurationTests {
|
36 | 41 |
|
@@ -67,9 +72,32 @@ public void testManualConfiguration() throws Exception {
|
67 | 72 | assertNotNull(this.context.getBean(DataSourceTransactionManager.class));
|
68 | 73 | }
|
69 | 74 |
|
| 75 | + @Test |
| 76 | + public void testExistingTransactionManager() { |
| 77 | + this.context.register(SwitchTransactionsOn.class, |
| 78 | + TransactionManagerConfiguration.class, |
| 79 | + EmbeddedDataSourceConfiguration.class, |
| 80 | + DataSourceTransactionManagerAutoConfiguration.class); |
| 81 | + this.context.refresh(); |
| 82 | + assertEquals("No transaction manager should be been created", 1, |
| 83 | + this.context.getBeansOfType(PlatformTransactionManager.class).size()); |
| 84 | + assertEquals("Wrong transaction manager", this.context.getBean("myTransactionManager"), |
| 85 | + this.context.getBean(PlatformTransactionManager.class)); |
| 86 | + } |
| 87 | + |
70 | 88 | @EnableTransactionManagement
|
71 | 89 | protected static class SwitchTransactionsOn {
|
72 | 90 |
|
73 | 91 | }
|
74 | 92 |
|
| 93 | + @Configuration |
| 94 | + protected static class TransactionManagerConfiguration { |
| 95 | + |
| 96 | + @Bean |
| 97 | + public PlatformTransactionManager myTransactionManager() { |
| 98 | + return mock(PlatformTransactionManager.class); |
| 99 | + } |
| 100 | + |
| 101 | + } |
| 102 | + |
75 | 103 | }
|
0 commit comments