INT-2594 added BF support to ExpressionEvaluatingCorrelationStrategy

This commit is contained in:
Oleg Zhurakousky
2012-06-12 12:27:08 -04:00
committed by Gary Russell
parent 8a4698d7cf
commit 8758aec3d1
3 changed files with 69 additions and 6 deletions

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Copyright 2002-2012 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.
@@ -14,17 +14,25 @@
package org.springframework.integration.aggregator;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.SpelParserConfiguration;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
/**
* @author Alex Peters
* @author Oleg Zhurakousky
*/
public class ExpressionEvaluatingCorrelationStrategyTests {
@@ -51,4 +59,22 @@ public class ExpressionEvaluatingCorrelationStrategyTests {
assertThat(correlationKey, is(String.class));
assertThat((String) correlationKey, is("b"));
}
@Test
public void testCorrelationStrategyWithAtBeanExpression() throws Exception {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("expression-evaluating-correlation-with-bf.xml", this.getClass());
MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
QueueChannel outputChannel = context.getBean("outputChannel", QueueChannel.class);
Message<?> message = MessageBuilder.withPayload("foo").setSequenceNumber(1).setSequenceSize(1).build();
inputChannel.send(message);
Message<?> reply = outputChannel.receive(0);
assertNotNull(reply);
}
public static class CustomCorrelator {
public Object correlate(Object o){
return o;
}
}
}

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.2.xsd">
<int:aggregator input-channel="inputChannel" output-channel="outputChannel"
correlation-strategy-expression="@correlator.correlate(payload)"/>
<int:channel id="outputChannel">
<int:queue/>
</int:channel>
<bean id="correlator"
class="org.springframework.integration.aggregator.ExpressionEvaluatingCorrelationStrategyTests.CustomCorrelator"/>
</beans>