From 99d975c0f17ab5265c50ab8baf056945704c1a69 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 9 Jul 2015 13:54:10 +0100 Subject: [PATCH] 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). --- .../HibernateFlowExecutionListenerTests.java | 32 +++++++++---------- ...atePersistenceContextPropagationTests.java | 4 +-- .../JpaFlowExecutionListenerTests.java | 32 +++++++++---------- ...JpaPersistenceContextPropagationTests.java | 4 +-- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernateFlowExecutionListenerTests.java b/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernateFlowExecutionListenerTests.java index 2d51dbdc..a483bc1c 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernateFlowExecutionListenerTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernateFlowExecutionListenerTests.java @@ -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"); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernatePersistenceContextPropagationTests.java b/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernatePersistenceContextPropagationTests.java index e7870b08..3b45ed13 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernatePersistenceContextPropagationTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernatePersistenceContextPropagationTests.java @@ -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)); } } diff --git a/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaFlowExecutionListenerTests.java b/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaFlowExecutionListenerTests.java index 1adf8c5c..4614b645 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaFlowExecutionListenerTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaFlowExecutionListenerTests.java @@ -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"); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaPersistenceContextPropagationTests.java b/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaPersistenceContextPropagationTests.java index 80864682..6f938df4 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaPersistenceContextPropagationTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaPersistenceContextPropagationTests.java @@ -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)); } }