|
21 | 21 | import static org.springframework.test.transaction.TransactionTestUtils.inTransaction;
|
22 | 22 | import static org.testng.Assert.assertEquals;
|
23 | 23 |
|
| 24 | +import javax.sql.DataSource; |
| 25 | + |
24 | 26 | import org.springframework.beans.Employee;
|
25 | 27 | import org.springframework.beans.Pet;
|
26 | 28 | import org.springframework.beans.factory.annotation.Autowired;
|
| 29 | +import org.springframework.context.annotation.Bean; |
| 30 | +import org.springframework.context.annotation.Configuration; |
| 31 | +import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
| 32 | +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
27 | 33 | import org.springframework.test.annotation.NotTransactional;
|
28 | 34 | import org.springframework.test.context.ContextConfiguration;
|
29 | 35 | import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
30 | 36 | import org.springframework.test.context.transaction.AfterTransaction;
|
31 | 37 | import org.springframework.test.context.transaction.BeforeTransaction;
|
| 38 | +import org.springframework.transaction.PlatformTransactionManager; |
32 | 39 | import org.testng.annotations.AfterClass;
|
33 | 40 | import org.testng.annotations.AfterMethod;
|
34 | 41 | import org.testng.annotations.BeforeClass;
|
@@ -151,4 +158,37 @@ public void afterTransaction() {
|
151 | 158 | assertNumRowsInPersonTable(1, "after a transactional test method");
|
152 | 159 | }
|
153 | 160 |
|
| 161 | + |
| 162 | + @Configuration |
| 163 | + static class ContextConfiguration { |
| 164 | + |
| 165 | + @Bean |
| 166 | + public Employee employee() { |
| 167 | + Employee employee = new Employee(); |
| 168 | + employee.setName("John Smith"); |
| 169 | + employee.setAge(42); |
| 170 | + employee.setCompany("Acme Widgets, Inc."); |
| 171 | + return employee; |
| 172 | + } |
| 173 | + |
| 174 | + @Bean |
| 175 | + public Pet pet() { |
| 176 | + return new Pet("Fido"); |
| 177 | + } |
| 178 | + |
| 179 | + @Bean |
| 180 | + public PlatformTransactionManager transactionManager() { |
| 181 | + return new DataSourceTransactionManager(dataSource()); |
| 182 | + } |
| 183 | + |
| 184 | + @Bean |
| 185 | + public DataSource dataSource() { |
| 186 | + return new EmbeddedDatabaseBuilder()// |
| 187 | + .addScript("classpath:/org/springframework/test/context/testng/schema.sql")// |
| 188 | + .addScript("classpath:/org/springframework/test/context/testng/data.sql")// |
| 189 | + .build(); |
| 190 | + } |
| 191 | + |
| 192 | + } |
| 193 | + |
154 | 194 | }
|
0 commit comments