INT-789, Fixed the schema file, added one more test

This commit is contained in:
Oleg Zhurakousky
2010-03-27 01:32:02 +00:00
parent 7381ee28cf
commit 7a72fbc9e7
4 changed files with 65 additions and 15 deletions

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:p="http://www.springframework.org/schema/p">
<int:channel id="inputA">
<int:interceptors>
<bean class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="eight"/>
</int:interceptors>
</int:channel>
<int:channel id="inputB"/>
<int:channel id="inputC"/>
<int:channel-interceptor-chain channel-name-pattern="*" order="3">
<bean class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="six"/>
</int:channel-interceptor-chain>
</beans>

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.integration.channel.interceptor;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -167,13 +166,29 @@ public class GlobalChannelInterceptorTests {
}
}
}
/**
* Will test failure if 'channel-name-pattern' filter points to a valid
* bean which is not an AbstractMessageChannel
*/
@Test(expected=BeanCreationException.class)
public void failGlobalInterceptorConfig(){
new ClassPathXmlApplicationContext("GlobalChannelInterceptorTests-failed-context.xml", GlobalChannelInterceptorTests.class);
@SuppressWarnings("unchecked")
@Test
public void validateGlobalInterceptorsAllPattern(){
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("GlobalChannelInterceptorTests-all-context.xml", GlobalChannelInterceptorTests.class);
Map<String, AbstractMessageChannel> channels = applicationContext.getBeansOfType(AbstractMessageChannel.class);
for (String channelName : channels.keySet()) {
AbstractMessageChannel channel = channels.get(channelName);
DirectFieldAccessor cAccessor = new DirectFieldAccessor(channel);
Object iList = cAccessor.getPropertyValue("interceptors");
DirectFieldAccessor iAccessor = new DirectFieldAccessor(iList);
List<SampleInterceptor> interceptoList = (List<SampleInterceptor>) iAccessor.getPropertyValue("interceptors");
if (channelName.equals("inputA")){
SampleInterceptor[] inter = interceptoList.toArray(new SampleInterceptor[]{});
Assert.assertTrue(inter.length == 2);
} else if (channelName.equals("inputB")){
SampleInterceptor[] inter = interceptoList.toArray(new SampleInterceptor[]{});
Assert.assertTrue(inter.length == 1);
} else if (channelName.equals("inputC")){
SampleInterceptor[] inter = interceptoList.toArray(new SampleInterceptor[]{});
Assert.assertTrue(inter.length == 1);
}
}
}
public static class SampleInterceptor implements ChannelInterceptor {