mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-28 18:19:05 +00:00
Polishing
This commit is contained in:
+3
-3
@@ -32,12 +32,12 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
* @author Sam Brannen
|
||||
* @since 4.1
|
||||
*/
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class PopulatedSchemaDatabaseConfig {
|
||||
|
||||
@Bean
|
||||
PlatformTransactionManager transactionManager() {
|
||||
return new DataSourceTransactionManager(dataSource());
|
||||
PlatformTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
+6
-17
@@ -21,10 +21,9 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.NestedTestConfiguration;
|
||||
import org.springframework.test.context.NestedTestConfiguration.EnclosingConfiguration;
|
||||
import org.springframework.test.context.jdbc.AbstractTransactionalTests;
|
||||
import org.springframework.test.context.jdbc.PopulatedSchemaDatabaseConfig;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.jdbc.SqlMergeMode;
|
||||
@@ -34,10 +33,8 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE;
|
||||
import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.OVERRIDE;
|
||||
|
||||
@@ -50,27 +47,19 @@ import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.OVERR
|
||||
* @since 5.1.3
|
||||
*/
|
||||
@SpringJUnitConfig(PopulatedSchemaDatabaseConfig.class)
|
||||
@Transactional
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
class SqlScriptNestedTests {
|
||||
|
||||
@Autowired
|
||||
JdbcTemplate jdbcTemplate;
|
||||
class SqlScriptNestedTests extends AbstractTransactionalTests {
|
||||
|
||||
@BeforeTransaction
|
||||
@AfterTransaction
|
||||
void checkInitialDatabaseState() {
|
||||
assertThat(countRowsInTable("user")).isEqualTo(0);
|
||||
assertNumUsers(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Sql("/org/springframework/test/context/jdbc/data.sql")
|
||||
void sqlScripts() {
|
||||
assertThat(countRowsInTable("user")).isEqualTo(1);
|
||||
}
|
||||
|
||||
private int countRowsInTable(String tableName) {
|
||||
return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
|
||||
assertUsers("Dilbert");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@@ -79,13 +68,13 @@ class SqlScriptNestedTests {
|
||||
@BeforeTransaction
|
||||
@AfterTransaction
|
||||
void checkInitialDatabaseState() {
|
||||
assertThat(countRowsInTable("user")).isEqualTo(0);
|
||||
assertNumUsers(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Sql("/org/springframework/test/context/jdbc/data.sql")
|
||||
void nestedSqlScripts() {
|
||||
assertThat(countRowsInTable("user")).isEqualTo(1);
|
||||
assertUsers("Dilbert");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user