[INT-140] Adds support for @CompletionStrategy annotation and supports a POJO completion strategy via namespace
This commit is contained in:
@@ -16,15 +16,15 @@
|
||||
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class Adder {
|
||||
|
||||
public Long add(Collection<Long> results) {
|
||||
long total = 0;
|
||||
public Long add(List<Long> results) {
|
||||
long total = 0l;
|
||||
for (long partialResult: results) {
|
||||
total += partialResult;
|
||||
}
|
||||
|
||||
@@ -90,6 +90,8 @@ public class AggregatorAnnotationTests {
|
||||
DirectFieldAccessor aggregatingMessageHandlerAccessor = new DirectFieldAccessor(aggregatingMessageHandler);
|
||||
return aggregatingMessageHandlerAccessor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private MessageBus getMessageBus(ApplicationContext context) {
|
||||
MessageBus messageBus = (MessageBus) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
|
||||
|
||||
@@ -16,25 +16,25 @@
|
||||
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.handler.HandlerMethodInvoker;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.router.AggregatingMessageHandler;
|
||||
import org.springframework.integration.router.Aggregator;
|
||||
import org.springframework.integration.router.CompletionStrategy;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.integration.router.CompletionStrategyAdapter;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
@@ -75,32 +75,28 @@ public class AggregatorParserTests {
|
||||
CompletionStrategy completionStrategy = (CompletionStrategy) context.getBean("completionStrategy");
|
||||
MessageChannel defaultReplyChannel = (MessageChannel) context.getBean("replyChannel");
|
||||
MessageChannel discardChannel = (MessageChannel) context.getBean("discardChannel");
|
||||
|
||||
DirectFieldAccessor messageHandlerFieldAccessor = new DirectFieldAccessor(completeAggregatingMessageHandler);
|
||||
Assert.assertEquals("The AggregatingMessageHandler is not injected with the appropriate Aggregator instance",
|
||||
testAggregator, getPropertyValue(completeAggregatingMessageHandler, "aggregator", Aggregator.class));
|
||||
testAggregator, messageHandlerFieldAccessor.getPropertyValue("aggregator"));
|
||||
Assert.assertEquals(
|
||||
"The AggregatingMessageHandler is not injected with the appropriate CompletionStrategy instance",
|
||||
completionStrategy, getPropertyValue(completeAggregatingMessageHandler, "completionStrategy",
|
||||
CompletionStrategy.class));
|
||||
completionStrategy, messageHandlerFieldAccessor.getPropertyValue("completionStrategy"));
|
||||
Assert.assertEquals("The AggregatingMessageHandler is not injected with the appropriate default reply channel",
|
||||
defaultReplyChannel, getPropertyValue(completeAggregatingMessageHandler, "defaultReplyChannel",
|
||||
MessageChannel.class));
|
||||
defaultReplyChannel, messageHandlerFieldAccessor.getPropertyValue("defaultReplyChannel"));
|
||||
Assert.assertEquals("The AggregatingMessageHandler is not injected with the appropriate discard channel",
|
||||
discardChannel, getPropertyValue(completeAggregatingMessageHandler, "discardChannel",
|
||||
MessageChannel.class));
|
||||
discardChannel, messageHandlerFieldAccessor.getPropertyValue("discardChannel"));
|
||||
Assert.assertEquals("The AggregatingMessageHandler is not set with the appropriate timeout value", 86420000l,
|
||||
getPropertyValue(completeAggregatingMessageHandler, "sendTimeout", long.class));
|
||||
messageHandlerFieldAccessor.getPropertyValue("sendTimeout"));
|
||||
Assert.assertEquals(
|
||||
"The AggregatingMessageHandler is not configured with the appropriate 'send partial results on timeout' flag",
|
||||
true, getPropertyValue(completeAggregatingMessageHandler, "sendPartialResultOnTimeout",
|
||||
boolean.class));
|
||||
true, messageHandlerFieldAccessor.getPropertyValue("sendPartialResultOnTimeout"));
|
||||
Assert.assertEquals("The AggregatingMessageHandler is not configured with the appropriate reaper interval",
|
||||
135l, getPropertyValue(completeAggregatingMessageHandler, "reaperInterval", long.class));
|
||||
135l, messageHandlerFieldAccessor.getPropertyValue("reaperInterval"));
|
||||
Assert.assertEquals(
|
||||
"The AggregatingMessageHandler is not configured with the appropriate tracked correlationId capacity",
|
||||
99, getPropertyValue(completeAggregatingMessageHandler, "trackedCorrelationIdCapacity", int.class));
|
||||
99, messageHandlerFieldAccessor.getPropertyValue("trackedCorrelationIdCapacity"));
|
||||
Assert.assertEquals("The AggregatingMessageHandler is not configured with the appropriate timeout",
|
||||
42l, getPropertyValue(completeAggregatingMessageHandler, "timeout", long.class));
|
||||
42l, messageHandlerFieldAccessor.getPropertyValue("timeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,7 +118,39 @@ public class AggregatorParserTests {
|
||||
public void testMissingMethodOnAggregator() {
|
||||
context = new ClassPathXmlApplicationContext("invalidMethodNameAggregator.xml", this.getClass());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=BeanDefinitionParsingException.class)
|
||||
public void testDuplicateCompletionStrategyDefinition() {
|
||||
context = new ClassPathXmlApplicationContext("completionStrategyMethodWithMissingReference.xml", this.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggregatorWithPojoCompletionStrategy(){
|
||||
AggregatingMessageHandler aggregatorWithPojoCompletionStrategy = (AggregatingMessageHandler) context.getBean("aggregatorWithPojoCompletionStrategy");
|
||||
CompletionStrategy completionStrategy = (CompletionStrategy)new DirectFieldAccessor(aggregatorWithPojoCompletionStrategy).getPropertyValue("completionStrategy");
|
||||
Assert.assertTrue(completionStrategy instanceof CompletionStrategyAdapter);
|
||||
DirectFieldAccessor completionStrategyAccessor = new DirectFieldAccessor(completionStrategy);
|
||||
HandlerMethodInvoker<?> invoker = (HandlerMethodInvoker<?>)completionStrategyAccessor.getPropertyValue("invoker");
|
||||
Assert.assertTrue(new DirectFieldAccessor(invoker).getPropertyValue("object") instanceof MaxValueCompletionStrategy);
|
||||
Assert.assertTrue(((Method)completionStrategyAccessor.getPropertyValue("method")).getName().equals("checkCompleteness"));
|
||||
|
||||
aggregatorWithPojoCompletionStrategy.handle(createMessage(1l, "id1", 0 , 0, null));
|
||||
aggregatorWithPojoCompletionStrategy.handle(createMessage(2l, "id1", 0 , 0, null));
|
||||
aggregatorWithPojoCompletionStrategy.handle(createMessage(3l, "id1", 0 , 0, null));
|
||||
MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
|
||||
Message<?> reply = replyChannel.receive(0);
|
||||
Assert.assertNull(reply);
|
||||
aggregatorWithPojoCompletionStrategy.handle(createMessage(5l, "id1", 0 , 0, null));
|
||||
reply = replyChannel.receive(0);
|
||||
Assert.assertNotNull(reply);
|
||||
Assert.assertEquals(11l, reply.getPayload());
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionParsingException.class)
|
||||
public void testAggregatorWithDuplicateCompletionStrategy() {
|
||||
context = new ClassPathXmlApplicationContext("duplicateCompletionStrategy.xml", this.getClass());
|
||||
}
|
||||
|
||||
private static <T> Message<T> createMessage(T payload, Object correlationId, int sequenceSize, int sequenceNumber,
|
||||
MessageChannel replyChannel) {
|
||||
GenericMessage<T> message = new GenericMessage<T>(payload);
|
||||
@@ -133,17 +161,4 @@ public class AggregatorParserTests {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reading private fields through reflection, since they don't have setters
|
||||
* @param beanUnderTest
|
||||
* @param fieldName
|
||||
* @return the value of the field
|
||||
* @throws Exception
|
||||
*/
|
||||
private static Object getPropertyValue(Object beanUnderTest, String fieldName, Class<?> type) throws Exception {
|
||||
Field field = ReflectionUtils.findField(beanUnderTest.getClass(), fieldName, type);
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
return field.get(beanUnderTest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.bus.MessageBus;
|
||||
import org.springframework.integration.endpoint.ConcurrentHandler;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.handler.MessageHandlerChain;
|
||||
import org.springframework.integration.router.AggregatingMessageHandler;
|
||||
import org.springframework.integration.router.CompletionStrategyAdapter;
|
||||
|
||||
public class CompletionStrategyAnnotationTests {
|
||||
|
||||
@Test
|
||||
public void testAnnotationWithDefaultSettings() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
new String[] { "classpath:/org/springframework/integration/config/testAnnotatedAggregator.xml" });
|
||||
final String endpointName = "endpointWithDefaultAnnotationAndCustomCompletionStrategy";
|
||||
DirectFieldAccessor aggregatingMessageHandlerAccessor = getDirectFieldAccessorForAggregatingHandler(context,
|
||||
endpointName);
|
||||
Assert.assertTrue(aggregatingMessageHandlerAccessor.getPropertyValue("completionStrategy") instanceof CompletionStrategyAdapter);
|
||||
DirectFieldAccessor invokerAccessor = new DirectFieldAccessor(new DirectFieldAccessor(
|
||||
aggregatingMessageHandlerAccessor.getPropertyValue("completionStrategy")).getPropertyValue("invoker"));
|
||||
Assert.assertSame(context.getBean(endpointName), invokerAccessor.getPropertyValue("object"));
|
||||
Assert.assertEquals("completionChecker", invokerAccessor.getPropertyValue("method"));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected=BeanCreationException.class)
|
||||
public void testInvalidAnnotation() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
new String[] { "classpath:/org/springframework/integration/config/testInvalidCompletionStrategyAnnotation.xml" });
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private DirectFieldAccessor getDirectFieldAccessorForAggregatingHandler(ApplicationContext context,
|
||||
final String endpointName) {
|
||||
MessageBus messageBus = getMessageBus(context);
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) messageBus
|
||||
.lookupEndpoint(endpointName + "-endpoint");
|
||||
MessageHandlerChain messageHandlerChain = (MessageHandlerChain) endpoint.getHandler();
|
||||
AggregatingMessageHandler aggregatingMessageHandler = (AggregatingMessageHandler) ((List) new DirectFieldAccessor(
|
||||
messageHandlerChain).getPropertyValue("handlers")).get(0);
|
||||
DirectFieldAccessor aggregatingMessageHandlerAccessor = new DirectFieldAccessor(aggregatingMessageHandler);
|
||||
return aggregatingMessageHandlerAccessor;
|
||||
}
|
||||
|
||||
private MessageBus getMessageBus(ApplicationContext context) {
|
||||
MessageBus messageBus = (MessageBus) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
|
||||
return messageBus;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -35,7 +34,7 @@ public class TestAggregator implements Aggregator {
|
||||
|
||||
private final ConcurrentMap<Object, Message<?>> aggregatedMessages = new ConcurrentHashMap<Object, Message<?>>();
|
||||
|
||||
public Message<?> aggregate(Collection<Message<?>> messages) {
|
||||
public Message<?> aggregate(List<Message<?>> messages) {
|
||||
List<Message<?>> sortableList = new ArrayList<Message<?>>(messages);
|
||||
Collections.sort(sortableList, new MessageSequenceComparator());
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.springframework.integration.annotation.Aggregator;
|
||||
import org.springframework.integration.annotation.CompletionStrategy;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.router.MessageSequenceComparator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
@MessageEndpoint(input="inputChannel")
|
||||
@Component("endpointWithDefaultAnnotationAndCustomCompletionStrategy")
|
||||
public class TestAnnotatedEndpointWithCompletionStrategy {
|
||||
|
||||
private final ConcurrentMap<Object, Message<?>> aggregatedMessages = new ConcurrentHashMap<Object, Message<?>>();
|
||||
|
||||
@Aggregator
|
||||
public Message<?> aggregatingMethod(List<Message<?>> messages) {
|
||||
List<Message<?>> sortableList = new ArrayList<Message<?>>(messages);
|
||||
Collections.sort(sortableList, new MessageSequenceComparator());
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Object correlationId = null;
|
||||
for (Message<?> message : sortableList) {
|
||||
buffer.append(message.getPayload().toString());
|
||||
if (null == correlationId) {
|
||||
correlationId = message.getHeader().getCorrelationId();
|
||||
}
|
||||
}
|
||||
Message<?> returnedMessage = new StringMessage(buffer.toString());
|
||||
aggregatedMessages.put(correlationId, returnedMessage);
|
||||
return returnedMessage;
|
||||
}
|
||||
|
||||
@CompletionStrategy
|
||||
public boolean completionChecker(List<Message<?>> messages) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Object, Message<?>> getAggregatedMessages() {
|
||||
return aggregatedMessages;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -42,7 +41,7 @@ public class TestAnnotatedEndpointWithCustomizedAggregator {
|
||||
@Aggregator(defaultReplyChannel = "replyChannel", discardChannel = "discardChannel",
|
||||
reaperInterval = 1234, sendPartialResultsOnTimeout = true,
|
||||
sendTimeout = 98765432, timeout = 4567890, trackedCorrelationIdCapacity = 42)
|
||||
public Message<?> aggregatingMethod(Collection<Message<?>> messages) {
|
||||
public Message<?> aggregatingMethod(List<Message<?>> messages) {
|
||||
List<Message<?>> sortableList = new ArrayList<Message<?>>(messages);
|
||||
Collections.sort(sortableList, new MessageSequenceComparator());
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -40,7 +39,7 @@ public class TestAnnotatedEndpointWithDefaultAggregator {
|
||||
private final ConcurrentMap<Object, Message<?>> aggregatedMessages = new ConcurrentHashMap<Object, Message<?>>();
|
||||
|
||||
@Aggregator
|
||||
public Message<?> aggregatingMethod(Collection<Message<?>> messages) {
|
||||
public Message<?> aggregatingMethod(List<Message<?>> messages) {
|
||||
List<Message<?>> sortableList = new ArrayList<Message<?>>(messages);
|
||||
Collections.sort(sortableList, new MessageSequenceComparator());
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
@@ -7,29 +7,41 @@
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||
|
||||
<aggregator id="aggregatorWithReference" ref="aggregatorBean"/>
|
||||
<aggregator id="aggregatorWithReference" ref="aggregatorBean" />
|
||||
|
||||
<aggregator id="completelyDefinedAggregator"
|
||||
ref="aggregatorBean"
|
||||
completion-strategy="completionStrategy"
|
||||
default-reply-channel="replyChannel"
|
||||
discard-channel="discardChannel"
|
||||
send-timeout="86420000"
|
||||
send-partial-result-on-timeout="true"
|
||||
reaper-interval="135"
|
||||
tracked-correlation-id-capacity="99"
|
||||
timeout="42"/>
|
||||
|
||||
<aggregator id="aggregatorWithReferenceAndMethod" ref="adderBean" method="add" default-reply-channel="replyChannel"/>
|
||||
<aggregator id="completelyDefinedAggregator" ref="aggregatorBean"
|
||||
completion-strategy="completionStrategy"
|
||||
default-reply-channel="replyChannel" discard-channel="discardChannel"
|
||||
send-timeout="86420000" send-partial-result-on-timeout="true"
|
||||
reaper-interval="135" tracked-correlation-id-capacity="99"
|
||||
timeout="42" />
|
||||
|
||||
<channel id="replyChannel"/>
|
||||
|
||||
<channel id="discardChannel"/>
|
||||
<aggregator id="aggregatorWithReferenceAndMethod" ref="adderBean"
|
||||
method="add" default-reply-channel="replyChannel" />
|
||||
|
||||
<beans:bean id="aggregatorBean" class="org.springframework.integration.config.TestAggregator"/>
|
||||
|
||||
<beans:bean id="adderBean" class="org.springframework.integration.config.Adder"/>
|
||||
<aggregator id="aggregatorWithPojoCompletionStrategy"
|
||||
ref="adderBean" method="add" default-reply-channel="replyChannel">
|
||||
<completion-strategy ref="pojoCompletionStrategy"
|
||||
method="checkCompleteness" />
|
||||
</aggregator>
|
||||
|
||||
<beans:bean id="completionStrategy" class="org.springframework.integration.config.TestCompletionStrategy"/>
|
||||
<channel id="replyChannel" />
|
||||
|
||||
<channel id="discardChannel" />
|
||||
|
||||
<beans:bean id="aggregatorBean"
|
||||
class="org.springframework.integration.config.TestAggregator" />
|
||||
|
||||
<beans:bean id="adderBean"
|
||||
class="org.springframework.integration.config.Adder" />
|
||||
|
||||
<beans:bean id="completionStrategy"
|
||||
class="org.springframework.integration.config.TestCompletionStrategy" />
|
||||
|
||||
<beans:bean id="pojoCompletionStrategy"
|
||||
class="org.springframework.integration.config.MaxValueCompletionStrategy">
|
||||
<beans:constructor-arg value="10" />
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<aggregator id="aggregator" ref="adderBean" method="add" completion-strategy="testCompletionStrategy" default-reply-channel="replyChannel">
|
||||
<completion-strategy ref="testCompletionStrategy"/>
|
||||
</aggregator>
|
||||
|
||||
<channel id="replyChannel"/>
|
||||
|
||||
<beans:bean id="adderBean" class="org.springframework.integration.config.Adder"/>
|
||||
|
||||
<beans:bean id="completionStrategyBean" class="org.springframework.integration.config.TestCompletionStrategy"></beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
@@ -6,7 +6,9 @@
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<aggregator id="aggregatorWithReferenceAndMethod" ref="adderBean" method="substract" default-reply-channel="replyChannel"/>
|
||||
|
||||
<channel id="replyChannel"/>
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
<context:component-scan base-package="org.springframework.integration.config" use-default-filters="false">
|
||||
<context:include-filter type="regex"
|
||||
expression="org\.springframework\.integration\.config\.TestAnnotatedEndpoint.*"/>
|
||||
<context:exclude-filter type="regex"
|
||||
expression="org\.springframework\.integration\.config\.TestAnnotatedEndpointWithCompletionStrategyOnly"/>
|
||||
</context:component-scan>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<annotation-driven/>
|
||||
|
||||
<channel id="inputChannel"/>
|
||||
|
||||
<channel id="replyChannel"/>
|
||||
|
||||
<channel id="discardChannel"/>
|
||||
|
||||
<context:component-scan base-package="org.springframework.integration.config" use-default-filters="false">
|
||||
<context:include-filter type="regex"
|
||||
expression="org\.springframework\.integration\.config\.TestAnnotatedEndpointWithCompletionStrategyOnly"/>
|
||||
</context:component-scan>
|
||||
|
||||
</beans:beans>
|
||||
@@ -208,7 +208,7 @@ public class AggregatingMessageHandlerTests {
|
||||
|
||||
private static class TestAggregator implements Aggregator {
|
||||
|
||||
public Message<?> aggregate(Collection<Message<?>> messages) {
|
||||
public Message<?> aggregate(List<Message<?>> messages) {
|
||||
List<Message<?>> sortableList = new ArrayList<Message<?>>(messages);
|
||||
Collections.sort(sortableList, new MessageSequenceComparator());
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
@@ -18,13 +18,12 @@ package org.springframework.integration.router;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
@@ -44,9 +43,9 @@ public class AggregatorAdapterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithNonParameterizedMessageCollectionBasedMethod() {
|
||||
Aggregator aggregator = new AggregatorAdapter(simpleAggregator, "doAggregationOnNonParameterizedCollectionOfMessages");
|
||||
Collection<Message<?>> messages = createCollectionOfMessages();
|
||||
public void testAdapterWithNonParameterizedMessageListBasedMethod() {
|
||||
Aggregator aggregator = new AggregatorAdapter(simpleAggregator, "doAggregationOnNonParameterizedListOfMessages");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessge = aggregator.aggregate(messages);
|
||||
Assert.assertTrue(simpleAggregator.isAggregationPerformed());
|
||||
Assert.assertEquals("123456789", returnedMessge.getPayload());
|
||||
@@ -54,8 +53,8 @@ public class AggregatorAdapterTests {
|
||||
|
||||
@Test
|
||||
public void testAdapterWithWildcardParametrizedMessageBasedMethod() {
|
||||
Aggregator aggregator = new AggregatorAdapter(simpleAggregator, "doAggregationOnCollectionOfMessagesParametrizedWithWildcard");
|
||||
Collection<Message<?>> messages = createCollectionOfMessages();
|
||||
Aggregator aggregator = new AggregatorAdapter(simpleAggregator, "doAggregationOnListOfMessagesParametrizedWithWildcard");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessge = aggregator.aggregate(messages);
|
||||
Assert.assertTrue(simpleAggregator.isAggregationPerformed());
|
||||
Assert.assertEquals("123456789", returnedMessge.getPayload());
|
||||
@@ -63,8 +62,8 @@ public class AggregatorAdapterTests {
|
||||
|
||||
@Test
|
||||
public void testAdapterWithTypeParametrizedMessageBasedMethod() {
|
||||
Aggregator aggregator = new AggregatorAdapter(simpleAggregator, "doAggregationOnCollectionOfMessagesParametrizedWithString");
|
||||
Collection<Message<?>> messages = createCollectionOfMessages();
|
||||
Aggregator aggregator = new AggregatorAdapter(simpleAggregator, "doAggregationOnListOfMessagesParametrizedWithString");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessge = aggregator.aggregate(messages);
|
||||
Assert.assertTrue(simpleAggregator.isAggregationPerformed());
|
||||
Assert.assertEquals("123456789", returnedMessge.getPayload());
|
||||
@@ -72,8 +71,8 @@ public class AggregatorAdapterTests {
|
||||
|
||||
@Test
|
||||
public void testAdapterWithPojoBasedMethod() {
|
||||
Aggregator aggregator = new AggregatorAdapter(simpleAggregator, "doAggregationOnCollectionOfStrings");
|
||||
Collection<Message<?>> messages = createCollectionOfMessages();
|
||||
Aggregator aggregator = new AggregatorAdapter(simpleAggregator, "doAggregationOnListOfStrings");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessge = aggregator.aggregate(messages);
|
||||
Assert.assertTrue(simpleAggregator.isAggregationPerformed());
|
||||
Assert.assertEquals("123456789", returnedMessge.getPayload());
|
||||
@@ -81,8 +80,8 @@ public class AggregatorAdapterTests {
|
||||
|
||||
@Test
|
||||
public void testAdapterWithPojoBasedMethodReturningObject() {
|
||||
Aggregator aggregator = new AggregatorAdapter(simpleAggregator, "doAggregationOnCollectionOfStringsReturningLong");
|
||||
Collection<Message<?>> messages = createCollectionOfMessages();
|
||||
Aggregator aggregator = new AggregatorAdapter(simpleAggregator, "doAggregationOnListOfStringsReturningLong");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessge = aggregator.aggregate(messages);
|
||||
Assert.assertTrue(simpleAggregator.isAggregationPerformed());
|
||||
Assert.assertEquals(123456789l, returnedMessge.getPayload());
|
||||
@@ -109,8 +108,8 @@ public class AggregatorAdapterTests {
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testCollectionSubclassParameterUsingMethodName() {
|
||||
new AggregatorAdapter(simpleAggregator, "collectionSubclassParameter");
|
||||
public void testListSubclassParameterUsingMethodName() {
|
||||
new AggregatorAdapter(simpleAggregator, "ListSubclassParameter");
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
@@ -122,7 +121,7 @@ public class AggregatorAdapterTests {
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testTooManyParametersUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new AggregatorAdapter(simpleAggregator, simpleAggregator.getClass().getMethod(
|
||||
"tooManyParameters", Collection.class, Collection.class));
|
||||
"tooManyParameters", List.class, List.class));
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
@@ -132,9 +131,9 @@ public class AggregatorAdapterTests {
|
||||
}
|
||||
|
||||
@Test(expected= ConfigurationException.class)
|
||||
public void testCollectionSubclassParameterUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
public void testListSubclassParameterUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new AggregatorAdapter(simpleAggregator, simpleAggregator.getClass().getMethod(
|
||||
"collectionSubclassParameter", new Class[] {List.class} ));
|
||||
"listSubclassParameter", new Class[] {LinkedList.class} ));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@@ -155,8 +154,8 @@ public class AggregatorAdapterTests {
|
||||
}
|
||||
|
||||
|
||||
private static Collection<Message<?>> createCollectionOfMessages() {
|
||||
Collection<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
private static List<Message<?>> createListOfMessages() {
|
||||
List<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
messages.add(new GenericMessage<String>("123"));
|
||||
messages.add(new GenericMessage<String>("456"));
|
||||
messages.add(new GenericMessage<String>("789"));
|
||||
@@ -178,7 +177,7 @@ public class AggregatorAdapterTests {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Message<?> doAggregationOnNonParameterizedCollectionOfMessages(Collection<Message> messages) {
|
||||
public Message<?> doAggregationOnNonParameterizedListOfMessages(List<Message> messages) {
|
||||
this.aggregationPerformed = true;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (Message<?> message : messages) {
|
||||
@@ -187,7 +186,7 @@ public class AggregatorAdapterTests {
|
||||
return new GenericMessage<String>(buffer.toString());
|
||||
}
|
||||
|
||||
public Message<?> doAggregationOnCollectionOfMessagesParametrizedWithWildcard(Collection<Message<?>> messages) {
|
||||
public Message<?> doAggregationOnListOfMessagesParametrizedWithWildcard(List<Message<?>> messages) {
|
||||
this.aggregationPerformed = true;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (Message<?> message : messages) {
|
||||
@@ -196,7 +195,7 @@ public class AggregatorAdapterTests {
|
||||
return new GenericMessage<String>(buffer.toString());
|
||||
}
|
||||
|
||||
public Message<?> doAggregationOnCollectionOfMessagesParametrizedWithString(Collection<Message<String>> messages) {
|
||||
public Message<?> doAggregationOnListOfMessagesParametrizedWithString(List<Message<String>> messages) {
|
||||
this.aggregationPerformed = true;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (Message<String> message : messages) {
|
||||
@@ -205,7 +204,7 @@ public class AggregatorAdapterTests {
|
||||
return new GenericMessage<String>(buffer.toString());
|
||||
}
|
||||
|
||||
public Message<?> doAggregationOnCollectionOfStrings(Collection<String> messages) {
|
||||
public Message<?> doAggregationOnListOfStrings(List<String> messages) {
|
||||
this.aggregationPerformed = true;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (String payload : messages) {
|
||||
@@ -214,7 +213,7 @@ public class AggregatorAdapterTests {
|
||||
return new GenericMessage<String>(buffer.toString());
|
||||
}
|
||||
|
||||
public Long doAggregationOnCollectionOfStringsReturningLong(Collection<String> messages) {
|
||||
public Long doAggregationOnListOfStringsReturningLong(List<String> messages) {
|
||||
this.aggregationPerformed = true;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (String payload : messages) {
|
||||
@@ -227,7 +226,7 @@ public class AggregatorAdapterTests {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Message<?> tooManyParameters(Collection<?> c1, Collection<?> c2) {
|
||||
public Message<?> tooManyParameters(List<?> c1, List<?> c2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -235,7 +234,7 @@ public class AggregatorAdapterTests {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Message<?> collectionSubclassParameter(List<?> l1){
|
||||
public Message<?> listSubclassParameter(LinkedList<?> l1){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user