Search in sources :

Example 1 with Recipient

use of org.springframework.integration.router.RecipientListRouter.Recipient 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 2 with Recipient

use of org.springframework.integration.router.RecipientListRouter.Recipient in project spring-integration by spring-projects.

the class RecipientListRouterTests method testDefaultChannelResolutionFromName.

@Test
public void testDefaultChannelResolutionFromName() {
    QueueChannel defaultChannel = new QueueChannel();
    List<Recipient> recipients = new ArrayList<Recipient>();
    recipients.add(new Recipient(new DirectChannel(), new AlwaysFalseSelector()));
    RecipientListRouter router = new RecipientListRouter();
    router.setRecipients(recipients);
    router.setDefaultOutputChannelName("defaultChannel");
    BeanFactory beanFactory = Mockito.mock(BeanFactory.class);
    when(beanFactory.getBean(Mockito.eq("defaultChannel"), Mockito.eq(MessageChannel.class))).thenReturn(defaultChannel);
    router.setBeanFactory(beanFactory);
    router.afterPropertiesSet();
    router.handleMessage(new GenericMessage<String>("foo"));
    assertSame(defaultChannel, TestUtils.getPropertyValue(router, "defaultOutputChannel"));
    Mockito.verify(beanFactory).getBean(Mockito.eq("defaultChannel"), Mockito.eq(MessageChannel.class));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) ArrayList(java.util.ArrayList) BeanFactory(org.springframework.beans.factory.BeanFactory) Recipient(org.springframework.integration.router.RecipientListRouter.Recipient) Test(org.junit.Test)

Example 3 with Recipient

use of org.springframework.integration.router.RecipientListRouter.Recipient in project spring-integration by spring-projects.

the class RecipientListRouterTests method recipientsWithSelectors.

@Test
public void recipientsWithSelectors() {
    QueueChannel channel1 = new QueueChannel();
    QueueChannel channel2 = new QueueChannel();
    QueueChannel channel3 = new QueueChannel();
    QueueChannel channel4 = new QueueChannel();
    QueueChannel channel5 = new QueueChannel();
    List<Recipient> recipients = new ArrayList<Recipient>();
    recipients.add(new Recipient(channel1, new AlwaysTrueSelector()));
    recipients.add(new Recipient(channel2, new AlwaysFalseSelector()));
    recipients.add(new Recipient(channel3));
    recipients.add(new Recipient(channel4));
    recipients.add(new Recipient(channel5, new AlwaysFalseSelector()));
    RecipientListRouter router = new RecipientListRouter();
    router.setRecipients(recipients);
    Message<?> message = new GenericMessage<String>("test");
    router.handleMessage(message);
    Message<?> reply1 = channel1.receive(0);
    assertEquals(message, reply1);
    Message<?> reply2 = channel2.receive(0);
    assertNull(reply2);
    Message<?> reply3 = channel3.receive(0);
    assertEquals(message, reply3);
    Message<?> reply4 = channel4.receive(0);
    assertEquals(message, reply4);
    Message<?> reply5 = channel5.receive(0);
    assertNull(reply5);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) ArrayList(java.util.ArrayList) Recipient(org.springframework.integration.router.RecipientListRouter.Recipient) Test(org.junit.Test)

Example 4 with Recipient

use of org.springframework.integration.router.RecipientListRouter.Recipient in project spring-integration by spring-projects.

the class RecipientListRouterTests method routeToDefaultChannelNoSelectorHits.

@Test
public void routeToDefaultChannelNoSelectorHits() {
    QueueChannel channel = new QueueChannel();
    channel.setBeanName("channel");
    QueueChannel defaultChannel = new QueueChannel();
    channel.setBeanName("default");
    List<Recipient> recipients = new ArrayList<Recipient>();
    recipients.add(new Recipient(channel, new AlwaysFalseSelector()));
    RecipientListRouter router = new RecipientListRouter();
    router.setRecipients(recipients);
    router.setDefaultOutputChannel(defaultChannel);
    Message<String> message = new GenericMessage<String>("test");
    router.handleMessage(message);
    Message<?> result1 = defaultChannel.receive(25);
    assertNotNull(result1);
    assertEquals("test", result1.getPayload());
    Message<?> result2 = channel.receive(5);
    assertNull(result2);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) ArrayList(java.util.ArrayList) Recipient(org.springframework.integration.router.RecipientListRouter.Recipient) Test(org.junit.Test)

Example 5 with Recipient

use of org.springframework.integration.router.RecipientListRouter.Recipient in project spring-integration by spring-projects.

the class RecipientListRouterTests method channelConfig.

@Test
@SuppressWarnings("unchecked")
public void channelConfig() {
    QueueChannel channel1 = new QueueChannel();
    QueueChannel channel2 = new QueueChannel();
    List<MessageChannel> channels = new ArrayList<MessageChannel>();
    channels.add(channel1);
    channels.add(channel2);
    RecipientListRouter router = new RecipientListRouter();
    router.setChannels(channels);
    router.setBeanFactory(mock(BeanFactory.class));
    router.afterPropertiesSet();
    ConcurrentLinkedQueue<Recipient> recipients = (ConcurrentLinkedQueue<Recipient>) new DirectFieldAccessor(router).getPropertyValue("recipients");
    assertEquals(2, recipients.size());
    assertEquals(channel1, new DirectFieldAccessor(recipients.poll()).getPropertyValue("channel"));
    assertEquals(channel2, new DirectFieldAccessor(recipients.poll()).getPropertyValue("channel"));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ArrayList(java.util.ArrayList) BeanFactory(org.springframework.beans.factory.BeanFactory) Recipient(org.springframework.integration.router.RecipientListRouter.Recipient) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Recipient (org.springframework.integration.router.RecipientListRouter.Recipient)5 ArrayList (java.util.ArrayList)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 BeanFactory (org.springframework.beans.factory.BeanFactory)2 MessageChannel (org.springframework.messaging.MessageChannel)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 Collection (java.util.Collection)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)1 PollableChannel (org.springframework.messaging.PollableChannel)1