use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class CollectionAndArrayTests method setWithRequestReplyHandler.
@Test
public void setWithRequestReplyHandler() {
MessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" }));
}
};
QueueChannel channel = new QueueChannel();
Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(channel).build();
handler.handleMessage(message);
Message<?> reply1 = channel.receive(0);
Message<?> reply2 = channel.receive(0);
assertNotNull(reply1);
assertNull(reply2);
assertThat(reply1.getPayload(), is(instanceOf(Set.class)));
assertEquals(2, ((Set<?>) reply1.getPayload()).size());
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class CollectionAndArrayTests method arrayWithRequestReplyHandler.
@Test
public void arrayWithRequestReplyHandler() {
MessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return new String[] { "foo", "bar" };
}
};
QueueChannel channel = new QueueChannel();
Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(channel).build();
handler.handleMessage(message);
Message<?> reply1 = channel.receive(0);
Message<?> reply2 = channel.receive(0);
assertNotNull(reply1);
assertNull(reply2);
assertTrue(reply1.getPayload().getClass().isArray());
assertEquals(2, ((String[]) reply1.getPayload()).length);
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class DelayHandlerTests method testRescheduleAndHandleAtTheSameTime.
// INT-3560
@Test
public /*
It's difficult to test it from real ctx, because any async process from 'inbound-channel-adapter'
can't achieve the DelayHandler before the main thread emits 'ContextRefreshedEvent'.
*/
void testRescheduleAndHandleAtTheSameTime() throws Exception {
QueueChannel results = new QueueChannel();
delayHandler.setOutputChannel(results);
this.delayHandler.setDefaultDelay(100);
startDelayerHandler();
this.input.send(new GenericMessage<>("foo"));
this.delayHandler.reschedulePersistedMessages();
Message<?> message = results.receive(10000);
assertNotNull(message);
message = results.receive(500);
assertNull(message);
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class HeaderAnnotationTransformerTests method headerAnnotationWithPrefixedHeader.
// INT-1082
@Test
public void headerAnnotationWithPrefixedHeader() {
Object target = new TestTransformer();
MethodInvokingTransformer transformer = new MethodInvokingTransformer(target, "appendCorrelationId");
MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
QueueChannel outputChannel = new QueueChannel();
handler.setOutputChannel(outputChannel);
handler.handleMessage(MessageBuilder.withPayload("test").setCorrelationId("abc").build());
Message<?> result = outputChannel.receive(0);
assertNotNull(result);
assertEquals("testabc", result.getPayload());
assertEquals("abc", new IntegrationMessageHeaderAccessor(result).getCorrelationId());
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class HeaderAnnotationTransformerTests method headerAnnotationWithUnprefixedHeader.
@Test
public void headerAnnotationWithUnprefixedHeader() {
Object target = new TestTransformer();
MethodInvokingTransformer transformer = new MethodInvokingTransformer(target, "appendFoo");
MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
QueueChannel outputChannel = new QueueChannel();
handler.setOutputChannel(outputChannel);
handler.handleMessage(MessageBuilder.withPayload("test").setHeader("foo", "bar").build());
Message<?> result = outputChannel.receive(0);
assertNotNull(result);
assertEquals("testbar", result.getPayload());
assertEquals("bar", result.getHeaders().get("foo"));
}
Aggregations