Search in sources :

Example 6 with SimpleMessageGroup

use of org.springframework.integration.store.SimpleMessageGroup in project spring-integration by spring-projects.

the class MethodInvokingMessageGroupProcessorTests method testHeaderParameters.

@Test
public void testHeaderParameters() throws Exception {
    class SingleAnnotationTestBean {

        @Aggregator
        public String method1(List<String> input, @Header("foo") String foo) {
            return input.get(0) + foo;
        }
    }
    SingleAnnotationTestBean bean = new SingleAnnotationTestBean();
    MethodInvokingMessageGroupProcessor aggregator = new MethodInvokingMessageGroupProcessor(bean);
    SimpleMessageGroup group = new SimpleMessageGroup("FOO");
    group.add(MessageBuilder.withPayload("foo").setHeader("foo", "bar").build());
    group.add(MessageBuilder.withPayload("bar").setHeader("foo", "bar").build());
    assertEquals("foobar", aggregator.aggregatePayloads(group, aggregator.aggregateHeaders(group)));
}
Also used : Header(org.springframework.messaging.handler.annotation.Header) ArrayList(java.util.ArrayList) List(java.util.List) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 7 with SimpleMessageGroup

use of org.springframework.integration.store.SimpleMessageGroup in project spring-integration by spring-projects.

the class MethodInvokingMessageGroupProcessorTests method noAnnotations.

@Test
public void noAnnotations() throws Exception {
    @SuppressWarnings("unused")
    class NoAnnotationTestBean {

        public String method1(List<String> input) {
            return input.get(0);
        }

        String method2(List<String> input) {
            return input.get(1);
        }
    }
    NoAnnotationTestBean bean = new NoAnnotationTestBean();
    MethodInvokingMessageGroupProcessor aggregator = new MethodInvokingMessageGroupProcessor(bean);
    SimpleMessageGroup group = new SimpleMessageGroup("FOO");
    group.add(new GenericMessage<String>("foo"));
    group.add(new GenericMessage<String>("bar"));
    assertEquals("foo", aggregator.aggregatePayloads(group, null));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 8 with SimpleMessageGroup

use of org.springframework.integration.store.SimpleMessageGroup in project spring-integration by spring-projects.

the class MethodInvokingMessageGroupProcessorTests method singleAnnotation.

@Test
public void singleAnnotation() throws Exception {
    @SuppressWarnings("unused")
    class SingleAnnotationTestBean {

        @Aggregator
        public String method1(List<String> input) {
            return input.get(0);
        }

        public String method2(List<String> input) {
            return input.get(1);
        }
    }
    SingleAnnotationTestBean bean = new SingleAnnotationTestBean();
    MethodInvokingMessageGroupProcessor aggregator = new MethodInvokingMessageGroupProcessor(bean);
    SimpleMessageGroup group = new SimpleMessageGroup("FOO");
    group.add(new GenericMessage<String>("foo"));
    group.add(new GenericMessage<String>("bar"));
    assertEquals("foo", aggregator.aggregatePayloads(group, null));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 9 with SimpleMessageGroup

use of org.springframework.integration.store.SimpleMessageGroup in project spring-integration by spring-projects.

the class MethodInvokingMessageGroupProcessorTests method testHeadersParameters.

@Test
public void testHeadersParameters() throws Exception {
    class SingleAnnotationTestBean {

        @Aggregator
        public String method1(List<String> input, @Headers Map<String, ?> map) {
            return input.get(0) + map.get("foo");
        }
    }
    SingleAnnotationTestBean bean = new SingleAnnotationTestBean();
    MethodInvokingMessageGroupProcessor aggregator = new MethodInvokingMessageGroupProcessor(bean);
    SimpleMessageGroup group = new SimpleMessageGroup("FOO");
    group.add(MessageBuilder.withPayload("foo").setHeader("foo", "bar").build());
    group.add(MessageBuilder.withPayload("bar").setHeader("foo", "bar").build());
    assertEquals("foobar", aggregator.aggregatePayloads(group, aggregator.aggregateHeaders(group)));
}
Also used : Headers(org.springframework.messaging.handler.annotation.Headers) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 10 with SimpleMessageGroup

use of org.springframework.integration.store.SimpleMessageGroup in project spring-integration by spring-projects.

the class SequenceSizeReleaseStrategyTests method groupWithLastAndFirstMessagesOfIncompleteSequence.

private MessageGroup groupWithLastAndFirstMessagesOfIncompleteSequence() {
    SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
    Message<String> message1 = MessageBuilder.withPayload("test1").setSequenceSize(3).setSequenceNumber(3).build();
    Message<String> message2 = MessageBuilder.withPayload("test2").setSequenceSize(3).setSequenceNumber(1).build();
    messages.add(message1);
    messages.add(message2);
    return messages;
}
Also used : SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup)

Aggregations

SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)31 Test (org.junit.Test)21 MessageGroup (org.springframework.integration.store.MessageGroup)13 Message (org.springframework.messaging.Message)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 List (java.util.List)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 Method (java.lang.reflect.Method)2 Query (org.springframework.data.mongodb.core.query.Query)2 QueueChannel (org.springframework.integration.channel.QueueChannel)2 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)2 Date (java.util.Date)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)1 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)1 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)1 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)1 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)1