Make tests compatible with Spring Framework 4.2
Spring Framework 4.2 removes the queryForInt method on JdbcTemplate in favour of queryForObject which is also available in earlier versions. This commit replaces calls to queryForInt with queryForObject, thereby allowing the tests to be run against Spring Framework 4.1 (the default) and Spring Framework 4.2 (for Spring IO Platform 2.0 compatibility testing).
This commit is contained in:
committed by
Rossen Stoyanchev
parent
af05256dd2
commit
99d975c0f1
@@ -100,7 +100,7 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testFlowCommitsInSingleRequest() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
@@ -110,7 +110,7 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
|
||||
TestBean bean = new TestBean("Keith Donald");
|
||||
hibernateTemplate.save(bean);
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
|
||||
EndState endState = new EndState(flowSession.getDefinitionInternal(), "success");
|
||||
endState.getAttributes().put("commit", true);
|
||||
@@ -118,12 +118,12 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
|
||||
hibernateListener.sessionEnding(context, flowSession, "success", null);
|
||||
hibernateListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have two rows", 2, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have two rows", 2, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
assertSessionNotBound();
|
||||
}
|
||||
|
||||
public void testFlowCommitsAfterMultipleRequests() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
@@ -133,14 +133,14 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
|
||||
TestBean bean1 = new TestBean("Keith Donald");
|
||||
hibernateTemplate.save(bean1);
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
hibernateListener.paused(context);
|
||||
assertSessionNotBound();
|
||||
|
||||
hibernateListener.resuming(context);
|
||||
TestBean bean2 = new TestBean("Keith Donald");
|
||||
hibernateTemplate.save(bean2);
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
assertSessionBound();
|
||||
|
||||
EndState endState = new EndState(flowSession.getDefinitionInternal(), "success");
|
||||
@@ -149,13 +149,13 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
|
||||
hibernateListener.sessionEnding(context, flowSession, "success", null);
|
||||
hibernateListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have three rows", 3, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have three rows", 3, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
|
||||
assertSessionNotBound();
|
||||
}
|
||||
|
||||
public void testCancelEndState() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
@@ -165,19 +165,19 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
|
||||
TestBean bean = new TestBean("Keith Donald");
|
||||
hibernateTemplate.save(bean);
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
|
||||
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
|
||||
endState.getAttributes().put("commit", false);
|
||||
flowSession.setState(endState);
|
||||
hibernateListener.sessionEnding(context, flowSession, "success", null);
|
||||
hibernateListener.sessionEnded(context, flowSession, "cancel", null);
|
||||
assertEquals("Table should only have two rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have two rows", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
assertSessionNotBound();
|
||||
}
|
||||
|
||||
public void testNoCommitAttributeSetOnEndState() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
@@ -190,13 +190,13 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
|
||||
hibernateListener.sessionEnding(context, flowSession, "success", null);
|
||||
hibernateListener.sessionEnded(context, flowSession, "cancel", null);
|
||||
assertEquals("Table should only have three rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have three rows", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
|
||||
assertSessionNotBound();
|
||||
}
|
||||
|
||||
public void testExceptionThrown() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
@@ -206,15 +206,15 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
|
||||
TestBean bean1 = new TestBean("Keith Donald");
|
||||
hibernateTemplate.save(bean1);
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
hibernateListener.exceptionThrown(context, new FlowExecutionException("bla", "bla", "bla"));
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
assertSessionNotBound();
|
||||
|
||||
}
|
||||
|
||||
public void testExceptionThrownWithNothingBound() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
|
||||
@@ -53,10 +53,10 @@ public class HibernatePersistenceContextPropagationTests extends AbstractPersist
|
||||
}
|
||||
if (!isCommited) {
|
||||
assertEquals("Nothing should be committed yet", 1,
|
||||
getJdbcTemplate().queryForInt("select count(*) from T_BEAN"));
|
||||
(int)getJdbcTemplate().queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
} else {
|
||||
assertEquals("All rows should be committed", rowCount,
|
||||
getJdbcTemplate().queryForInt("select count(*) from T_BEAN"));
|
||||
(int)getJdbcTemplate().queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testFlowCommitsInSingleRequest() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
@@ -63,7 +63,7 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
TestBean bean = new TestBean(1, "Keith Donald");
|
||||
EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
|
||||
em.persist(bean);
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
|
||||
EndState endState = new EndState(flowSession.getDefinitionInternal(), "success");
|
||||
endState.getAttributes().put("commit", true);
|
||||
@@ -71,12 +71,12 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
|
||||
jpaListener.sessionEnding(context, flowSession, "success", null);
|
||||
jpaListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have two rows", 2, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have two rows", 2, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
assertSessionNotBound();
|
||||
}
|
||||
|
||||
public void testFlowCommitsAfterMultipleRequests() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
@@ -87,7 +87,7 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
TestBean bean1 = new TestBean(1, "Keith Donald");
|
||||
EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
|
||||
em.persist(bean1);
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
jpaListener.paused(context);
|
||||
assertSessionNotBound();
|
||||
|
||||
@@ -95,7 +95,7 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
TestBean bean2 = new TestBean(2, "Keith Donald");
|
||||
em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
|
||||
em.persist(bean2);
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
assertSessionBound();
|
||||
|
||||
EndState endState = new EndState(flowSession.getDefinitionInternal(), "success");
|
||||
@@ -104,13 +104,13 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
|
||||
jpaListener.sessionEnding(context, flowSession, "success", null);
|
||||
jpaListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have three rows", 3, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have three rows", 3, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
|
||||
assertSessionNotBound();
|
||||
}
|
||||
|
||||
public void testCancelEndState() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
@@ -121,19 +121,19 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
TestBean bean = new TestBean(1, "Keith Donald");
|
||||
EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
|
||||
em.persist(bean);
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
|
||||
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
|
||||
endState.getAttributes().put("commit", false);
|
||||
flowSession.setState(endState);
|
||||
jpaListener.sessionEnding(context, flowSession, "cancel", null);
|
||||
jpaListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have two rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have two rows", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
assertSessionNotBound();
|
||||
}
|
||||
|
||||
public void testNoCommitAttributeSetOnEndState() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
@@ -146,13 +146,13 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
|
||||
jpaListener.sessionEnding(context, flowSession, "cancel", null);
|
||||
jpaListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have three rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have three rows", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
|
||||
assertSessionNotBound();
|
||||
}
|
||||
|
||||
public void testExceptionThrown() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
@@ -163,15 +163,15 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
TestBean bean = new TestBean(1, "Keith Donald");
|
||||
EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
|
||||
em.persist(bean);
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
jpaListener.exceptionThrown(context, new FlowExecutionException("bla", "bla", "bla"));
|
||||
assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should still only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
assertSessionNotBound();
|
||||
|
||||
}
|
||||
|
||||
public void testExceptionThrownWithNothingBound() {
|
||||
assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertEquals("Table should only have one row", 1, (int)jdbcTemplate.queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
MockRequestContext context = new MockRequestContext();
|
||||
MockFlowSession flowSession = new MockFlowSession();
|
||||
flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
|
||||
|
||||
@@ -51,10 +51,10 @@ public class JpaPersistenceContextPropagationTests extends AbstractPersistenceCo
|
||||
}
|
||||
if (!isCommited) {
|
||||
assertEquals("Nothing should be committed yet", 1,
|
||||
getJdbcTemplate().queryForInt("select count(*) from T_BEAN"));
|
||||
(int)getJdbcTemplate().queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
} else {
|
||||
assertEquals("All rows should be committed", rowCount,
|
||||
getJdbcTemplate().queryForInt("select count(*) from T_BEAN"));
|
||||
(int)getJdbcTemplate().queryForObject("select count(*) from T_BEAN", Integer.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user