Search in sources :

Example 56 with PollableChannel

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

the class AggregatorParserTests method testSimpleJavaBeanAggregator.

@Test
public void testSimpleJavaBeanAggregator() {
    List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
    MessageChannel input = (MessageChannel) context.getBean("aggregatorWithReferenceAndMethodInput");
    outboundMessages.add(createMessage(1L, "id1", 3, 1, null));
    outboundMessages.add(createMessage(2L, "id1", 3, 3, null));
    outboundMessages.add(createMessage(3L, "id1", 3, 2, null));
    outboundMessages.forEach(input::send);
    PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
    Message<?> response = outputChannel.receive(10);
    Assert.assertEquals(6L, response.getPayload());
    Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
    Object handler = context.getBean("aggregatorWithReferenceAndMethod.handler");
    assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory"));
}
Also used : Message(org.springframework.messaging.Message) MessageChannel(org.springframework.messaging.MessageChannel) ArrayList(java.util.ArrayList) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 57 with PollableChannel

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

the class ChannelParserTests method testChannelInteceptorInnerBean.

@Test
public void testChannelInteceptorInnerBean() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("channelInterceptorParserTests.xml", getClass());
    PollableChannel channel = (PollableChannel) context.getBean("channelWithInterceptorInnerBean");
    channel.send(new GenericMessage<String>("test"));
    Message<?> transformed = channel.receive(1000);
    assertEquals("TEST", transformed.getPayload());
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 58 with PollableChannel

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

the class ChannelParserTests method testPriorityChannelWithIntegerDatatypeEnforced.

@Test
public void testPriorityChannelWithIntegerDatatypeEnforced() {
    PollableChannel channel = this.context.getBean("integerOnlyPriorityChannel", PollableChannel.class);
    channel.send(new GenericMessage<>(3));
    channel.send(new GenericMessage<>(2));
    channel.send(new GenericMessage<>(1));
    assertEquals(1, channel.receive(0).getPayload());
    assertEquals(2, channel.receive(0).getPayload());
    assertEquals(3, channel.receive(0).getPayload());
    boolean threwException = false;
    try {
        channel.send(new GenericMessage<>("wrong type"));
    } catch (MessageDeliveryException e) {
        assertEquals("wrong type", e.getFailedMessage().getPayload());
        threwException = true;
    }
    assertTrue(threwException);
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) Test(org.junit.Test)

Example 59 with PollableChannel

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

the class ChannelParserTests method testPriorityChannelWithDefaultComparator.

@Test
public void testPriorityChannelWithDefaultComparator() {
    PollableChannel channel = this.context.getBean("priorityChannelWithDefaultComparator", PollableChannel.class);
    Message<String> lowPriorityMessage = MessageBuilder.withPayload("low").setPriority(-14).build();
    Message<String> midPriorityMessage = MessageBuilder.withPayload("mid").setPriority(0).build();
    Message<String> highPriorityMessage = MessageBuilder.withPayload("high").setPriority(99).build();
    channel.send(lowPriorityMessage);
    channel.send(highPriorityMessage);
    channel.send(midPriorityMessage);
    Message<?> reply1 = channel.receive(0);
    Message<?> reply2 = channel.receive(0);
    Message<?> reply3 = channel.receive(0);
    assertEquals("high", reply1.getPayload());
    assertEquals("mid", reply2.getPayload());
    assertEquals("low", reply3.getPayload());
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 60 with PollableChannel

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

the class ChannelAdapterParserTests method methodInvokingSourceNotStarted.

@Test
public void methodInvokingSourceNotStarted() {
    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);
    Message<?> message = channel.receive(100);
    assertNull(message);
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) 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