mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-24 15:49:26 +00:00
Delete deprecated code in the TestContext framework
This commit deletes the deprecated SimpleJdbcTestUtils class as well as remaining usage of SimpleJdbcTemplate within the TestContext framework and its test suite. Issue: SPR-10499
This commit is contained in:
+25
-25
@@ -35,11 +35,11 @@ import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -80,29 +80,29 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
protected String bar;
|
||||
|
||||
|
||||
protected static int clearPersonTable(final SimpleJdbcTemplate simpleJdbcTemplate) {
|
||||
return SimpleJdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "person");
|
||||
protected static int clearPersonTable(final JdbcTemplate jdbcTemplate) {
|
||||
return JdbcTestUtils.deleteFromTables(jdbcTemplate, "person");
|
||||
}
|
||||
|
||||
protected static void createPersonTable(final SimpleJdbcTemplate simpleJdbcTemplate) {
|
||||
protected static void createPersonTable(final JdbcTemplate jdbcTemplate) {
|
||||
try {
|
||||
simpleJdbcTemplate.update("CREATE TABLE person (name VARCHAR(20) NOT NULL, PRIMARY KEY(name))");
|
||||
jdbcTemplate.update("CREATE TABLE person (name VARCHAR(20) NOT NULL, PRIMARY KEY(name))");
|
||||
}
|
||||
catch (final BadSqlGrammarException bsge) {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
protected static int countRowsInPersonTable(final SimpleJdbcTemplate simpleJdbcTemplate) {
|
||||
return SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "person");
|
||||
protected static int countRowsInPersonTable(final JdbcTemplate jdbcTemplate) {
|
||||
return JdbcTestUtils.countRowsInTable(jdbcTemplate, "person");
|
||||
}
|
||||
|
||||
protected static int addPerson(final SimpleJdbcTemplate simpleJdbcTemplate, final String name) {
|
||||
return simpleJdbcTemplate.update("INSERT INTO person VALUES(?)", name);
|
||||
protected static int addPerson(final JdbcTemplate jdbcTemplate, final String name) {
|
||||
return jdbcTemplate.update("INSERT INTO person VALUES(?)", name);
|
||||
}
|
||||
|
||||
protected static int deletePerson(final SimpleJdbcTemplate simpleJdbcTemplate, final String name) {
|
||||
return simpleJdbcTemplate.update("DELETE FROM person WHERE name=?", name);
|
||||
protected static int deletePerson(final JdbcTemplate jdbcTemplate, final String name) {
|
||||
return jdbcTemplate.update("DELETE FROM person WHERE name=?", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,36 +189,36 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
@BeforeTransaction
|
||||
public void beforeTransaction() {
|
||||
assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
assertEquals("Adding yoda", 1, addPerson(super.simpleJdbcTemplate, YODA));
|
||||
countRowsInPersonTable(super.jdbcTemplate));
|
||||
assertEquals("Adding yoda", 1, addPerson(super.jdbcTemplate, YODA));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
assertEquals("Verifying the number of rows in the person table before a test method.",
|
||||
(inTransaction() ? 2 : 1), countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
(inTransaction() ? 2 : 1), countRowsInPersonTable(super.jdbcTemplate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifyTestDataWithinTransaction() {
|
||||
assertInTransaction(true);
|
||||
assertEquals("Adding jane", 1, addPerson(super.simpleJdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(super.simpleJdbcTemplate, SUE));
|
||||
assertEquals("Adding jane", 1, addPerson(super.jdbcTemplate, JANE));
|
||||
assertEquals("Adding sue", 1, addPerson(super.jdbcTemplate, SUE));
|
||||
assertEquals("Verifying the number of rows in the person table in modifyTestDataWithinTransaction().", 4,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.jdbcTemplate));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
assertEquals("Verifying the number of rows in the person table after a test method.",
|
||||
(inTransaction() ? 4 : 1), countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
(inTransaction() ? 4 : 1), countRowsInPersonTable(super.jdbcTemplate));
|
||||
}
|
||||
|
||||
@AfterTransaction
|
||||
public void afterTransaction() {
|
||||
assertEquals("Deleting yoda", 1, deletePerson(super.simpleJdbcTemplate, YODA));
|
||||
assertEquals("Deleting yoda", 1, deletePerson(super.jdbcTemplate, YODA));
|
||||
assertEquals("Verifying the number of rows in the person table after a transactional test method.", 1,
|
||||
countRowsInPersonTable(super.simpleJdbcTemplate));
|
||||
countRowsInPersonTable(super.jdbcTemplate));
|
||||
}
|
||||
|
||||
|
||||
@@ -226,10 +226,10 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
|
||||
@Resource
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
SimpleJdbcTemplate simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
createPersonTable(simpleJdbcTemplate);
|
||||
clearPersonTable(simpleJdbcTemplate);
|
||||
addPerson(simpleJdbcTemplate, BOB);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
createPersonTable(jdbcTemplate);
|
||||
clearPersonTable(jdbcTemplate);
|
||||
addPerson(jdbcTemplate, BOB);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -79,11 +79,11 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
|
||||
|
||||
|
||||
private int createPerson(String name) {
|
||||
return simpleJdbcTemplate.update("INSERT INTO person VALUES(?)", name);
|
||||
return jdbcTemplate.update("INSERT INTO person VALUES(?)", name);
|
||||
}
|
||||
|
||||
private int deletePerson(String name) {
|
||||
return simpleJdbcTemplate.update("DELETE FROM person WHERE name=?", name);
|
||||
return jdbcTemplate.update("DELETE FROM person WHERE name=?", name);
|
||||
}
|
||||
|
||||
private void assertNumRowsInPersonTable(int expectedNumRows, String testState) {
|
||||
|
||||
+2
-2
@@ -84,11 +84,11 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
|
||||
|
||||
|
||||
private int createPerson(String name) {
|
||||
return simpleJdbcTemplate.update("INSERT INTO person VALUES(?)", name);
|
||||
return jdbcTemplate.update("INSERT INTO person VALUES(?)", name);
|
||||
}
|
||||
|
||||
private int deletePerson(String name) {
|
||||
return simpleJdbcTemplate.update("DELETE FROM person WHERE name=?", name);
|
||||
return jdbcTemplate.update("DELETE FROM person WHERE name=?", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -58,8 +58,8 @@ public class DirtiesContextTransactionalTestNGSpringContextTests extends Abstrac
|
||||
assertInTransaction(true);
|
||||
assertNotNull(super.applicationContext,
|
||||
"The application context should have been set due to ApplicationContextAware semantics.");
|
||||
assertNotNull(super.simpleJdbcTemplate,
|
||||
"The SimpleJdbcTemplate should have been created in setDataSource() via DI for the DataSource.");
|
||||
assertNotNull(super.jdbcTemplate,
|
||||
"The JdbcTemplate should have been created in setDataSource() via DI for the DataSource.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user