Polish @Sql tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
@@ -34,8 +35,13 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
public class EmptyDatabaseConfig {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager transactionManager() {
|
||||
return new DataSourceTransactionManager(dataSource());
|
||||
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
|
||||
return new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.test.context.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -46,13 +44,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@DirtiesContext
|
||||
public class NonTransactionalSqlScriptsTests {
|
||||
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Test
|
||||
// test##_ prefix is required for @FixMethodOrder.
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.test.context.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -52,13 +50,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@DirtiesContext
|
||||
public class TransactionalInlinedStatementsSqlScriptsTests {
|
||||
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Test
|
||||
// test##_ prefix is required for @FixMethodOrder.
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.test.context.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -47,13 +45,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@DirtiesContext
|
||||
public class TransactionalSqlScriptsTests {
|
||||
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Test
|
||||
// test##_ prefix is required for @FixMethodOrder.
|
||||
@@ -62,7 +55,7 @@ public class TransactionalSqlScriptsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Sql({ "drop-schema.sql", "schema.sql", "data.sql", "data-add-dogbert.sql" })
|
||||
@Sql({ "recreate-schema.sql", "data.sql", "data-add-dogbert.sql" })
|
||||
// test##_ prefix is required for @FixMethodOrder.
|
||||
public void test02_methodLevelScripts() {
|
||||
assertNumUsers(2);
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.test.context.jdbc.SqlMergeMode;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD;
|
||||
|
||||
/**
|
||||
* Abstract base class for tests involving {@link SqlMergeMode @SqlMergeMode}.
|
||||
@@ -34,7 +33,7 @@ import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER
|
||||
* @since 5.2
|
||||
*/
|
||||
@ContextConfiguration(classes = EmptyDatabaseConfig.class)
|
||||
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
|
||||
@DirtiesContext
|
||||
abstract class AbstractSqlMergeModeTests extends AbstractTransactionalJUnit4SpringContextTests {
|
||||
|
||||
protected void assertUsers(String... expectedUsers) {
|
||||
|
||||
@@ -34,7 +34,7 @@ import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.OVERR
|
||||
* @author Dmitry Semukhin
|
||||
* @since 5.2
|
||||
*/
|
||||
@Sql({ "../schema.sql", "../data-add-catbert.sql" })
|
||||
@Sql({ "../recreate-schema.sql", "../data-add-catbert.sql" })
|
||||
@SqlMergeMode(MERGE)
|
||||
public class ClassLevelMergeSqlMergeModeTests extends AbstractSqlMergeModeTests {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ClassLevelMergeSqlMergeModeTests extends AbstractSqlMergeModeTests
|
||||
}
|
||||
|
||||
@Test
|
||||
@Sql({ "../schema.sql", "../data.sql", "../data-add-dogbert.sql", "../data-add-catbert.sql" })
|
||||
@Sql({ "../recreate-schema.sql", "../data.sql", "../data-add-dogbert.sql", "../data-add-catbert.sql" })
|
||||
@SqlMergeMode(OVERRIDE)
|
||||
public void overridden() {
|
||||
assertUsers("Dilbert", "Dogbert", "Catbert");
|
||||
|
||||
@@ -34,7 +34,7 @@ import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.OVERR
|
||||
* @author Dmitry Semukhin
|
||||
* @since 5.2
|
||||
*/
|
||||
@Sql({ "../schema.sql", "../data-add-catbert.sql" })
|
||||
@Sql({ "../recreate-schema.sql", "../data-add-catbert.sql" })
|
||||
@SqlMergeMode(OVERRIDE)
|
||||
public class ClassLevelOverrideSqlMergeModeTests extends AbstractSqlMergeModeTests {
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ClassLevelOverrideSqlMergeModeTests extends AbstractSqlMergeModeTes
|
||||
}
|
||||
|
||||
@Test
|
||||
@Sql({ "../schema.sql", "../data.sql", "../data-add-dogbert.sql", "../data-add-catbert.sql" })
|
||||
@Sql({ "../recreate-schema.sql", "../data.sql", "../data-add-dogbert.sql", "../data-add-catbert.sql" })
|
||||
public void overridden() {
|
||||
assertUsers("Dilbert", "Dogbert", "Catbert");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user