use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class AggregatorParserTests method testAggregation.
@Test
public void testAggregation() {
MessageChannel input = (MessageChannel) context.getBean("aggregatorWithReferenceInput");
TestAggregatorBean aggregatorBean = (TestAggregatorBean) context.getBean("aggregatorBean");
List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
outboundMessages.add(createMessage("123", "id1", 3, 1, null));
outboundMessages.add(createMessage("789", "id1", 3, 3, null));
outboundMessages.add(createMessage("456", "id1", 3, 2, null));
outboundMessages.forEach(input::send);
assertEquals("One and only one message must have been aggregated", 1, aggregatorBean.getAggregatedMessages().size());
Message<?> aggregatedMessage = aggregatorBean.getAggregatedMessages().get("id1");
assertEquals("The aggregated message payload is not correct", "123456789", aggregatedMessage.getPayload());
Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
Object handler = context.getBean("aggregatorWithReference.handler");
assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory"));
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class AggregatorParserTests method testAggregationByExpression.
@Test
public void testAggregationByExpression() {
MessageChannel input = (MessageChannel) context.getBean("aggregatorWithExpressionsInput");
SubscribableChannel outputChannel = (SubscribableChannel) context.getBean("aggregatorWithExpressionsOutput");
final AtomicReference<Message<?>> aggregatedMessage = new AtomicReference<Message<?>>();
outputChannel.subscribe(aggregatedMessage::set);
List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
outboundMessages.add(MessageBuilder.withPayload("123").setHeader("foo", "1").build());
outboundMessages.add(MessageBuilder.withPayload("456").setHeader("foo", "1").build());
outboundMessages.add(MessageBuilder.withPayload("789").setHeader("foo", "1").build());
outboundMessages.forEach(input::send);
assertEquals("The aggregated message payload is not correct", "[123]", aggregatedMessage.get().getPayload().toString());
Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
Object handler = context.getBean("aggregatorWithExpressions.handler");
assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory"));
assertTrue(TestUtils.getPropertyValue(handler, "expireGroupsUponTimeout", Boolean.class));
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class AggregatorParserTests method testAggregationWithMessageGroupProcessorAndStrategies.
@Test
public void testAggregationWithMessageGroupProcessorAndStrategies() {
QueueChannel output = this.context.getBean("outputChannel", QueueChannel.class);
output.purge(null);
MessageChannel input = (MessageChannel) context.getBean("aggregatorWithCustomMGPReferenceInput");
List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
outboundMessages.add(createMessage("123", "id1", 3, 1, null));
outboundMessages.add(createMessage("789", "id1", 3, 3, null));
outboundMessages.add(createMessage("456", "id1", 3, 2, null));
outboundMessages.forEach(input::send);
assertEquals(3, output.getQueueSize());
output.purge(null);
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class AggregatorParserTests method testSimpleJavaBeanAggregator.
@Test
public void testSimpleJavaBeanAggregator() {
List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
MessageChannel input = (MessageChannel) context.getBean("aggregatorWithReferenceAndMethodInput");
outboundMessages.add(createMessage(1L, "id1", 3, 1, null));
outboundMessages.add(createMessage(2L, "id1", 3, 3, null));
outboundMessages.add(createMessage(3L, "id1", 3, 2, null));
outboundMessages.forEach(input::send);
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
Message<?> response = outputChannel.receive(10);
Assert.assertEquals(6L, response.getPayload());
Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
Object handler = context.getBean("aggregatorWithReferenceAndMethod.handler");
assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory"));
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class CorrelatingMessageHandlerIntegrationTests method completesAfterThreshold.
@Test
public void completesAfterThreshold() throws Exception {
defaultHandler.setReleaseStrategy(new MessageCountReleaseStrategy());
MessageChannel discardChannel = mock(MessageChannel.class);
when(discardChannel.send(any(Message.class))).thenReturn(true);
defaultHandler.setDiscardChannel(discardChannel);
Message<?> message1 = correlatedMessage(1, 2, 1);
Message<?> message2 = correlatedMessage(1, 2, 2);
defaultHandler.handleMessage(message1);
verify(outputChannel).send(message1);
defaultHandler.handleMessage(message2);
verify(outputChannel, never()).send(message2);
verify(discardChannel).send(message2);
}
Aggregations