Search in sources :

Example 26 with SourcePollingChannelAdapter

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

the class JpaPollingChannelAdapterTests method testWithJpaQueryButNoResultsAndDelete.

@Test
@DirtiesContext
public void testWithJpaQueryButNoResultsAndDelete() throws Exception {
    testTrigger.reset();
    // ~~~~SETUP~~~~~
    final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
    jpaExecutor.setJpaQuery("from Student s where s.lastName = 'Something Else'");
    jpaExecutor.setDeleteAfterPoll(true);
    jpaExecutor.afterPropertiesSet();
    final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
    final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
    adapter.start();
    Thread.sleep(1000);
    final Consumer consumer = new Consumer();
    final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
    received.add(consumer.poll(10000));
    final Message<Collection<?>> message = received.get(0);
    adapter.stop();
    assertNull(message);
}
Also used : Consumer(org.springframework.integration.jpa.test.Consumer) Message(org.springframework.messaging.Message) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) ArrayList(java.util.ArrayList) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Collection(java.util.Collection) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 27 with SourcePollingChannelAdapter

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

the class ConsoleInboundChannelAdapterParserTests method adapterWithProvidedCharset.

@Test
public void adapterWithProvidedCharset() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("consoleInboundChannelAdapterParserTests.xml", ConsoleInboundChannelAdapterParserTests.class);
    SourcePollingChannelAdapter adapter = context.getBean("adapterWithProvidedCharset.adapter", SourcePollingChannelAdapter.class);
    MessageSource<?> source = adapter.getMessageSource();
    DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(source);
    Reader bufferedReader = (Reader) sourceAccessor.getPropertyValue("reader");
    assertEquals(BufferedReader.class, bufferedReader.getClass());
    assertEquals(false, sourceAccessor.getPropertyValue("blockToDetectEOF"));
    DirectFieldAccessor bufferedReaderAccessor = new DirectFieldAccessor(bufferedReader);
    Reader reader = (Reader) bufferedReaderAccessor.getPropertyValue("in");
    assertEquals(InputStreamReader.class, reader.getClass());
    Charset readerCharset = Charset.forName(((InputStreamReader) reader).getEncoding());
    assertEquals(Charset.forName("UTF-8"), readerCharset);
    Message<?> message = source.receive();
    assertNotNull(message);
    assertEquals("foo", message.getPayload());
    adapter = context.getBean("pipedAdapterWithCharset.adapter", SourcePollingChannelAdapter.class);
    source = adapter.getMessageSource();
    assertTrue(TestUtils.getPropertyValue(source, "blockToDetectEOF", Boolean.class));
    bufferedReader = (Reader) sourceAccessor.getPropertyValue("reader");
    assertEquals(BufferedReader.class, bufferedReader.getClass());
    bufferedReaderAccessor = new DirectFieldAccessor(bufferedReader);
    reader = (Reader) bufferedReaderAccessor.getPropertyValue("in");
    assertEquals(InputStreamReader.class, reader.getClass());
    readerCharset = Charset.forName(((InputStreamReader) reader).getEncoding());
    assertEquals(Charset.forName("UTF-8"), readerCharset);
    context.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Charset(java.nio.charset.Charset) Test(org.junit.Test)

Example 28 with SourcePollingChannelAdapter

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

the class MockIntegrationContext method resetBeans.

/**
 * Reinstate the mocked beans after execution test to their real state.
 * Typically is used from the {@link org.junit.After} method.
 * @param beanNames the bean names to reset.
 * If {@code null}, all the mocked beans are reset
 */
public void resetBeans(String... beanNames) {
    final Collection<String> names;
    if (!ObjectUtils.isEmpty(beanNames)) {
        names = Arrays.asList(beanNames);
    } else {
        names = null;
    }
    this.beans.entrySet().stream().filter(e -> names == null || names.contains(e.getKey())).forEach(e -> {
        Object endpoint = this.beanFactory.getBean(e.getKey());
        DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(endpoint);
        if (endpoint instanceof SourcePollingChannelAdapter) {
            directFieldAccessor.setPropertyValue("source", e.getValue());
        } else if (endpoint instanceof IntegrationConsumer) {
            directFieldAccessor.setPropertyValue("handler", e.getValue());
        }
    });
}
Also used : Arrays(java.util.Arrays) MockMessageHandler(org.springframework.integration.test.mock.MockMessageHandler) Collection(java.util.Collection) ObjectUtils(org.springframework.util.ObjectUtils) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) HashMap(java.util.HashMap) BeansException(org.springframework.beans.BeansException) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageProducer(org.springframework.integration.core.MessageProducer) TestUtils(org.springframework.integration.test.util.TestUtils) MessageChannel(org.springframework.messaging.MessageChannel) MessageSource(org.springframework.integration.core.MessageSource) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Lifecycle(org.springframework.context.Lifecycle) IntegrationConsumer(org.springframework.integration.endpoint.IntegrationConsumer) MessageHandler(org.springframework.messaging.MessageHandler) BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) Map(java.util.Map) BeanFactory(org.springframework.beans.factory.BeanFactory) Assert(org.springframework.util.Assert) IntegrationConsumer(org.springframework.integration.endpoint.IntegrationConsumer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter)

Example 29 with SourcePollingChannelAdapter

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

the class FeedInboundChannelAdapterParserTests method validateSuccessfulHttpConfigurationWithCustomMetadataStore.

@Test
public void validateSuccessfulHttpConfigurationWithCustomMetadataStore() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("FeedInboundChannelAdapterParserTests-http-context.xml", this.getClass());
    SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class);
    FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source");
    assertNotNull(TestUtils.getPropertyValue(source, "metadataStore"));
    context.close();
}
Also used : FeedEntryMessageSource(org.springframework.integration.feed.inbound.FeedEntryMessageSource) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 30 with SourcePollingChannelAdapter

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

the class FeedInboundChannelAdapterParserTests method validateSuccessfulNewsRetrievalWithFileUrlAndMessageHistory.

@Test
public void validateSuccessfulNewsRetrievalWithFileUrlAndMessageHistory() throws Exception {
    // Test file samples.rss has 3 news items
    latch = spy(new CountDownLatch(3));
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("FeedInboundChannelAdapterParserTests-file-usage-context.xml", this.getClass());
    latch.await(10, TimeUnit.SECONDS);
    verify(latch, times(3)).countDown();
    context.close();
    // since we are not deleting the persister file
    // in this iteration no new feeds will be received and the latch will timeout
    latch = spy(new CountDownLatch(3));
    context = new ClassPathXmlApplicationContext("FeedInboundChannelAdapterParserTests-file-usage-context.xml", this.getClass());
    latch.await(500, TimeUnit.MILLISECONDS);
    verify(latch, times(0)).countDown();
    SourcePollingChannelAdapter adapter = context.getBean("feedAdapterUsage", SourcePollingChannelAdapter.class);
    assertTrue(TestUtils.getPropertyValue(adapter, "source.syndFeedInput.preserveWireFeed", Boolean.class));
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) 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