From 1de89be40a4b028b210c18f48e4d55095b5859d2 Mon Sep 17 00:00:00 2001 From: David Syer Date: Wed, 25 Aug 2010 20:37:31 +0000 Subject: [PATCH] Add extra integration test for jdbc poller --- ...PollingChannelAdapterIntegrationTests.java | 46 +++++++++++++++++++ .../pollingChannelAdapterIntegrationTest.sql | 3 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapterIntegrationTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapterIntegrationTests.java index c6dc3f5c06..675b929d41 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapterIntegrationTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapterIntegrationTests.java @@ -10,6 +10,8 @@ import java.sql.Types; import java.util.List; import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -25,6 +27,8 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; * @author Jonas Partner */ public class JdbcPollingChannelAdapterIntegrationTests { + + private static Log logger = LogFactory.getLog(JdbcPollingChannelAdapterIntegrationTests.class); private EmbeddedDatabase embeddedDatabase; @@ -184,6 +188,43 @@ public class JdbcPollingChannelAdapterIntegrationTests { } + @Test + public void testSimplePollForListWithRowMapperAndInsertPerRowAndMaxRows() { + JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter( + this.embeddedDatabase, "select * from item where id not in (select id from copy)"); + adapter.setUpdateSql("insert into copy values(:id,10)"); + adapter.setUpdatePerRow(true); + adapter.setMaxRowsPerPoll(1); + adapter.setRowMapper(new ItemRowMapper()); + + this.jdbcTemplate.update("insert into item values(1,2)"); + this.jdbcTemplate.update("insert into item values(2,2)"); + + logger.debug(adapter.receive()); + Message message = adapter.receive(); + Object payload = message.getPayload(); + List rows = (List) payload; + assertEquals("Wrong number of elements", 1, rows.size()); + assertTrue("Wrong payload type", rows.get(0) instanceof Item); + Item item = (Item) rows.get(0); + logger.debug(item); + assertEquals("Wrong id", 2, item.getId()); + assertEquals("Wrong status", 2, item.getStatus()); + + int countOfStatusTwo = this.jdbcTemplate + .queryForInt("select count(*) from item where status = 2"); + assertEquals( + "Status not updated incorect number of rows with status 2", 2, + countOfStatusTwo); + + int countOfStatusTen = this.jdbcTemplate + .queryForInt("select count(*) from copy where status = 10"); + assertEquals( + "Status not updated incorect number of rows with status 10", 2, + countOfStatusTen); + + } + @Test public void testEmptyPoll() { JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter( @@ -214,6 +255,11 @@ public class JdbcPollingChannelAdapterIntegrationTests { public void setStatus(int status) { this.status = status; } + + @Override + public String toString() { + return "Item [id=" + id + ", status=" + status + "]"; + } } private static class ItemRowMapper implements RowMapper { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/pollingChannelAdapterIntegrationTest.sql b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/pollingChannelAdapterIntegrationTest.sql index 1f0246d3b8..f6ef433fa7 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/pollingChannelAdapterIntegrationTest.sql +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/pollingChannelAdapterIntegrationTest.sql @@ -1 +1,2 @@ -create table item(id int,status int); \ No newline at end of file +create table item(id int,status int); +create table copy(id int,status int); \ No newline at end of file