INT-677 - added inner bean definition support for <splitter/> and <transformer/> message consumers
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<?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/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd"
|
||||
xmlns:util="http://www.springframework.org/schema/util">
|
||||
|
||||
<util:properties id="testConfigurations" location="classpath:org/springframework/integration/config/xml/innerdefaware.properties"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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 java.io.ByteArrayInputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class InnerDefinitionAwareEndpointParserTests {
|
||||
|
||||
@Autowired
|
||||
private Properties testConfigurations;
|
||||
|
||||
@Test
|
||||
public void testInnerSplitterDefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("splitter-inner-success");
|
||||
this.testSplitterDefinitionSuccess(configProperty);
|
||||
}
|
||||
@Test
|
||||
public void testRefSplitterDefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("splitter-ref-success");
|
||||
this.testSplitterDefinitionSuccess(configProperty);
|
||||
}
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testInnerSplitterDefinitionFailureRefAndInner(){
|
||||
String xmlConfig = testConfigurations.getProperty("splitter-failure-refAndBean");
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(xmlConfig.getBytes());
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
||||
reader.loadBeanDefinitions(new InputStreamResource(stream));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInnerTransformerDefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("transformer-inner-success");
|
||||
this.testTransformerDefinitionSuccess(configProperty);
|
||||
}
|
||||
@Test
|
||||
public void testRefTransformerDefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("transformer-ref-success");
|
||||
this.testTransformerDefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testInnerTransformerDefinitionFailureRefAndInner(){
|
||||
String xmlConfig = testConfigurations.getProperty("transformer-failure-refAndBean");
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(xmlConfig.getBytes());
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
||||
reader.loadBeanDefinitions(new InputStreamResource(stream));
|
||||
}
|
||||
|
||||
private void testSplitterDefinitionSuccess(String configProperty){
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(configProperty.getBytes());
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
||||
reader.loadBeanDefinitions(new InputStreamResource(stream));
|
||||
EventDrivenConsumer splitter = (EventDrivenConsumer) ac.getBean("testSplitter");
|
||||
Assert.assertNotNull(splitter);
|
||||
MessageBuilder inChannelMessageBuilder = MessageBuilder.withPayload(new String[]{"One","Two"});
|
||||
Message inMessage = inChannelMessageBuilder.build();
|
||||
DirectChannel inChannel = (DirectChannel) ac.getBean("inChannel");
|
||||
inChannel.send(inMessage);
|
||||
PollableChannel outChannel = (PollableChannel) ac.getBean("outChannel");
|
||||
Assert.assertTrue(outChannel.receive().getPayload() instanceof String);
|
||||
outChannel = (PollableChannel) ac.getBean("outChannel");
|
||||
Assert.assertTrue(outChannel.receive().getPayload() instanceof String);
|
||||
}
|
||||
|
||||
private void testTransformerDefinitionSuccess(String configProperty){
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(configProperty.getBytes());
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
||||
reader.loadBeanDefinitions(new InputStreamResource(stream));
|
||||
EventDrivenConsumer transformer = (EventDrivenConsumer) ac.getBean("testTransformer");
|
||||
Assert.assertNotNull(transformer);
|
||||
MessageBuilder inChannelMessageBuilder = MessageBuilder.withPayload(new String[]{"One","Two"});
|
||||
Message inMessage = inChannelMessageBuilder.build();
|
||||
DirectChannel inChannel = (DirectChannel) ac.getBean("inChannel");
|
||||
inChannel.send(inMessage);
|
||||
PollableChannel outChannel = (PollableChannel) ac.getBean("outChannel");
|
||||
String payload = (String) outChannel.receive().getPayload();
|
||||
Assert.assertTrue(payload.equals("One,Two"));
|
||||
}
|
||||
|
||||
public static class TestSplitter{
|
||||
public Collection split(String[] payload){
|
||||
return CollectionUtils.arrayToList(payload);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestTransformer{
|
||||
public String split(String[] payload){
|
||||
return StringUtils.arrayToDelimitedString(payload, ",");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
splitter-inner-success=\
|
||||
<?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-1.0.xsd"> \
|
||||
<channel id="inChannel"/> \
|
||||
<channel id="outChannel"> \
|
||||
<queue capacity="2" /> \
|
||||
</channel> \
|
||||
<splitter id="testSplitter" input-channel="inChannel" output-channel="outChannel"> \
|
||||
<beans:bean class="org.springframework.integration.config.xml.InnerDefinitionAwareEndpointParserTests$TestSplitter" /> \
|
||||
</splitter> \
|
||||
</beans:beans>
|
||||
splitter-ref-success=\
|
||||
<?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-1.0.xsd"> \
|
||||
<channel id="inChannel"/> \
|
||||
<channel id="outChannel"> \
|
||||
<queue capacity="2" /> \
|
||||
</channel> \
|
||||
<splitter id="testSplitter" ref="splitterBean" input-channel="inChannel" output-channel="outChannel"/> \
|
||||
<beans:bean id="splitterBean" class="org.springframework.integration.config.xml.InnerDefinitionAwareEndpointParserTests$TestSplitter" /> \
|
||||
</beans:beans>
|
||||
splitter-failure-refAndBean=\
|
||||
<?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-1.0.xsd"> \
|
||||
<channel id="inChannel"/> \
|
||||
<channel id="outChannel"> \
|
||||
<queue capacity="2" /> \
|
||||
</channel> \
|
||||
<splitter id="testSplitter" ref="splitterBean" input-channel="inChannel" output-channel="outChannel"> \
|
||||
<beans:bean class="org.springframework.integration.config.xml.InnerDefinitionAwareEndpointParserTests$TestSplitter" /> \
|
||||
</splitter> \
|
||||
<beans:bean id="splitterBean" class="org.springframework.integration.config.xml.InnerDefinitionAwareEndpointParserTests$TestSplitter" /> \
|
||||
</beans:beans>
|
||||
transformer-inner-success=\
|
||||
<?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-1.0.xsd"> \
|
||||
<channel id="inChannel"/> \
|
||||
<channel id="outChannel"> \
|
||||
<queue capacity="1" /> \
|
||||
</channel> \
|
||||
<transformer id="testTransformer" input-channel="inChannel" output-channel="outChannel"> \
|
||||
<beans:bean class="org.springframework.integration.config.xml.InnerDefinitionAwareEndpointParserTests$TestTransformer" /> \
|
||||
</transformer> \
|
||||
</beans:beans>
|
||||
transformer-ref-success=\
|
||||
<?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-1.0.xsd"> \
|
||||
<channel id="inChannel"/> \
|
||||
<channel id="outChannel"> \
|
||||
<queue capacity="1" /> \
|
||||
</channel> \
|
||||
<transformer id="testTransformer" ref="testTransformerBean" input-channel="inChannel" output-channel="outChannel"/> \
|
||||
<beans:bean id="testTransformerBean" class="org.springframework.integration.config.xml.InnerDefinitionAwareEndpointParserTests$TestTransformer" /> \
|
||||
</beans:beans>
|
||||
transformer-failure-refAndBean=\
|
||||
<?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-1.0.xsd"> \
|
||||
<channel id="inChannel"/> \
|
||||
<channel id="outChannel"> \
|
||||
<queue capacity="1" /> \
|
||||
</channel> \
|
||||
<splitter id="testTransformer" ref="testTransformerBean" input-channel="inChannel" output-channel="outChannel"> \
|
||||
<beans:bean class="org.springframework.integration.config.xml.InnerDefinitionAwareEndpointParserTests$TestTransformer" /> \
|
||||
</splitter> \
|
||||
<beans:bean id="testTransformerBean" class="org.springframework.integration.config.xml.InnerDefinitionAwareEndpointParserTests$TestTransformer" /> \
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user