/** * An expression to determine the output message from the released group. Defaults to a message * with a payload that is a collection of payloads from the input messages. * @param expression the expression. * @return the aggregator spec. */ public AggregatorSpec outputExpression(String expression) { return this.outputProcessor(new ExpressionEvaluatingMessageGroupProcessor(expression)); }
@Test public void testProcessAndSendWithFilterAndProjectionAndMethodInvokingExpressionEvaluated() { when(group.getMessages()).thenReturn(messages); processor = new ExpressionEvaluatingMessageGroupProcessor(String.format("T(%s).sum(?[payload>2].![payload])", getClass().getName())); processor.setBeanFactory(mock(BeanFactory.class)); Object result = processor.processMessageGroup(group); assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>); Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build(); assertEquals(3 + 4 + 5, resultMessage.getPayload()); }
@Test public void testProcessAndSendWithSizeExpressionEvaluated() { when(group.getMessages()).thenReturn(messages); processor = new ExpressionEvaluatingMessageGroupProcessor("#root.size()"); processor.setBeanFactory(mock(BeanFactory.class)); Object result = processor.processMessageGroup(group); assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>); Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build(); assertEquals(5, resultMessage.getPayload()); }
@Bean public MessageHandler gatherer1() { return new AggregatingMessageHandler( new ExpressionEvaluatingMessageGroupProcessor("^[payload gt 5] ?: -1D"), new SimpleMessageStore(), new HeaderAttributeCorrelationStrategy(IntegrationMessageHeaderAccessor.CORRELATION_ID), new ExpressionEvaluatingReleaseStrategy("size() == 2")); }
@Test public void testProcessAndSendWithFilterAndProjectionExpressionEvaluated() { when(group.getMessages()).thenReturn(messages); processor = new ExpressionEvaluatingMessageGroupProcessor("?[payload>2].![payload]"); processor.setBeanFactory(mock(BeanFactory.class)); Object result = processor.processMessageGroup(group); assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>); Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build(); assertTrue(resultMessage.getPayload() instanceof Collection<?>); Collection<?> list = (Collection<?>) resultMessage.getPayload(); assertEquals(3, list.size()); assertTrue(list.contains(3)); assertTrue(list.contains(4)); assertTrue(list.contains(5)); }
@Test public void testProcessAndCheckHeaders() { when(group.getMessages()).thenReturn(messages); processor = new ExpressionEvaluatingMessageGroupProcessor("#root"); processor.setBeanFactory(mock(BeanFactory.class)); Object result = processor.processMessageGroup(group); processor.setBeanFactory(mock(BeanFactory.class)); assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>); Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build(); assertEquals("bar", resultMessage.getHeaders().get("foo")); }
@Test public void testProcessAndSendWithProjectionExpressionEvaluated() { when(group.getMessages()).thenReturn(messages); processor = new ExpressionEvaluatingMessageGroupProcessor("![payload]"); processor.setBeanFactory(mock(BeanFactory.class)); Object result = processor.processMessageGroup(group); assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>); Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build(); assertTrue(resultMessage.getPayload() instanceof Collection<?>); Collection<?> list = (Collection<?>) resultMessage.getPayload(); assertEquals(5, list.size()); assertTrue(list.contains(1)); assertTrue(list.contains(2)); assertTrue(list.contains(3)); assertTrue(list.contains(4)); assertTrue(list.contains(5)); }
/** * An expression to determine the output message from the released group. Defaults to a message * with a payload that is a collection of payloads from the input messages. * @param expression the expression. * @return the aggregator spec. */ public AggregatorSpec outputExpression(String expression) { return this.outputProcessor(new ExpressionEvaluatingMessageGroupProcessor(expression)); }
/** * An expression to determine the output message from the released group. Defaults to a message * with a payload that is a collection of payloads from the input messages. * @param expression the expression. * @return the aggregator spec. */ public AggregatorSpec outputExpression(String expression) { return this.outputProcessor(new ExpressionEvaluatingMessageGroupProcessor(expression)); }
/** * An expression to determine the output message from the released group. Defaults to a message * with a payload that is a collection of payloads from the input messages. * @param expression the expression. * @return the aggregator spec. */ public AggregatorSpec outputExpression(String expression) { return this.outputProcessor(new ExpressionEvaluatingMessageGroupProcessor(expression)); }
@Bean @ConditionalOnProperty(prefix = AggregatorProperties.PREFIX, name = "aggregation") @ConditionalOnMissingBean public MessageGroupProcessor messageGroupProcessor() { return new ExpressionEvaluatingMessageGroupProcessor(this.properties.getAggregation().getExpressionString()); }