use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class ContentEnricherTests method clonePayloadWithFailure.
@Test
public void clonePayloadWithFailure() {
QueueChannel replyChannel = new QueueChannel();
DirectChannel requestChannel = new DirectChannel();
requestChannel.subscribe(new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return new Source("John", "Doe");
}
});
ContentEnricher enricher = new ContentEnricher();
enricher.setRequestChannel(requestChannel);
enricher.setShouldClonePayload(true);
SpelExpressionParser parser = new SpelExpressionParser();
Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
propertyExpressions.put("name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
enricher.setPropertyExpressions(propertyExpressions);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
UncloneableTargetUser target = new UncloneableTargetUser();
target.setName("replace me");
Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
try {
enricher.handleMessage(requestMessage);
} catch (MessageHandlingException e) {
assertThat(e.getMessage(), containsString("Failed to clone payload object"));
return;
}
fail("Expected a MessageHandlingException to be thrown.");
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class ContentEnricherTests method simpleProperty.
@Test
public void simpleProperty() {
QueueChannel replyChannel = new QueueChannel();
DirectChannel requestChannel = new DirectChannel();
requestChannel.subscribe(new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return new Source("John", "Doe");
}
});
ContentEnricher enricher = new ContentEnricher();
enricher.setRequestChannel(requestChannel);
SpelExpressionParser parser = new SpelExpressionParser();
Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
propertyExpressions.put("name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
enricher.setPropertyExpressions(propertyExpressions);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
Target target = new Target("replace me");
Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
enricher.handleMessage(requestMessage);
Message<?> reply = replyChannel.receive(0);
assertEquals("Doe, John", ((Target) reply.getPayload()).getName());
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class ContentEnricherTests method clonePayload.
@Test
public void clonePayload() {
QueueChannel replyChannel = new QueueChannel();
DirectChannel requestChannel = new DirectChannel();
requestChannel.subscribe(new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return new Source("John", "Doe");
}
});
ContentEnricher enricher = new ContentEnricher();
enricher.setRequestChannel(requestChannel);
enricher.setShouldClonePayload(true);
SpelExpressionParser parser = new SpelExpressionParser();
Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
propertyExpressions.put("name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
enricher.setPropertyExpressions(propertyExpressions);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
Target target = new Target("replace me");
Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
enricher.handleMessage(requestMessage);
Message<?> reply = replyChannel.receive(0);
Target result = (Target) reply.getPayload();
assertEquals("Doe, John", result.getName());
assertNotSame(target, result);
}
use of org.springframework.integration.channel.DirectChannel 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.channel.DirectChannel in project spring-integration by spring-projects.
the class SplitterParserTests method splitterParserTestWithRequiresReply.
@Test(expected = ReplyRequiredException.class)
public void splitterParserTestWithRequiresReply() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("splitterParserTests.xml", this.getClass());
context.start();
DirectChannel inputChannel = context.getBean("requiresReplyInput", DirectChannel.class);
inputChannel.send(MessageBuilder.withPayload(Collections.emptyList()).build());
context.close();
}
Aggregations