Tidy JDBC inbound poller tests some more
This commit is contained in:
@@ -38,26 +38,25 @@ import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
@Transactional
|
||||
// Not transactional because the poller threads need access to the data
|
||||
// @Transactional
|
||||
public class JdbcPollingChannelAdapterParserTests {
|
||||
|
||||
|
||||
|
||||
final long receiveTimeout = 5000;
|
||||
|
||||
|
||||
private SimpleJdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
private MessagingTemplate messagingTemplate;
|
||||
|
||||
|
||||
private ConfigurableApplicationContext appCtx;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleInboundChannelAdapter(){
|
||||
public void testSimpleInboundChannelAdapter() {
|
||||
setUp("pollingForMapJdbcInboundChannelAdapterTest.xml", getClass());
|
||||
this.jdbcTemplate.update("insert into item values(1,'',2)");
|
||||
Message<?> message = messagingTemplate.receive();
|
||||
@@ -66,10 +65,9 @@ public class JdbcPollingChannelAdapterParserTests {
|
||||
assertNotNull("No message found ", message);
|
||||
assertTrue("Wrong payload type expected instance of List", message.getPayload() instanceof List<?>);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleInboundChannelAdapterWithUpdate(){
|
||||
public void testSimpleInboundChannelAdapterWithUpdate() {
|
||||
setUp("pollingForMapJdbcInboundChannelAdapterWithUpdateTest.xml", getClass());
|
||||
this.jdbcTemplate.update("insert into item values(1,'',2)");
|
||||
Message<?> message = messagingTemplate.receive();
|
||||
@@ -77,9 +75,9 @@ public class JdbcPollingChannelAdapterParserTests {
|
||||
message = messagingTemplate.receive();
|
||||
assertNull(messagingTemplate.receive());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleInboundChannelAdapterWithNestedUpdate(){
|
||||
public void testSimpleInboundChannelAdapterWithNestedUpdate() {
|
||||
setUp("pollingForMapJdbcInboundChannelAdapterWithNestedUpdateTest.xml", getClass());
|
||||
this.jdbcTemplate.update("insert into item values(1,'',2)");
|
||||
Message<?> message = messagingTemplate.receive();
|
||||
@@ -87,17 +85,17 @@ public class JdbcPollingChannelAdapterParserTests {
|
||||
message = messagingTemplate.receive();
|
||||
assertNull(messagingTemplate.receive());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testExtendedInboundChannelAdapter(){
|
||||
public void testExtendedInboundChannelAdapter() {
|
||||
setUp("pollingWithJdbcOperationsJdbcInboundChannelAdapterTest.xml", getClass());
|
||||
this.jdbcTemplate.update("insert into item values(1,'',2)");
|
||||
Message<?> message = messagingTemplate.receive();
|
||||
assertNotNull(message);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParameterSourceFactoryInboundChannelAdapter(){
|
||||
public void testParameterSourceFactoryInboundChannelAdapter() {
|
||||
setUp("pollingWithParameterSourceJdbcInboundChannelAdapterTest.xml", getClass());
|
||||
this.jdbcTemplate.update("insert into item values(1,'',2)");
|
||||
Message<?> message = messagingTemplate.receive();
|
||||
@@ -106,17 +104,17 @@ public class JdbcPollingChannelAdapterParserTests {
|
||||
assertEquals(1, list.size());
|
||||
assertEquals("bar", list.get(0).get("NAME"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParameterSourceInboundChannelAdapter(){
|
||||
public void testParameterSourceInboundChannelAdapter() {
|
||||
setUp("pollingWithParametersForMapJdbcInboundChannelAdapterTest.xml", getClass());
|
||||
this.jdbcTemplate.update("insert into item values(1,'',2)");
|
||||
Message<?> message = messagingTemplate.receive();
|
||||
assertNotNull(message);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMaxRowsInboundChannelAdapter(){
|
||||
public void testMaxRowsInboundChannelAdapter() {
|
||||
setUp("pollingWithMaxRowsJdbcInboundChannelAdapterTest.xml", getClass());
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
|
||||
public Void doInTransaction(TransactionStatus status) {
|
||||
@@ -136,37 +134,36 @@ public class JdbcPollingChannelAdapterParserTests {
|
||||
count += payloadSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if(appCtx != null) {
|
||||
if (appCtx != null) {
|
||||
appCtx.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUp(String name, Class<?> cls){
|
||||
|
||||
public void setUp(String name, Class<?> cls) {
|
||||
appCtx = new ClassPathXmlApplicationContext(name, cls);
|
||||
setupJdbcTemplate();
|
||||
jdbcTemplate.update("delete from item");
|
||||
setupTransactionManager();
|
||||
setupMessagingTemplate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void setupMessagingTemplate() {
|
||||
PollableChannel pollableChannel = this.appCtx.getBean("target", PollableChannel.class);
|
||||
this.messagingTemplate = new MessagingTemplate(pollableChannel);
|
||||
this.messagingTemplate = new MessagingTemplate(pollableChannel);
|
||||
this.messagingTemplate.setReceiveTimeout(500);
|
||||
}
|
||||
|
||||
|
||||
protected void setupJdbcTemplate() {
|
||||
this.jdbcTemplate = new SimpleJdbcTemplate(this.appCtx.getBean("dataSource",DataSource.class));
|
||||
this.jdbcTemplate = new SimpleJdbcTemplate(this.appCtx.getBean("dataSource", DataSource.class));
|
||||
}
|
||||
|
||||
|
||||
protected void setupTransactionManager() {
|
||||
this.transactionManager = this.appCtx.getBean("transactionManager",PlatformTransactionManager.class);
|
||||
this.transactionManager = this.appCtx.getBean("transactionManager", PlatformTransactionManager.class);
|
||||
}
|
||||
|
||||
|
||||
public static class TestSqlParameterSource extends AbstractSqlParameterSource {
|
||||
|
||||
public Object getValue(String paramName) throws IllegalArgumentException {
|
||||
|
||||
Reference in New Issue
Block a user