Skip to content

Commit 2b17ee0

Browse files
committed
[SPR-6184] AnnotationConfigContextLoader now defines "$ContextConfiguration" as the resource suffix for generated default @configuration class names.
1 parent 39583d2 commit 2b17ee0

File tree

2 files changed

+40
-65
lines changed

2 files changed

+40
-65
lines changed

org.springframework.test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@
2121
import static org.springframework.test.transaction.TransactionTestUtils.inTransaction;
2222
import static org.testng.Assert.assertEquals;
2323

24+
import javax.sql.DataSource;
25+
2426
import org.springframework.beans.Employee;
2527
import org.springframework.beans.Pet;
2628
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;
2733
import org.springframework.test.annotation.NotTransactional;
2834
import org.springframework.test.context.ContextConfiguration;
2935
import org.springframework.test.context.support.AnnotationConfigContextLoader;
3036
import org.springframework.test.context.transaction.AfterTransaction;
3137
import org.springframework.test.context.transaction.BeforeTransaction;
38+
import org.springframework.transaction.PlatformTransactionManager;
3239
import org.testng.annotations.AfterClass;
3340
import org.testng.annotations.AfterMethod;
3441
import org.testng.annotations.BeforeClass;
@@ -151,4 +158,37 @@ public void afterTransaction() {
151158
assertNumRowsInPersonTable(1, "after a transactional test method");
152159
}
153160

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+
154194
}

org.springframework.test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTestsConfig.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)