@Test public void testImplicit() { // used to fail to load AC (no channel 'bar') List<ChannelInterceptor> barInterceptors = bar.getChannelInterceptors(); assertEquals(2, barInterceptors.size()); assertThat(barInterceptors.get(0), anyOf(instanceOf(Interceptor1.class), instanceOf(Interceptor2.class))); assertThat(barInterceptors.get(1), anyOf(instanceOf(Interceptor1.class), instanceOf(Interceptor2.class))); List<ChannelInterceptor> fooInterceptors = foo.getChannelInterceptors(); assertEquals(2, fooInterceptors.size()); assertThat(fooInterceptors.get(0), anyOf(instanceOf(WireTap.class), instanceOf(Interceptor2.class))); assertThat(fooInterceptors.get(1), anyOf(instanceOf(WireTap.class), instanceOf(Interceptor2.class))); List<ChannelInterceptor> bazInterceptors = baz.getChannelInterceptors(); assertEquals(2, bazInterceptors.size()); assertThat(bazInterceptors.get(0), anyOf(instanceOf(WireTap.class), instanceOf(Interceptor1.class))); assertThat(bazInterceptors.get(1), anyOf(instanceOf(WireTap.class), instanceOf(Interceptor1.class))); }
@Test public void testParentChildAnnotationConfiguration() { AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.register(ChildConfiguration.class); child.setParent(this.context); child.refresh(); AbstractMessageChannel foo = child.getBean("foo", AbstractMessageChannel.class); ChannelInterceptor baz = child.getBean("baz", ChannelInterceptor.class); assertTrue(foo.getChannelInterceptors().contains(baz)); assertFalse(this.output.getChannelInterceptors().contains(baz)); child.close(); }
@Test public void testParentChildAnnotationConfigurationFromAnotherPackage() { AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.register(org.springframework.integration.configuration2.ChildConfiguration.class); child.setParent(this.context); child.refresh(); AbstractMessageChannel foo = child.getBean("foo", AbstractMessageChannel.class); ChannelInterceptor baz = child.getBean("baz", ChannelInterceptor.class); assertTrue(foo.getChannelInterceptors().contains(baz)); assertFalse(this.output.getChannelInterceptors().contains(baz)); child.close(); }
private void moveChannelInterceptors(AbstractMessageChannel existingMessageChannel, AbstractMessageChannel actualMessageChannel) { for (ChannelInterceptor channelInterceptor : existingMessageChannel.getChannelInterceptors()) { actualMessageChannel.addInterceptor(channelInterceptor); existingMessageChannel.removeInterceptor(channelInterceptor); } }