From cd87a1a167a593722f291a38feb730948a023439 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 24 Aug 2011 15:47:31 -0400 Subject: [PATCH] INT-2011 fixed MessagingMethodInvokerHelper.HandlerMethod.dummyMessages to be of type Collection> instead of List> --- .../util/MessagingMethodInvokerHelper.java | 2 +- .../config/AggregatorParserTests.java | 26 +++++++++++++++++++ .../config/MaxValueReleaseStrategy.java | 11 +++++++- .../config/aggregatorParserTests.xml | 11 +++++++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java index 3b923d5baa..d0f3fdd330 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java @@ -419,7 +419,7 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator private static final TypeDescriptor messageArrayTypeDescriptor = TypeDescriptor.valueOf(Message[].class); @SuppressWarnings("unused") - private static final List> dummyMessages = Collections.emptyList(); + private static final Collection> dummyMessages = Collections.emptyList(); private final Method method; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java index 444f38503f..f88586dd24 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java @@ -53,6 +53,7 @@ import org.springframework.integration.test.util.TestUtils; * @author Marius Bogoevici * @author Mark Fisher * @author Iwein Fuld + * @author Oleg Zhurakousky */ public class AggregatorParserTests { @@ -184,6 +185,31 @@ public class AggregatorParserTests { Assert.assertNotNull(reply); assertEquals(11l, reply.getPayload()); } + + @Test // see INT-2011 + public void testAggregatorWithPojoReleaseStrategyAsCollection() { + MessageChannel input = (MessageChannel) context.getBean("aggregatorWithPojoReleaseStrategyInputAsCollection"); + EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("aggregatorWithPojoReleaseStrategyAsCollection"); + ReleaseStrategy releaseStrategy = (ReleaseStrategy) new DirectFieldAccessor(new DirectFieldAccessor(endpoint) + .getPropertyValue("handler")).getPropertyValue("releaseStrategy"); + Assert.assertTrue(releaseStrategy instanceof MethodInvokingReleaseStrategy); + DirectFieldAccessor releaseStrategyAccessor = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(releaseStrategy) + .getPropertyValue("adapter")).getPropertyValue("delegate")); + Map map = (Map) releaseStrategyAccessor.getPropertyValue("handlerMethods"); + assertEquals("The release strategy is not injected with the appropriate method", 1, map.size()); + assertTrue("Handler methods do not contain correct method: " + map, map.toString() + .contains("checkCompleteness")); + input.send(createMessage(1l, "correllationId", 4, 0, null)); + input.send(createMessage(2l, "correllationId", 4, 1, null)); + input.send(createMessage(3l, "correllationId", 4, 2, null)); + PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel"); + Message reply = outputChannel.receive(0); + Assert.assertNull(reply); + input.send(createMessage(5l, "correllationId", 4, 3, null)); + reply = outputChannel.receive(0); + Assert.assertNotNull(reply); + assertEquals(11l, reply.getPayload()); + } @Test(expected = BeanCreationException.class) public void testAggregatorWithInvalidReleaseStrategyMethod() { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/MaxValueReleaseStrategy.java b/spring-integration-core/src/test/java/org/springframework/integration/config/MaxValueReleaseStrategy.java index aaca1a3b8f..223606049f 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/MaxValueReleaseStrategy.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/MaxValueReleaseStrategy.java @@ -15,6 +15,7 @@ */ package org.springframework.integration.config; +import java.util.Collection; import java.util.List; public class MaxValueReleaseStrategy { @@ -26,7 +27,15 @@ public class MaxValueReleaseStrategy { this.maxValue = maxValue; } - public boolean checkCompleteness(List numbers) { + public boolean checkCompletenessAsList(List numbers) { + int sum = 0; + for (long number: numbers) { + sum += number; + } + return sum >= maxValue; + } + + public boolean checkCompletenessAsCollection(Collection numbers) { int sum = 0; for (long number: numbers) { sum += number; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/aggregatorParserTests.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/aggregatorParserTests.xml index 425441b4e9..1964ed742b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/aggregatorParserTests.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/aggregatorParserTests.xml @@ -52,7 +52,16 @@ ref="adderBean" method="add" release-strategy="pojoReleaseStrategy" - release-strategy-method="checkCompleteness"/> + release-strategy-method="checkCompletenessAsList"/> + + +