INT-1927 allow sub-elements of <channel-interceptor> other than <bean> tested with <wire-tap>

This commit is contained in:
David Turanski
2011-06-24 13:47:49 -04:00
parent bad2debbf7
commit b60525a259
6 changed files with 171 additions and 41 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"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<int:channel id="inputA"/>
<int:channel-interceptor>
<int:wire-tap channel="wiretap"/>
</int:channel-interceptor>
<int:channel id="wiretap">
<int:queue/>
</int:channel>
<int:bridge input-channel="inputA" output-channel="nullChannel"/>
</beans>

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2002-2011 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.channel.interceptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.message.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author David Turanski
* @since 2.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class GlobalChannelInterceptorSubElementTests {
@Autowired
ApplicationContext applicationContext;
@Autowired
@Qualifier("inputA")
MessageChannel inputA;
@Autowired
@Qualifier("wiretap")
PollableChannel wiretapChannel;
@Test
public void testWiretapSubElement(){
inputA.send(new GenericMessage<String>("hello"));
Message<?> result = wiretapChannel.receive(100);
assertNotNull(result);
assertEquals("hello",result.getPayload());
}
}

View File

@@ -16,6 +16,9 @@
package org.springframework.integration.channel.interceptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -24,30 +27,36 @@ import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.channel.ChannelInterceptor;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @author Dave Turanski
* @author David Turanski
* @since 2.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class GlobalChannelInterceptorTests {
@Autowired
ApplicationContext applicationContext;
@Test
public void validateGlobalInterceptor() throws Exception{
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"GlobalChannelInterceptorTests-context.xml", GlobalChannelInterceptorTests.class);
Map<String, MessageChannel> channels = applicationContext.getBeansOfType(MessageChannel.class);
Map<String, MessageChannel> channels = applicationContext.getBeansOfType(MessageChannel.class);
for (String channelName : channels.keySet()) {
MessageChannel channel = channels.get(channelName);
if (channelName.equals("nullChannel")){
@@ -107,12 +116,14 @@ public class GlobalChannelInterceptorTests {
}
}
@Autowired
@Qualifier("inpuC")
MessageChannel inpuCchannel;
@Test
public void testWildCardPatternMatch() {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"GlobalChannelInterceptorTests-context.xml", GlobalChannelInterceptorTests.class);
AbstractMessageChannel channel = applicationContext.getBean("inpuC", AbstractMessageChannel.class);
List<?> interceptorList = TestUtils.getPropertyValue(channel, "interceptors.interceptors", List.class);
List<?> interceptorList = TestUtils.getPropertyValue(inpuCchannel, "interceptors.interceptors", List.class);
List<String> interceptorNames = new ArrayList<String>();
for (Object interceptor : interceptorList) {
interceptorNames.add(interceptor.toString());
@@ -121,7 +132,7 @@ public class GlobalChannelInterceptorTests {
Assert.assertTrue(interceptorNames.contains("interceptor-eleven"));
}
public static class SampleInterceptor implements ChannelInterceptor {
private String testIdentifier;