namespace support for JDBC inbound channel adapter
resolves INT-876
This commit is contained in:
@@ -13,6 +13,7 @@ import org.junit.Test;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
@@ -26,6 +27,7 @@ public class JdbcPollingChannelAdapterIntegrationTest {
|
||||
|
||||
SimpleJdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
|
||||
@@ -59,8 +61,6 @@ public class JdbcPollingChannelAdapterIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimplePollForListWithRowMapperNoUpdate() {
|
||||
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(
|
||||
@@ -83,7 +83,7 @@ public class JdbcPollingChannelAdapterIntegrationTest {
|
||||
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(
|
||||
this.embeddedDatabase, "select * from item where status=2");
|
||||
adapter
|
||||
.setUpdatesql("update item set status = 10 where id in (:idList)");
|
||||
.setUpdateSql("update item set status = 10 where id in (:idList)");
|
||||
adapter.setRowMapper(new ItemRowMapper());
|
||||
|
||||
this.jdbcTemplate.update("insert into item values(1,2)");
|
||||
@@ -116,7 +116,7 @@ public class JdbcPollingChannelAdapterIntegrationTest {
|
||||
public void testSimplePollForListWithRowMapperAndUpdatePerRow() {
|
||||
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(
|
||||
this.embeddedDatabase, "select * from item where status=2");
|
||||
adapter.setUpdatesql("update item set status = 10 where id = :id");
|
||||
adapter.setUpdateSql("update item set status = 10 where id = :id");
|
||||
adapter.setUpdatePerRow(true);
|
||||
adapter.setRowMapper(new ItemRowMapper());
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.springframework.integration.jdbc.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.sun.xml.internal.xsom.impl.scd.Iterators.Map;
|
||||
|
||||
@Transactional
|
||||
public class JdbcPollingChannelAdapterParserTest {
|
||||
|
||||
|
||||
final long receiveTimeout = 5000;
|
||||
|
||||
SimpleJdbcTemplate jdbcTemplate;
|
||||
|
||||
MessageChannelTemplate channelTemplate;
|
||||
|
||||
ConfigurableApplicationContext appCtx;
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleInboundChannelAdapter(){
|
||||
setUp("pollingForMapJdbcInboundChannelAdapterTest.xml", getClass());
|
||||
this.jdbcTemplate.update("insert into item values(1,2)");
|
||||
Message<?> message = channelTemplate.receive();
|
||||
assertNotNull("No message found ", message);
|
||||
assertTrue("Wrong payload type expected instance of List", message.getPayload() instanceof List);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleInboundChannelAdapterWithUpdate(){
|
||||
setUp("pollingForMapJdbcInboundChannelAdapterWithUpdateTest.xml", getClass());
|
||||
this.jdbcTemplate.update("insert into item values(1,2)");
|
||||
Message<?> message = channelTemplate.receive();
|
||||
assertNotNull(message);
|
||||
message = channelTemplate.receive();
|
||||
assertNull(channelTemplate.receive());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown(){
|
||||
if(appCtx != null){
|
||||
appCtx.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUp(String name, Class<?> cls){
|
||||
appCtx = new ClassPathXmlApplicationContext(name, cls);
|
||||
setupJdbcTemplate();
|
||||
setupMessageChannelTemplate();
|
||||
}
|
||||
|
||||
|
||||
protected void setupMessageChannelTemplate(){
|
||||
PollableChannel pollableChannel = this.appCtx.getBean("target", PollableChannel.class);
|
||||
this.channelTemplate = new MessageChannelTemplate(pollableChannel);
|
||||
this.channelTemplate.setReceiveTimeout(5000);
|
||||
}
|
||||
|
||||
protected void setupJdbcTemplate(){
|
||||
this.jdbcTemplate = new SimpleJdbcTemplate(this.appCtx.getBean("dataSource",DataSource.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
create table item(id int,status int);
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<si:channel id="target">
|
||||
<si:queue />
|
||||
</si:channel>
|
||||
|
||||
<jdbc:embedded-database type="DERBY" id="dataSource">
|
||||
<jdbc:script location="org/springframework/integration/jdbc/config/inboundSchema.sql" />
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<beans:bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
|
||||
<beans:property name="dataSource" ref="dataSource"/>
|
||||
</beans:bean>
|
||||
|
||||
<si:poller default="true">
|
||||
<si:interval-trigger interval="1" />
|
||||
</si:poller>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/jdbc
|
||||
http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">
|
||||
|
||||
<inbound-channel-adapter query="select * from item where status=2" channel="target"
|
||||
data-source="dataSource" />
|
||||
|
||||
<beans:import resource="jdbcInboundChannelAdapterCommonConfig.xml" />
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/jdbc
|
||||
http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">
|
||||
|
||||
|
||||
|
||||
|
||||
<inbound-channel-adapter query="select * from item where status=2" channel="target"
|
||||
data-source="dataSource" update="update item set status =10 where id in (:idList)" />
|
||||
|
||||
<beans:import resource="jdbcInboundChannelAdapterCommonConfig.xml" />
|
||||
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user