Merge class-level and method-level @Sql declarations
See gh-1835
This commit is contained in:
@@ -25,6 +25,7 @@ import org.junit.runners.MethodSorters;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -58,6 +59,10 @@ public class RepeatableSqlAnnotationSqlScriptsTests extends AbstractTransactiona
|
||||
assertNumUsers(2);
|
||||
}
|
||||
|
||||
protected int countRowsInTable(String tableName) {
|
||||
return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertThat(countRowsInTable("user")).as("Number of rows in the 'user' table.").isEqualTo(expected);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.springframework.test.context.jdbc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Test to verify method level merge of @Sql annotations.
|
||||
*
|
||||
* @author Dmitry Semukhin
|
||||
*/
|
||||
@ContextConfiguration(classes = EmptyDatabaseConfig.class)
|
||||
@Sql(value = {"schema.sql", "data-add-catbert.sql"})
|
||||
@DirtiesContext
|
||||
public class SqlMethodMergeTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||
|
||||
@Test
|
||||
@Sql(value = "data-add-dogbert.sql", mergeMode = Sql.MergeMode.MERGE)
|
||||
public void testMerge() {
|
||||
assertNumUsers(2);
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.springframework.test.context.jdbc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Test to verify method level override of @Sql annotations.
|
||||
*
|
||||
* @author Dmitry Semukhin
|
||||
*/
|
||||
@ContextConfiguration(classes = EmptyDatabaseConfig.class)
|
||||
@Sql(value = {"schema.sql", "data-add-catbert.sql"})
|
||||
@DirtiesContext
|
||||
public class SqlMethodOverrideTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||
|
||||
@Test
|
||||
@Sql(value = {"schema.sql", "data.sql", "data-add-dogbert.sql", "data-add-catbert.sql"}, mergeMode = Sql.MergeMode.OVERRIDE)
|
||||
public void testMerge() {
|
||||
assertNumUsers(3);
|
||||
}
|
||||
|
||||
protected void assertNumUsers(int expected) {
|
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user