use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class ResourceInboundChannelAdapterParserTests method testDefaultConfig.
@Test
public void testDefaultConfig() {
ApplicationContext context = new ClassPathXmlApplicationContext("ResourcePatternResolver-config.xml", this.getClass());
SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault", SourcePollingChannelAdapter.class);
ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source", ResourceRetrievingMessageSource.class);
assertNotNull(source);
boolean autoStartup = TestUtils.getPropertyValue(resourceAdapter, "autoStartup", Boolean.class);
assertFalse(autoStartup);
assertEquals("/**/*", TestUtils.getPropertyValue(source, "pattern"));
assertEquals(context, TestUtils.getPropertyValue(source, "patternResolver"));
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class ResourceInboundChannelAdapterParserTests method testUsageWithCustomResourceFilter.
@SuppressWarnings("unchecked")
@Test
public void testUsageWithCustomResourceFilter() throws Exception {
for (int i = 0; i < 10; i++) {
File f = new File(workDir, "testUsageWithRf" + i);
f.createNewFile();
}
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ResourcePatternResolver-config-usagerf.xml", this.getClass());
SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault", SourcePollingChannelAdapter.class);
ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source", ResourceRetrievingMessageSource.class);
assertNotNull(source);
TestCollectionFilter customFilter = context.getBean("customFilter", TestCollectionFilter.class);
assertEquals(customFilter, TestUtils.getPropertyValue(source, "filter"));
assertFalse(customFilter.invoked);
resourceAdapter.start();
QueueChannel resultChannel = context.getBean("resultChannel", QueueChannel.class);
Message<Resource[]> message = (Message<Resource[]>) resultChannel.receive(10000);
assertNotNull(message);
assertTrue(customFilter.invoked);
context.close();
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class ApplicationContextMessageBusTests method errorChannelWithFailedDispatch.
@Test
public void errorChannelWithFailedDispatch() throws InterruptedException {
TestApplicationContext context = TestUtils.createTestApplicationContext();
QueueChannel errorChannel = new QueueChannel();
QueueChannel outputChannel = new QueueChannel();
context.registerChannel("errorChannel", errorChannel);
CountDownLatch latch = new CountDownLatch(1);
SourcePollingChannelAdapter channelAdapter = new SourcePollingChannelAdapter();
channelAdapter.setSource(new FailingSource(latch));
PollerMetadata pollerMetadata = new PollerMetadata();
pollerMetadata.setTrigger(new PeriodicTrigger(1000));
channelAdapter.setOutputChannel(outputChannel);
context.registerEndpoint("testChannel", channelAdapter);
context.refresh();
latch.await(2000, TimeUnit.MILLISECONDS);
Message<?> message = errorChannel.receive(5000);
context.stop();
assertNull(outputChannel.receive(100));
assertNotNull("message should not be null", message);
assertTrue(message instanceof ErrorMessage);
Throwable exception = ((ErrorMessage) message).getPayload();
assertEquals("intentional test failure", exception.getCause().getMessage());
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class ChannelAdapterParserTests method methodInvokingSourceStoppedByApplicationContext.
@Test
public void methodInvokingSourceStoppedByApplicationContext() {
String beanName = "methodInvokingSource";
PollableChannel channel = (PollableChannel) this.applicationContext.getBean("queueChannel");
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
testBean.store("source test");
Object adapter = this.applicationContext.getBean(beanName);
assertNotNull(adapter);
assertTrue(adapter instanceof SourcePollingChannelAdapter);
assertEquals(-1, ((SourcePollingChannelAdapter) adapter).getPhase());
this.applicationContext.start();
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertEquals("source test", testBean.getMessage());
this.applicationContext.stop();
message = channel.receive(100);
assertNull(message);
}
use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.
the class ChannelAdapterParserTests method methodInvokingSourceWithHeaders.
@Test
public void methodInvokingSourceWithHeaders() {
String beanName = "methodInvokingSourceWithHeaders";
PollableChannel channel = (PollableChannel) this.applicationContext.getBean("queueChannelForHeadersTest");
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
testBean.store("source test");
Object adapter = this.applicationContext.getBean(beanName);
assertNotNull(adapter);
assertTrue(adapter instanceof SourcePollingChannelAdapter);
((SourcePollingChannelAdapter) adapter).start();
Message<?> message = channel.receive(10000);
((SourcePollingChannelAdapter) adapter).stop();
assertNotNull(message);
assertEquals("source test", testBean.getMessage());
assertEquals("source test", message.getPayload());
assertEquals("ABC", message.getHeaders().get("foo"));
assertEquals(123, message.getHeaders().get("bar"));
}
Aggregations