INT-654
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -30,6 +30,8 @@ import org.junit.Test;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.aggregator.CorrelationStrategy;
|
||||
import org.springframework.integration.aggregator.CorrelationStrategyAdapter;
|
||||
import org.springframework.integration.aggregator.Resequencer;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
@@ -39,6 +41,7 @@ import org.springframework.integration.message.MessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ResequencerParserTests {
|
||||
|
||||
@@ -117,6 +120,25 @@ public class ResequencerParserTests {
|
||||
false, getPropertyValue(resequencer, "releasePartialSequences"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCorrelationStrategyRefOnly() throws Exception {
|
||||
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithCorrelationStrategyRefOnly");
|
||||
Resequencer resequencer = (Resequencer) new DirectFieldAccessor(endpoint).getPropertyValue("handler");
|
||||
assertEquals("The ResequencerEndpoint is not configured with the appropriate CorrelationStrategy",
|
||||
context.getBean("testCorrelationStrategy"), getPropertyValue(resequencer, "correlationStrategy"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCorrelationStrategyRefAndMethod() throws Exception {
|
||||
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithCorrelationStrategyRefAndMethod");
|
||||
Resequencer resequencer = (Resequencer) new DirectFieldAccessor(endpoint).getPropertyValue("handler");
|
||||
Object correlationStrategy = getPropertyValue(resequencer, "correlationStrategy");
|
||||
assertEquals("The ResequencerEndpoint is not configured with a CorrelationStrategy adapter",
|
||||
CorrelationStrategyAdapter.class, correlationStrategy.getClass());
|
||||
CorrelationStrategyAdapter adapter = (CorrelationStrategyAdapter) correlationStrategy;
|
||||
assertEquals("foo", adapter.getCorrelationKey(MessageBuilder.withPayload("not important").build()));
|
||||
}
|
||||
|
||||
|
||||
private static <T> Message<T> createMessage(T payload, Object correlationId,
|
||||
int sequenceSize, int sequenceNumber, MessageChannel outputChannel) {
|
||||
@@ -128,4 +150,20 @@ public class ResequencerParserTests {
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
static class TestCorrelationStrategy implements CorrelationStrategy {
|
||||
|
||||
public Object getCorrelationKey(Message<?> message) {
|
||||
return "test";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class TestCorrelationStrategyPojo {
|
||||
|
||||
public Object foo(Object o) {
|
||||
return "foo";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
|
||||
<channel id="inputChannel2"/>
|
||||
|
||||
<channel id="inputChannel3"/>
|
||||
|
||||
<channel id="inputChannel4"/>
|
||||
|
||||
<resequencer id="completelyDefinedResequencer"
|
||||
input-channel="inputChannel2"
|
||||
output-channel="outputChannel"
|
||||
@@ -32,4 +36,19 @@
|
||||
timeout="42"
|
||||
release-partial-sequences="false"/>
|
||||
|
||||
<resequencer id="resequencerWithCorrelationStrategyRefOnly"
|
||||
input-channel="inputChannel3"
|
||||
correlation-strategy="testCorrelationStrategy"/>
|
||||
|
||||
<resequencer id="resequencerWithCorrelationStrategyRefAndMethod"
|
||||
input-channel="inputChannel4"
|
||||
correlation-strategy="testCorrelationStrategyPojo"
|
||||
correlation-strategy-method="foo"/>
|
||||
|
||||
<beans:bean id="testCorrelationStrategy"
|
||||
class="org.springframework.integration.config.ResequencerParserTests$TestCorrelationStrategy"/>
|
||||
|
||||
<beans:bean id="testCorrelationStrategyPojo"
|
||||
class="org.springframework.integration.config.ResequencerParserTests$TestCorrelationStrategyPojo"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
Reference in New Issue
Block a user