Polish contribution

See gh-1835
This commit is contained in:
Sam Brannen
2019-07-19 17:14:07 +02:00
parent d77b715d38
commit ab8876219f
7 changed files with 150 additions and 108 deletions

View File

@@ -25,7 +25,6 @@ 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;
@@ -59,10 +58,6 @@ 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);
}

View File

@@ -1,30 +0,0 @@
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"));
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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;
import static org.springframework.test.context.jdbc.Sql.MergeMode.MERGE;
/**
* Transactional integration tests for {@link Sql @Sql} that verify proper
* merging support for class-level and method-level declarations.
*
* @author Dmitry Semukhin
* @author Sam Brannen
* @since 5.2
*/
@ContextConfiguration(classes = EmptyDatabaseConfig.class)
@Sql({ "schema.sql", "data-add-catbert.sql" })
@DirtiesContext
public class SqlMethodMergeTests extends AbstractTransactionalJUnit4SpringContextTests {
@Test
@Sql(scripts = "data-add-dogbert.sql", mergeMode = MERGE)
public void testMerge() {
assertNumUsers(2);
}
protected void assertNumUsers(int expected) {
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
}
}

View File

@@ -1,30 +0,0 @@
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"));
}
}

View File

@@ -0,0 +1,54 @@
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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;
import static org.springframework.test.context.jdbc.Sql.MergeMode.OVERRIDE;
/**
* Transactional integration tests for {@link Sql @Sql} that verify proper
* overriding support for class-level and method-level declarations.
*
* @author Dmitry Semukhin
* @author Sam Brannen
* @since 5.2
*/
@ContextConfiguration(classes = EmptyDatabaseConfig.class)
@Sql({ "schema.sql", "data-add-catbert.sql" })
@DirtiesContext
public class SqlMethodOverrideTests extends AbstractTransactionalJUnit4SpringContextTests {
@Test
@Sql(
scripts = { "schema.sql", "data.sql", "data-add-dogbert.sql", "data-add-catbert.sql" },
mergeMode = OVERRIDE
)
public void methodLevelSqlScriptsOverrideClassLevelScripts() {
assertNumUsers(3);
}
protected void assertNumUsers(int expected) {
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user"));
}
}