Skip to content

Commit

Permalink
Make tests compatible with Spring Framework 4.2
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
wilkinsona authored and rstoyanchev committed Jul 10, 2015
1 parent af05256 commit 99d975c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
Expand Up @@ -100,7 +100,7 @@ public void testFlowNotAPersistenceContext() {
}

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");
Expand All @@ -110,20 +110,20 @@ public void testFlowCommitsInSingleRequest() {

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);
flowSession.setState(endState);

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");
Expand All @@ -133,14 +133,14 @@ public void testFlowCommitsAfterMultipleRequests() {

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");
Expand All @@ -149,13 +149,13 @@ public void testFlowCommitsAfterMultipleRequests() {

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");
Expand All @@ -165,19 +165,19 @@ public void testCancelEndState() {

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");
Expand All @@ -190,13 +190,13 @@ public void testNoCommitAttributeSetOnEndState() {

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");
Expand All @@ -206,15 +206,15 @@ public void testExceptionThrown() {

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");
Expand Down
Expand Up @@ -53,10 +53,10 @@ protected void assertCommitState(boolean insertRow, boolean isCommited) {
}
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));
}
}

Expand Down
Expand Up @@ -52,7 +52,7 @@ public void testFlowNotAPersistenceContext() {
}

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");
Expand All @@ -63,20 +63,20 @@ public void testFlowCommitsInSingleRequest() {
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);
flowSession.setState(endState);

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");
Expand All @@ -87,15 +87,15 @@ public void testFlowCommitsAfterMultipleRequests() {
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();

jpaListener.resuming(context);
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");
Expand All @@ -104,13 +104,13 @@ public void testFlowCommitsAfterMultipleRequests() {

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");
Expand All @@ -121,19 +121,19 @@ public void testCancelEndState() {
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");
Expand All @@ -146,13 +146,13 @@ public void testNoCommitAttributeSetOnEndState() {

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");
Expand All @@ -163,15 +163,15 @@ public void testExceptionThrown() {
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");
Expand Down
Expand Up @@ -51,10 +51,10 @@ protected void assertCommitState(boolean insertRow, boolean isCommited) {
}
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));
}
}

Expand Down

0 comments on commit 99d975c

Please sign in to comment.