use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ChainParserTests method chainNestingAndAggregation.
@SuppressWarnings("rawtypes")
@Test
public void chainNestingAndAggregation() throws Exception {
Message<?> message = MessageBuilder.withPayload("test").setCorrelationId(1).setSequenceSize(1).build();
this.aggregatorInput.send(message);
Message reply = this.output.receive(3000);
assertNotNull(reply);
assertEquals("foo", reply.getPayload());
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ChannelInterceptorTests method testPostReceiveInterceptor.
@Test
public void testPostReceiveInterceptor() {
final AtomicInteger invokedCount = new AtomicInteger();
final AtomicInteger messageCount = new AtomicInteger();
channel.addInterceptor(new ChannelInterceptorAdapter() {
@Override
public Message<?> postReceive(Message<?> message, MessageChannel channel) {
assertNotNull(channel);
assertSame(ChannelInterceptorTests.this.channel, channel);
if (message != null) {
messageCount.incrementAndGet();
}
invokedCount.incrementAndGet();
return message;
}
});
channel.receive(0);
assertEquals(1, invokedCount.get());
assertEquals(0, messageCount.get());
channel.send(new GenericMessage<String>("test"));
Message<?> result = channel.receive(0);
assertNotNull(result);
assertEquals(2, invokedCount.get());
assertEquals(1, messageCount.get());
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ChannelInterceptorTests method afterCompletionWithSendException.
@Test
public void afterCompletionWithSendException() {
final AbstractMessageChannel testChannel = new AbstractMessageChannel() {
@Override
protected boolean doSend(Message<?> message, long timeout) {
throw new RuntimeException("Simulated exception");
}
};
AfterCompletionTestInterceptor interceptor1 = new AfterCompletionTestInterceptor();
AfterCompletionTestInterceptor interceptor2 = new AfterCompletionTestInterceptor();
testChannel.addInterceptor(interceptor1);
testChannel.addInterceptor(interceptor2);
try {
testChannel.send(MessageBuilder.withPayload("test").build());
} catch (Exception ex) {
assertEquals("Simulated exception", ex.getCause().getMessage());
}
assertTrue(interceptor1.wasAfterCompletionInvoked());
assertTrue(interceptor2.wasAfterCompletionInvoked());
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ResequencingMessageGroupProcessorTests method shouldProcessSequence.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void shouldProcessSequence() {
Message prototypeMessage = MessageBuilder.withPayload("foo").setCorrelationId("x").setSequenceNumber(1).setSequenceSize(3).build();
List<Message<?>> messages = new ArrayList<Message<?>>();
Message message1 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(1).build();
Message message2 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(2).build();
Message message3 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(3).build();
messages.add(message1);
messages.add(message2);
messages.add(message3);
SimpleMessageGroup group = new SimpleMessageGroup(messages, "x");
List<Message> processedMessages = (List<Message>) processor.processMessageGroup(group);
assertThat(processedMessages, hasItems(message1, message2, message3));
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class DirectChannelSubscriptionTests method exceptionThrownFromRegisteredEndpoint.
@Test(expected = MessagingException.class)
public void exceptionThrownFromRegisteredEndpoint() {
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
public Object handleRequestMessage(Message<?> message) {
throw new RuntimeException("intentional test failure");
}
};
handler.setOutputChannel(targetChannel);
EventDrivenConsumer endpoint = new EventDrivenConsumer(sourceChannel, handler);
context.registerEndpoint("testEndpoint", endpoint);
context.refresh();
try {
this.sourceChannel.send(new GenericMessage<String>("foo"));
} finally {
context.stop();
}
}
Aggregations