Search in sources :

Example 46 with PollableChannel

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

the class EnricherParserTests3 method testSourceBeanResolver.

@Test
public void testSourceBeanResolver() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-context.xml", this.getClass());
    MessageChannel beanResolveIn = context.getBean("beanResolveIn", MessageChannel.class);
    PollableChannel beanResolveOut = context.getBean("beanResolveOut", PollableChannel.class);
    SomeBean payload = new SomeBean("foo");
    assertEquals("foo", payload.getNested().getValue());
    beanResolveIn.send(new GenericMessage<SomeBean>(payload));
    @SuppressWarnings("unchecked") Message<SomeBean> out = (Message<SomeBean>) beanResolveOut.receive();
    assertSame(payload, out.getPayload());
    assertEquals("bar", out.getPayload().getNested().getValue());
    context.close();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 47 with PollableChannel

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

the class ControlBusRecipientListRouterTests method testAddRecipientWithNullExpression.

@Test
public void testAddRecipientWithNullExpression() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel3')");
    Message<?> message = new GenericMessage<Integer>(1);
    channel.send(message);
    PollableChannel chanel3 = (PollableChannel) context.getBean("channel3");
    assertTrue(chanel3.receive(0).getPayload().equals(1));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) GenericMessage(org.springframework.messaging.support.GenericMessage) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 48 with PollableChannel

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

the class ControlBusRecipientListRouterTests method testGetRecipients.

@Test
@SuppressWarnings("unchecked")
public void testGetRecipients() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel1')");
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.getRecipients()");
    PollableChannel channel1 = (PollableChannel) context.getBean("channel1");
    Message<?> result = this.output.receive(0);
    Collection<Recipient> mappings = (Collection<Recipient>) result.getPayload();
    assertEquals(channel1, mappings.iterator().next().getChannel());
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) PollableChannel(org.springframework.messaging.PollableChannel) Collection(java.util.Collection) Recipient(org.springframework.integration.router.RecipientListRouter.Recipient) Test(org.junit.Test)

Example 49 with PollableChannel

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

the class ControlBusRecipientListRouterTests method testRemoveRecipient.

@Test
public void testRemoveRecipient() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel1')");
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel4')");
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.removeRecipient('channel4')");
    Message<?> message = new GenericMessage<Integer>(1);
    channel.send(message);
    PollableChannel chanel1 = (PollableChannel) context.getBean("channel1");
    PollableChannel chanel4 = (PollableChannel) context.getBean("channel4");
    assertTrue(chanel1.receive(0).getPayload().equals(1));
    assertNull(chanel4.receive(0));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) GenericMessage(org.springframework.messaging.support.GenericMessage) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 50 with PollableChannel

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

the class ControlBusRecipientListRouterTests method testReplaceRecipients.

@Test
public void testReplaceRecipients() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.replaceRecipients('channel7=true')");
    Message<?> message = new GenericMessage<Integer>(1);
    channel.send(message);
    PollableChannel chanel7 = (PollableChannel) context.getBean("channel7");
    assertTrue(chanel7.receive(0).getPayload().equals(1));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) GenericMessage(org.springframework.messaging.support.GenericMessage) 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