INT-681, INT-710, INT-1181 The <service-activator> element now supports an "expression" attribute as an alternative to "ref" + "method". Added ServiceActivatorFactoryBean, modified parser, updated schema, added ServiceActivator constructor to accept expression string, and provided some basic tests.

This commit is contained in:
Mark Fisher
2010-06-16 19:25:35 +00:00
parent be92d13413
commit 7565773418
6 changed files with 206 additions and 33 deletions

View File

@@ -0,0 +1,20 @@
<?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.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<service-activator input-channel="literalExpressionInput" expression="'foo'"/>
<service-activator input-channel="beanAsTargetInput" expression="@testBean.caps(payload)"/>
<service-activator input-channel="beanAsArgumentInput" expression="payload.getSimpleClassName(@testBean)"/>
<service-activator input-channel="beanInvocationResultInput" expression="payload.concat(@testBean.caps('foo'))"/>
<beans:bean id="testBean" class="org.springframework.integration.config.xml.ServiceActivatorParserTests$TestBean"/>
</beans:beans>

View File

@@ -0,0 +1,100 @@
/*
* Copyright 2002-2010 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.xml;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.gateway.SimpleMessagingGateway;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class ServiceActivatorParserTests {
@Autowired
private MessageChannel literalExpressionInput;
@Autowired
private MessageChannel beanAsTargetInput;
@Autowired
private MessageChannel beanAsArgumentInput;
@Autowired
private MessageChannel beanInvocationResultInput;
@Test
public void literalExpression() {
Object result = this.sendAndReceive(literalExpressionInput, "hello");
assertEquals("foo", result);
}
@Test
public void beanAsTarget() {
Object result = this.sendAndReceive(beanAsTargetInput, "hello");
assertEquals("HELLO", result);
}
@Test
public void beanAsArgument() {
Object result = this.sendAndReceive(beanAsArgumentInput, new TestPayload());
assertEquals("TestBean", result);
}
@Test
public void beanInvocationResult() {
Object result = this.sendAndReceive(beanInvocationResultInput, "hello");
assertEquals("helloFOO", result);
}
private Object sendAndReceive(MessageChannel channel, Object payload) {
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
gateway.setRequestChannel(channel);
return gateway.sendAndReceive(payload);
}
@SuppressWarnings("unused")
private static class TestBean {
public String caps(String s) {
return s.toUpperCase();
}
}
@SuppressWarnings("unused")
private static class TestPayload {
public String getSimpleClassName(Object o) {
return o.getClass().getSimpleName();
}
}
}