INT-3422: Add ChannelInterceptorAware.remove()

JIRA: https://jira.spring.io/browse/INT-3422

* Add two methods:
```
boolean removeInterceptor(ChannelInterceptor interceptor);
boolean removeInterceptor(int index);
```

The method `removeInterceptorsOfType(Class<?> clazz)` isn't good, because we lead undesired behavior, when several provided interceptors might be of the same type (e.g. by superclass)

INT-3422: PR comments
This commit is contained in:
Artem Bilan
2014-08-01 14:40:42 +03:00
committed by Gary Russell
parent 463c185b38
commit 507fd42d01
3 changed files with 69 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.channel.ChannelInterceptorAware;
@@ -70,8 +70,15 @@ public class ChannelInterceptorTests {
Message<?> message = new GenericMessage<String>("test");
channel.send(message);
assertEquals(1, interceptor.getCount());
assertTrue(channel.removeInterceptor(interceptor));
channel.send(new GenericMessage<String>("TEST"));
assertEquals(1, interceptor.getCount());
Message<?> result = channel.receive(0);
assertNull(result);
assertNotNull(result);
assertEquals("TEST", result.getPayload());
}
@Test
@@ -116,6 +123,11 @@ public class ChannelInterceptorTests {
singleItemChannel.send(new GenericMessage<String>("test2"), 0);
assertEquals(2, invokedCounter.get());
assertEquals(1, sentCounter.get());
assertNotNull(singleItemChannel.removeInterceptor(0));
singleItemChannel.send(new GenericMessage<String>("test2"), 0);
assertEquals(2, invokedCounter.get());
assertEquals(1, sentCounter.get());
}
@Test
@@ -164,8 +176,9 @@ public class ChannelInterceptorTests {
assertEquals(1, messageCount.get());
}
@Test
public void testInterceptorBeanWithPnamespace(){
ApplicationContext ac = new ClassPathXmlApplicationContext("ChannelInterceptorTests-context.xml", ChannelInterceptorTests.class);
public void testInterceptorBeanWithPNamespace(){
ConfigurableApplicationContext ac =
new ClassPathXmlApplicationContext("ChannelInterceptorTests-context.xml", ChannelInterceptorTests.class);
ChannelInterceptorAware channel = ac.getBean("input", AbstractMessageChannel.class);
List<ChannelInterceptor> interceptors = channel.getChannelInterceptors();
ChannelInterceptor channelInterceptor = interceptors.get(0);
@@ -173,6 +186,7 @@ public class ChannelInterceptorTests {
String foo = ((PreSendReturnsMessageInterceptor) channelInterceptor).getFoo();
assertTrue(StringUtils.hasText(foo));
assertEquals("foo", foo);
ac.close();
}