Search in sources :

Example 61 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class ChannelAdapterParserTests method methodInvokingSourceStopped.

@Test
public void methodInvokingSourceStopped() {
    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);
    ((SourcePollingChannelAdapter) adapter).start();
    Message<?> message = channel.receive(10000);
    assertNotNull(message);
    assertEquals("source test", testBean.getMessage());
    ((SourcePollingChannelAdapter) adapter).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 62 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class ChannelAdapterParserTests method testMessageSourceUniqueIds.

@Test
public void testMessageSourceUniqueIds() {
    PollableChannel channel1 = this.applicationContext.getBean("channelAdapter1Channel", PollableChannel.class);
    PollableChannel channel2 = this.applicationContext.getBean("channelAdapter2Channel", PollableChannel.class);
    for (int i = 0; i < 10; i++) {
        Message<?> message = channel1.receive(5000);
        assertNotNull(message);
        assertEquals(i + 1, message.getPayload());
        message = channel2.receive(5000);
        assertNotNull(message);
        assertEquals(i + 1, message.getPayload());
    }
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 63 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class ChannelAdapterParserTests method methodInvokingSourceStoppedByApplicationContextInner.

@Test
public void methodInvokingSourceStoppedByApplicationContextInner() {
    String beanName = "methodInvokingSource";
    PollableChannel channel = (PollableChannel) this.applicationContextInner.getBean("queueChannel");
    // TestBean testBean = (TestBean) this.applicationContextInner.getBean("testBean");
    // testBean.store("source test");
    Object adapter = this.applicationContextInner.getBean(beanName);
    assertNotNull(adapter);
    assertTrue(adapter instanceof SourcePollingChannelAdapter);
    this.applicationContextInner.start();
    Message<?> message = channel.receive(10000);
    assertNotNull(message);
    // assertEquals("source test", testBean.getMessage());
    this.applicationContextInner.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 64 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class ChannelAdapterParserTests method methodInvokingSourceStartedByApplicationContext.

@Test
public void methodInvokingSourceStartedByApplicationContext() {
    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);
    this.applicationContext.start();
    Message<?> message = channel.receive(1000);
    assertNotNull(message);
    assertEquals("source test", testBean.getMessage());
    this.applicationContext.stop();
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 65 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class SplitterParserTests method splitterAdapterWithRefOnly.

@Test
public void splitterAdapterWithRefOnly() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("splitterParserTests.xml", this.getClass());
    context.start();
    MessageChannel input = (MessageChannel) context.getBean("splitterAdapterWithRefOnlyInput");
    PollableChannel output = (PollableChannel) context.getBean("output");
    input.send(new GenericMessage<String>("this.is.a.test"));
    Message<?> result1 = output.receive(1000);
    assertEquals("this", result1.getPayload());
    Message<?> result2 = output.receive(1000);
    assertEquals("is", result2.getPayload());
    Message<?> result3 = output.receive(1000);
    assertEquals("a", result3.getPayload());
    Message<?> result4 = output.receive(1000);
    assertEquals("test", result4.getPayload());
    assertNull(output.receive(0));
    context.close();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Aggregations

PollableChannel (org.springframework.messaging.PollableChannel)210 Test (org.junit.Test)190 MessageChannel (org.springframework.messaging.MessageChannel)89 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)82 QueueChannel (org.springframework.integration.channel.QueueChannel)52 GenericMessage (org.springframework.messaging.support.GenericMessage)52 Message (org.springframework.messaging.Message)40 BeanFactory (org.springframework.beans.factory.BeanFactory)25 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)20 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)19 MessagingException (org.springframework.messaging.MessagingException)16 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)13 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)12 ErrorMessage (org.springframework.messaging.support.ErrorMessage)12 Document (org.w3c.dom.Document)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Date (java.util.Date)10 ArrayList (java.util.ArrayList)9 MessageHistory (org.springframework.integration.history.MessageHistory)9