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());
}
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));
}
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);
}
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);
}
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"));
}
Aggregations