Search in sources :

Example 61 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class FtpMessageHistoryTests method testMessageHistory.

@Test
public void testMessageHistory() throws Exception {
    ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("ftp-message-history-context.xml", this.getClass());
    SourcePollingChannelAdapter adapter = ac.getBean("adapterFtp", SourcePollingChannelAdapter.class);
    assertEquals("adapterFtp", adapter.getComponentName());
    assertEquals("ftp:inbound-channel-adapter", adapter.getComponentType());
    ac.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 62 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class RedisStoreInboundChannelAdapterIntegrationTests method testListInboundConfiguration.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public void testListInboundConfiguration() throws Exception {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.prepareList(jcf);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("list-inbound-adapter.xml", this.getClass());
    SourcePollingChannelAdapter spca = context.getBean("listAdapter", SourcePollingChannelAdapter.class);
    spca.start();
    QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
    Message<Integer> message = (Message<Integer>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(Integer.valueOf(13), message.getPayload());
    // poll again, should get the same stuff
    message = (Message<Integer>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(Integer.valueOf(13), message.getPayload());
    this.deletePresidents(jcf);
    context.close();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 63 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class RedisStoreInboundChannelAdapterIntegrationTests method testListInboundConfigurationWithSynchronizationAndRollback.

@SuppressWarnings("resource")
@Test
@RedisAvailable
public // synchronization rollback renames the list
void testListInboundConfigurationWithSynchronizationAndRollback() throws Exception {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    StringRedisTemplate template = this.createStringRedisTemplate(jcf);
    template.delete("baz");
    this.prepareList(jcf);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("list-inbound-adapter.xml", this.getClass());
    SubscribableChannel fail = context.getBean("redisFailChannel", SubscribableChannel.class);
    final CountDownLatch latch = new CountDownLatch(1);
    fail.subscribe(message -> {
        latch.countDown();
        throw new RuntimeException("Test Rollback");
    });
    SourcePollingChannelAdapter spca = context.getBean("listAdapterWithSynchronizationAndRollback", SourcePollingChannelAdapter.class);
    spca.start();
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    int n = 0;
    while (n++ < 100 && template.keys("baz").size() == 0) {
        Thread.sleep(100);
    }
    assertTrue("Rename didn't occur", n < 100);
    assertEquals(Long.valueOf(13), template.boundListOps("baz").size());
    template.delete("baz");
    spca.stop();
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) SubscribableChannel(org.springframework.messaging.SubscribableChannel) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 64 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class InboundChannelAdapterParserTests method testAutoChannel.

@Test
public void testAutoChannel() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("InboundChannelAdapterParserTests-context.xml", this.getClass());
    // Auto-created channel
    MessageChannel autoChannel = context.getBean("autoChannel", MessageChannel.class);
    SourcePollingChannelAdapter autoChannelAdapter = context.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class);
    assertEquals("/foo", TestUtils.getPropertyValue(autoChannelAdapter, "source.synchronizer.remoteDirectoryExpression", Expression.class).getExpressionString());
    assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel"));
    assertEquals(Integer.MIN_VALUE, TestUtils.getPropertyValue(autoChannelAdapter, "source.maxFetchSize"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 65 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class InboundChannelAdapterParserTests method testWithLocalFiles.

@Test
public void testWithLocalFiles() throws Exception {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("InboundChannelAdapterParserTests-context.xml", this.getClass());
    assertTrue(new File("src/main/resources").exists());
    Object adapter = context.getBean("sftpAdapterAutoCreate");
    assertTrue(adapter instanceof SourcePollingChannelAdapter);
    SftpInboundFileSynchronizingMessageSource source = (SftpInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(adapter, "source");
    assertNotNull(source);
    PriorityBlockingQueue<?> blockingQueue = TestUtils.getPropertyValue(adapter, "source.fileSource.toBeReceived", PriorityBlockingQueue.class);
    Comparator<?> comparator = blockingQueue.comparator();
    assertNotNull(comparator);
    SftpInboundFileSynchronizer synchronizer = TestUtils.getPropertyValue(source, "synchronizer", SftpInboundFileSynchronizer.class);
    assertEquals("'/foo'", TestUtils.getPropertyValue(synchronizer, "remoteDirectoryExpression", Expression.class).getExpressionString());
    assertNotNull(TestUtils.getPropertyValue(synchronizer, "localFilenameGeneratorExpression"));
    assertTrue(TestUtils.getPropertyValue(synchronizer, "preserveTimestamp", Boolean.class));
    String remoteFileSeparator = (String) TestUtils.getPropertyValue(synchronizer, "remoteFileSeparator");
    assertEquals(".bar", TestUtils.getPropertyValue(synchronizer, "temporaryFileSuffix", String.class));
    assertNotNull(remoteFileSeparator);
    assertEquals(".", remoteFileSeparator);
    PollableChannel requestChannel = context.getBean("requestChannel", PollableChannel.class);
    assertNotNull(requestChannel.receive(10000));
    FileListFilter<?> acceptAllFilter = context.getBean("acceptAllFilter", FileListFilter.class);
    @SuppressWarnings("unchecked") Collection<FileListFilter<?>> filters = TestUtils.getPropertyValue(source, "fileSource.scanner.filter.fileFilters", Collection.class);
    assertThat(filters, hasItem(acceptAllFilter));
    assertEquals(42, source.getMaxFetchSize());
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) FileListFilter(org.springframework.integration.file.filters.FileListFilter) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) SftpInboundFileSynchronizingMessageSource(org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizingMessageSource) SftpInboundFileSynchronizer(org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizer) File(java.io.File) 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