renamed modules org.springframework.integration.* -> spring-integration-*
@Ignore'd SimpleTcpNetOutboundGatewayTests#testOutboundClose() to avoid failure; this failure is correlated to the module name change, but hard to understand how it would be caused by it
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package org.springframework.integration.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class JdbcMessageHandlerIntegrationTests {
|
||||
|
||||
private EmbeddedDatabase embeddedDatabase;
|
||||
|
||||
private SimpleJdbcTemplate jdbcTemplate;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
|
||||
builder.setType(EmbeddedDatabaseType.HSQL).addScript(
|
||||
"classpath:org/springframework/integration/jdbc/messageHandlerIntegrationTest.sql");
|
||||
this.embeddedDatabase = builder.build();
|
||||
this.jdbcTemplate = new SimpleJdbcTemplate(this.embeddedDatabase);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
this.embeddedDatabase.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleStaticInsert() {
|
||||
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate.getJdbcOperations(), "insert into foos (id, status, name) values (1, 0, 'foo')");
|
||||
Message<String> message = new StringMessage("foo");
|
||||
handler.handleMessage(message);
|
||||
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", 1);
|
||||
assertEquals("Wrong id", "1", map.get("ID"));
|
||||
assertEquals("Wrong status", 0, map.get("STATUS"));
|
||||
assertEquals("Wrong name", "foo", map.get("NAME"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleDynamicInsert() {
|
||||
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate.getJdbcOperations(), "insert into foos (id, status, name) values (1, 0, :payload)");
|
||||
Message<String> message = new StringMessage("foo");
|
||||
handler.handleMessage(message);
|
||||
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", 1);
|
||||
assertEquals("Wrong name", "foo", map.get("NAME"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdHeaderDynamicInsert() {
|
||||
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate.getJdbcOperations(), "insert into foos (id, status, name) values (:headers[$id], 0, :payload)");
|
||||
Message<String> message = new StringMessage("foo");
|
||||
handler.handleMessage(message);
|
||||
String id = message.getHeaders().getId().toString();
|
||||
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", id);
|
||||
assertEquals("Wrong id", id, map.get("ID"));
|
||||
assertEquals("Wrong name", "foo", map.get("NAME"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDottedHeaderDynamicInsert() {
|
||||
JdbcMessageHandler handler = new JdbcMessageHandler(jdbcTemplate.getJdbcOperations(), "insert into foos (id, status, name) values (:headers[business.id], 0, :payload)");
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setHeader("business.id", "FOO").build();
|
||||
handler.handleMessage(message);
|
||||
String id = message.getHeaders().get("business.id").toString();
|
||||
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", id);
|
||||
assertEquals("Wrong id", id, map.get("ID"));
|
||||
assertEquals("Wrong name", "foo", map.get("NAME"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package org.springframework.integration.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.integration.test.matcher.PayloadAndHeaderMatcher.sameExceptIgnorableHeaders;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class JdbcMessageStoreTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
private JdbcMessageStore messageStore;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
messageStore = new JdbcMessageStore(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testGetNonExistent() throws Exception {
|
||||
Message<?> result = messageStore.getMessage(UUID.randomUUID());
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndGet() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("foo").build();
|
||||
Message<String> saved = messageStore.addMessage(message);
|
||||
assertNull(messageStore.getMessage(message.getHeaders().getId()));
|
||||
Message<?> result = messageStore.getMessage(saved.getHeaders().getId());
|
||||
assertNotNull(result);
|
||||
assertThat(saved, sameExceptIgnorableHeaders(result));
|
||||
assertNotNull(result.getHeaders().get(JdbcMessageStore.SAVED_KEY));
|
||||
assertNotNull(result.getHeaders().get(JdbcMessageStore.CREATED_DATE_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndGetWithDifferentRegion() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("foo").build();
|
||||
Message<String> saved = messageStore.addMessage(message);
|
||||
messageStore.setRegion("FOO");
|
||||
Message<?> result = messageStore.getMessage(saved.getHeaders().getId());
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndUpdate() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId("X").build();
|
||||
message = messageStore.addMessage(message);
|
||||
message = MessageBuilder.fromMessage(message).setCorrelationId("Y").build();
|
||||
message = messageStore.addMessage(message);
|
||||
assertEquals("Y", messageStore.getMessage(message.getHeaders().getId()).getHeaders().getCorrelationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndUpdateAlreadySaved() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("foo").build();
|
||||
message = messageStore.addMessage(message);
|
||||
Message<String> result = messageStore.addMessage(message);
|
||||
assertEquals(message, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndUpdateAlreadySavedAndCopied() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("foo").build();
|
||||
Message<String> saved = messageStore.addMessage(message);
|
||||
Message<String> copy = MessageBuilder.fromMessage(saved).build();
|
||||
Message<String> result = messageStore.addMessage(copy);
|
||||
assertNotSame(copy, result);
|
||||
assertThat(saved, sameExceptIgnorableHeaders(result, JdbcMessageStore.CREATED_DATE_KEY));
|
||||
assertNotNull(messageStore.getMessage(saved.getHeaders().getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndDelete() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("foo").build();
|
||||
message = messageStore.addMessage(message);
|
||||
assertNotNull(messageStore.removeMessage(message.getHeaders().getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndGetMessageGroup() throws Exception {
|
||||
String correlationId = "X";
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(correlationId).build();
|
||||
long now = System.currentTimeMillis();
|
||||
messageStore.addMessageToGroup(correlationId, message);
|
||||
MessageGroup group = messageStore.getMessageGroup(correlationId);
|
||||
assertEquals(1, group.size());
|
||||
assertTrue("Timestamp too early: " + group.getTimestamp() + "<" + now, group.getTimestamp() >= now);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testAddAndMarkMessageGroup() throws Exception {
|
||||
String correlationId = "X";
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(correlationId).build();
|
||||
messageStore.addMessageToGroup(correlationId, message);
|
||||
MessageGroup group = messageStore.getMessageGroup(correlationId);
|
||||
messageStore.markMessageGroup(group);
|
||||
assertEquals(1, group.getMarked().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void testExpireMessageGroup() throws Exception {
|
||||
String correlationId = "X";
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(correlationId).build();
|
||||
messageStore.addMessageToGroup(correlationId, message);
|
||||
messageStore.expireMessageGroups(-10000);
|
||||
MessageGroup group = messageStore.getMessageGroup(correlationId);
|
||||
assertEquals(0, group.getMarked().size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
package org.springframework.integration.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
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.embedded.EmbeddedDatabase;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class JdbcPollingChannelAdapterIntegrationTests {
|
||||
|
||||
private EmbeddedDatabase embeddedDatabase;
|
||||
|
||||
private SimpleJdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
|
||||
builder
|
||||
.setType(EmbeddedDatabaseType.DERBY)
|
||||
.addScript(
|
||||
"classpath:org/springframework/integration/jdbc/pollingChannelAdapterIntegrationTest.sql");
|
||||
this.embeddedDatabase = builder.build();
|
||||
this.jdbcTemplate = new SimpleJdbcTemplate(this.embeddedDatabase);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
this.embeddedDatabase.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimplePollForListOfMapsNoUpdate() {
|
||||
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(
|
||||
this.embeddedDatabase, "select * from item");
|
||||
this.jdbcTemplate.update("insert into item values(1,2)");
|
||||
Message<Object> message = adapter.receive();
|
||||
Object payload = message.getPayload();
|
||||
assertTrue("Wrong payload type", payload instanceof List<?>);
|
||||
List<?> rows = (List<?>) payload;
|
||||
assertEquals("Wrong number of elements", 1, rows.size());
|
||||
assertTrue("Returned row not a map", rows.get(0) instanceof Map<?,?>);
|
||||
Map<?, ?> row = (Map<?, ?>) rows.get(0);
|
||||
assertEquals("Wrong id", 1, row.get("id"));
|
||||
assertEquals("Wrong status", 2, row.get("status"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimplePollForListWithRowMapperNoUpdate() {
|
||||
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(
|
||||
this.embeddedDatabase, "select * from item");
|
||||
adapter.setRowMapper(new ItemRowMapper());
|
||||
this.jdbcTemplate.update("insert into item values(1,2)");
|
||||
Message<Object> 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);
|
||||
assertEquals("Wrong id", 1, item.getId());
|
||||
assertEquals("Wrong status", 2, item.getStatus());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimplePollForListWithRowMapperAndOneUpdate() {
|
||||
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(
|
||||
this.embeddedDatabase, "select * from item where status=2");
|
||||
adapter
|
||||
.setUpdateSql("update item set status = 10 where id in (:idList)");
|
||||
adapter.setRowMapper(new ItemRowMapper());
|
||||
|
||||
this.jdbcTemplate.update("insert into item values(1,2)");
|
||||
this.jdbcTemplate.update("insert into item values(2,2)");
|
||||
|
||||
Message<Object> message = adapter.receive();
|
||||
Object payload = message.getPayload();
|
||||
List<?> rows = (List<?>) payload;
|
||||
assertEquals("Wrong number of elements", 2, rows.size());
|
||||
assertTrue("Wrong payload type", rows.get(0) instanceof Item);
|
||||
Item item = (Item) rows.get(0);
|
||||
assertEquals("Wrong id", 1, 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", 0,
|
||||
countOfStatusTwo);
|
||||
|
||||
int countOfStatusTen = this.jdbcTemplate
|
||||
.queryForInt("select count(*) from item where status = 10");
|
||||
assertEquals(
|
||||
"Status not updated incorect number of rows with status 10", 2,
|
||||
countOfStatusTen);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
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.setUpdatePerRow(true);
|
||||
adapter.setRowMapper(new ItemRowMapper());
|
||||
|
||||
this.jdbcTemplate.update("insert into item values(1,2)");
|
||||
this.jdbcTemplate.update("insert into item values(2,2)");
|
||||
|
||||
Message<Object> message = adapter.receive();
|
||||
Object payload = message.getPayload();
|
||||
List<?> rows = (List<?>) payload;
|
||||
assertEquals("Wrong number of elements", 2, rows.size());
|
||||
assertTrue("Wrong payload type", rows.get(0) instanceof Item);
|
||||
Item item = (Item) rows.get(0);
|
||||
assertEquals("Wrong id", 1, 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", 0,
|
||||
countOfStatusTwo);
|
||||
|
||||
int countOfStatusTen = this.jdbcTemplate
|
||||
.queryForInt("select count(*) from item where status = 10");
|
||||
assertEquals(
|
||||
"Status not updated incorect number of rows with status 10", 2,
|
||||
countOfStatusTen);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyPoll() {
|
||||
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(
|
||||
this.embeddedDatabase, "select * from item");
|
||||
Message<Object> message = adapter.receive();
|
||||
assertNull("Message received when no rows in table", message);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static class Item {
|
||||
|
||||
private int id;
|
||||
|
||||
private int status;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ItemRowMapper implements RowMapper<Item> {
|
||||
|
||||
public Item mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
Item item = new Item();
|
||||
item.setId(rs.getInt(1));
|
||||
item.setStatus(rs.getInt(2));
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package org.springframework.integration.jdbc.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
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.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
|
||||
public class JdbcMessageHandlerParserTests {
|
||||
|
||||
private SimpleJdbcTemplate jdbcTemplate;
|
||||
|
||||
private MessageChannel channel;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testSimpleInboundChannelAdapter(){
|
||||
setUp("handlingWithJdbcOperationsJdbcOutboundChannelAdapterTest.xml", getClass());
|
||||
Message<?> message = MessageBuilder.withPayload("foo").setHeader("business.key", "FOO").build();
|
||||
channel.send(message);
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
|
||||
assertEquals("Wrong id", "FOO", map.get("ID"));
|
||||
assertEquals("Wrong id", "foo", map.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDollarHeaderInboundChannelAdapter(){
|
||||
setUp("handlingDollarHeaderJdbcOutboundChannelAdapterTest.xml", getClass());
|
||||
Message<?> message = MessageBuilder.withPayload("foo").build();
|
||||
channel.send(message);
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
|
||||
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
|
||||
assertEquals("Wrong id", "foo", map.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapPayloadInboundChannelAdapter(){
|
||||
setUp("handlingMapPayloadJdbcOutboundChannelAdapterTest.xml", getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
|
||||
channel.send(message);
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
|
||||
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
|
||||
assertEquals("Wrong id", "bar", map.get("name"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown(){
|
||||
if(context != null){
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUp(String name, Class<?> cls){
|
||||
context = new ClassPathXmlApplicationContext(name, cls);
|
||||
jdbcTemplate = new SimpleJdbcTemplate(this.context.getBean("dataSource",DataSource.class));
|
||||
channel = this.context.getBean("target", MessageChannel.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.springframework.integration.jdbc.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.jdbc.JdbcMessageStore;
|
||||
import org.springframework.integration.store.MessageStore;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
public class JdbcMessageStoreParserTests {
|
||||
|
||||
private ClassPathXmlApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testSimpleMessageStoreWithDataSource() {
|
||||
setUp("defaultJdbcMessageStore.xml", getClass());
|
||||
MessageStore store = context.getBean("messageStore", MessageStore.class);
|
||||
assertTrue(store instanceof JdbcMessageStore);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleMessageStoreWithTemplate() {
|
||||
setUp("jdbcOperationsJdbcMessageStore.xml", getClass());
|
||||
MessageStore store = context.getBean("messageStore", MessageStore.class);
|
||||
assertTrue(store instanceof JdbcMessageStore);
|
||||
}
|
||||
|
||||
@After
|
||||
@Test
|
||||
public void testMessageStoreWithAttributes() {
|
||||
setUp("soupedUpJdbcMessageStore.xml", getClass());
|
||||
MessageStore store = context.getBean("messageStore", MessageStore.class);
|
||||
assertEquals("FOO", ReflectionTestUtils.getField(store, "region"));
|
||||
assertEquals("BAR_", ReflectionTestUtils.getField(store, "tablePrefix"));
|
||||
assertEquals(context.getBean(LobHandler.class), ReflectionTestUtils.getField(store, "lobHandler"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUp(String name, Class<?> cls) {
|
||||
context = new ClassPathXmlApplicationContext(name, cls);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.springframework.integration.jdbc.config;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
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;
|
||||
|
||||
@Transactional
|
||||
public class JdbcPollingChannelAdapterParserTests {
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtendedInboundChannelAdapter(){
|
||||
setUp("pollingWithJdbcOperationsJdbcInboundChannelAdapterTest.xml", getClass());
|
||||
this.jdbcTemplate.update("insert into item values(1,2)");
|
||||
Message<?> message = channelTemplate.receive();
|
||||
assertNotNull(message);
|
||||
}
|
||||
|
||||
@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(500);
|
||||
}
|
||||
|
||||
protected void setupJdbcTemplate(){
|
||||
this.jdbcTemplate = new SimpleJdbcTemplate(this.appCtx.getBean("dataSource",DataSource.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
|
||||
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="HSQL"/>
|
||||
|
||||
<int-jdbc:message-store id="messageStore" data-source="dataSource"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.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">
|
||||
|
||||
<outbound-channel-adapter query="insert into foos (id, status, name) values (:headers[$id], 0, :payload)"
|
||||
channel="target" data-source="dataSource"/>
|
||||
|
||||
<beans:import resource="jdbcOutboundChannelAdapterCommonConfig.xml" />
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.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">
|
||||
|
||||
<outbound-channel-adapter query="insert into foos (id, status, name) values (:headers[$id], 0, :payload[foo])"
|
||||
channel="target" data-source="dataSource"/>
|
||||
|
||||
<beans:import resource="jdbcOutboundChannelAdapterCommonConfig.xml" />
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.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">
|
||||
|
||||
<outbound-channel-adapter query="insert into foos (id, status, name) values (:headers[business.key], 0, :payload)"
|
||||
channel="target" jdbc-operations="jdbcTemplate" />
|
||||
|
||||
<beans:import resource="jdbcOutboundChannelAdapterCommonConfig.xml" />
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1 @@
|
||||
create table item(id int,status int);
|
||||
@@ -0,0 +1,29 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.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>
|
||||
|
||||
<si:poller default="true">
|
||||
<si:interval-trigger interval="100" />
|
||||
</si:poller>
|
||||
|
||||
<jdbc:embedded-database type="HSQL" id="dataSource">
|
||||
<jdbc:script location="org/springframework/integration/jdbc/config/inboundSchema.sql" />
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<constructor-arg ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
|
||||
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="HSQL"/>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<constructor-arg ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<int-jdbc:message-store id="messageStore" jdbc-operations="jdbcTemplate"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.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"/>
|
||||
|
||||
<jdbc:embedded-database type="HSQL" id="dataSource">
|
||||
<jdbc:script location="org/springframework/integration/jdbc/config/outboundSchema.sql" />
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<constructor-arg ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1 @@
|
||||
create table foos(id varchar(100),status int,name varchar(20));
|
||||
@@ -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,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" update="update item set status=10 where id in (:idList)" />
|
||||
|
||||
<beans:import resource="jdbcInboundChannelAdapterCommonConfig.xml" />
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.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" jdbc-operations="jdbcTemplate" />
|
||||
|
||||
<beans:import resource="jdbcInboundChannelAdapterCommonConfig.xml" />
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
|
||||
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="HSQL"/>
|
||||
|
||||
<int-jdbc:message-store id="messageStore" data-source="dataSource" lob-handler="lobHandler" region="FOO" table-prefix="BAR_"/>
|
||||
|
||||
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2006-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.jdbc.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test for static utility to help with serialization.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SerializationUtilsTests {
|
||||
|
||||
private static BigInteger FOO = new BigInteger(
|
||||
"-9702942423549012526722364838327831379660941553432801565505143675386108883970811292563757558516603356009681061" +
|
||||
"5697574744209306031461371833798723505120163874786203211176873686513374052845353833564048");
|
||||
|
||||
@Test
|
||||
public void testSerializeCycleSunnyDay() throws Exception {
|
||||
assertEquals("foo", SerializationUtils.deserialize(SerializationUtils.serialize("foo")));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testDeserializeUndefined() throws Exception {
|
||||
byte[] bytes = FOO.toByteArray();
|
||||
Object foo = SerializationUtils.deserialize(bytes);
|
||||
assertNotNull(foo);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSerializeNonSerializable() throws Exception {
|
||||
SerializationUtils.serialize(new Object());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDeserializeNonSerializable() throws Exception {
|
||||
SerializationUtils.deserialize("foo".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeNull() throws Exception {
|
||||
assertNull(SerializationUtils.serialize(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserializeNull() throws Exception {
|
||||
assertNull(SerializationUtils.deserialize(null));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user