Search in sources :

Example 41 with SourcePollingChannelAdapter

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"));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 42 with SourcePollingChannelAdapter

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();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Resource(org.springframework.core.io.Resource) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) File(java.io.File) Test(org.junit.Test)

Example 43 with SourcePollingChannelAdapter

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());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) ErrorMessage(org.springframework.messaging.support.ErrorMessage) PollerMetadata(org.springframework.integration.scheduling.PollerMetadata) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Test(org.junit.Test)

Example 44 with SourcePollingChannelAdapter

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);
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 45 with SourcePollingChannelAdapter

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"));
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Aggregations

SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)66 Test (org.junit.Test)58 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 Message (org.springframework.messaging.Message)15 PollableChannel (org.springframework.messaging.PollableChannel)13 Collection (java.util.Collection)10 ArrayList (java.util.ArrayList)9 QueueChannel (org.springframework.integration.channel.QueueChannel)9 JpaExecutor (org.springframework.integration.jpa.core.JpaExecutor)9 Consumer (org.springframework.integration.jpa.test.Consumer)9 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)8 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)8 Trigger (org.springframework.scheduling.Trigger)7 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)6 Expression (org.springframework.expression.Expression)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)5 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)5 File (java.io.File)4