Fixed BadSqlGrammarException usage in transaction test suite
Issue: SPR-10902
(cherry picked from commit ef66708
)
This commit is contained in:
parent
5e88fe5842
commit
beaf6992b2
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.test.context.junit4;
|
package org.springframework.test.context.junit4;
|
||||||
|
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -51,7 +51,7 @@ public abstract class AbstractTransactionalSpringRunnerTests {
|
||||||
try {
|
try {
|
||||||
simpleJdbcTemplate.update("CREATE TABLE person (name VARCHAR(20) NOT NULL, PRIMARY KEY(name))");
|
simpleJdbcTemplate.update("CREATE TABLE person (name VARCHAR(20) NOT NULL, PRIMARY KEY(name))");
|
||||||
}
|
}
|
||||||
catch (BadSqlGrammarException bsge) {
|
catch (DataAccessException dae) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.springframework.tests.sample.beans.Pet;
|
||||||
import org.springframework.beans.factory.BeanNameAware;
|
import org.springframework.beans.factory.BeanNameAware;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.transaction.AfterTransaction;
|
import org.springframework.test.context.transaction.AfterTransaction;
|
||||||
|
@ -87,7 +87,7 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||||
try {
|
try {
|
||||||
jdbcTemplate.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) {
|
catch (DataAccessException dae) {
|
||||||
/* ignore */
|
/* ignore */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||||
public final void verifyApplicationContext() {
|
public final void verifyApplicationContext() {
|
||||||
assertInTransaction(false);
|
assertInTransaction(false);
|
||||||
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.",
|
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.",
|
||||||
super.applicationContext);
|
super.applicationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -143,7 +143,7 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||||
public final void verifyBeanInitialized() {
|
public final void verifyBeanInitialized() {
|
||||||
assertInTransaction(false);
|
assertInTransaction(false);
|
||||||
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
|
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
|
||||||
this.beanInitialized);
|
this.beanInitialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -188,14 +188,14 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||||
@BeforeTransaction
|
@BeforeTransaction
|
||||||
public void beforeTransaction() {
|
public void beforeTransaction() {
|
||||||
assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1,
|
assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1,
|
||||||
countRowsInPersonTable(super.jdbcTemplate));
|
countRowsInPersonTable(super.jdbcTemplate));
|
||||||
assertEquals("Adding yoda", 1, addPerson(super.jdbcTemplate, YODA));
|
assertEquals("Adding yoda", 1, addPerson(super.jdbcTemplate, YODA));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
assertEquals("Verifying the number of rows in the person table before a test method.",
|
assertEquals("Verifying the number of rows in the person table before a test method.",
|
||||||
(inTransaction() ? 2 : 1), countRowsInPersonTable(super.jdbcTemplate));
|
(inTransaction() ? 2 : 1), countRowsInPersonTable(super.jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -204,20 +204,20 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||||
assertEquals("Adding jane", 1, addPerson(super.jdbcTemplate, JANE));
|
assertEquals("Adding jane", 1, addPerson(super.jdbcTemplate, JANE));
|
||||||
assertEquals("Adding sue", 1, addPerson(super.jdbcTemplate, SUE));
|
assertEquals("Adding sue", 1, addPerson(super.jdbcTemplate, SUE));
|
||||||
assertEquals("Verifying the number of rows in the person table in modifyTestDataWithinTransaction().", 4,
|
assertEquals("Verifying the number of rows in the person table in modifyTestDataWithinTransaction().", 4,
|
||||||
countRowsInPersonTable(super.jdbcTemplate));
|
countRowsInPersonTable(super.jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
assertEquals("Verifying the number of rows in the person table after a test method.",
|
assertEquals("Verifying the number of rows in the person table after a test method.",
|
||||||
(inTransaction() ? 4 : 1), countRowsInPersonTable(super.jdbcTemplate));
|
(inTransaction() ? 4 : 1), countRowsInPersonTable(super.jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterTransaction
|
@AfterTransaction
|
||||||
public void afterTransaction() {
|
public void afterTransaction() {
|
||||||
assertEquals("Deleting yoda", 1, deletePerson(super.jdbcTemplate, 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,
|
assertEquals("Verifying the number of rows in the person table after a transactional test method.", 1,
|
||||||
countRowsInPersonTable(super.jdbcTemplate));
|
countRowsInPersonTable(super.jdbcTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue