From 69bc8d602a1053ee4a56affea57ae0d9aed4569f Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Sun, 30 Mar 2014 16:31:34 +0300 Subject: [PATCH] Add `@GlobalChannelInterceptor` test --- ...slIntegrationConfigurationInitializer.java | 2 +- .../dsl/test/IntegrationFlowTests.java | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/spring-integration-java-dsl/src/main/java/org/springframework/integration/dsl/core/DslIntegrationConfigurationInitializer.java b/spring-integration-java-dsl/src/main/java/org/springframework/integration/dsl/core/DslIntegrationConfigurationInitializer.java index 21e6335..1a3e693 100644 --- a/spring-integration-java-dsl/src/main/java/org/springframework/integration/dsl/core/DslIntegrationConfigurationInitializer.java +++ b/spring-integration-java-dsl/src/main/java/org/springframework/integration/dsl/core/DslIntegrationConfigurationInitializer.java @@ -62,7 +62,7 @@ public class DslIntegrationConfigurationInitializer implements IntegrationConfig } private void checkSpecBeans(ConfigurableListableBeanFactory beanFactory) { - List specBeanNames = Arrays.asList(beanFactory.getBeanNamesForType(IntegrationComponentSpec.class, false, false)); + List specBeanNames = Arrays.asList(beanFactory.getBeanNamesForType(IntegrationComponentSpec.class, true, false)); if (!specBeanNames.isEmpty()) { throw new BeanCreationException("'IntegrationComponentSpec' beans: '" + specBeanNames + "' must be populated " + "to target objects via 'get()' method call. It is important for @Autowired injections."); diff --git a/spring-integration-java-dsl/src/test/java/org/springframework/integration/dsl/test/IntegrationFlowTests.java b/spring-integration-java-dsl/src/test/java/org/springframework/integration/dsl/test/IntegrationFlowTests.java index 80a1735..846abf0 100644 --- a/spring-integration-java-dsl/src/test/java/org/springframework/integration/dsl/test/IntegrationFlowTests.java +++ b/spring-integration-java-dsl/src/test/java/org/springframework/integration/dsl/test/IntegrationFlowTests.java @@ -62,11 +62,13 @@ import org.springframework.integration.annotation.IntegrationComponentScan; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.MessagingGateway; import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.integration.channel.AbstractPollableChannel; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.FixedSubscriberChannel; import org.springframework.integration.channel.PublishSubscribeChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; +import org.springframework.integration.config.GlobalChannelInterceptor; import org.springframework.integration.core.MessageSource; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.IntegrationFlows; @@ -101,6 +103,7 @@ import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessagingException; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.core.DestinationResolutionException; +import org.springframework.messaging.support.ChannelInterceptorAdapter; import org.springframework.messaging.support.GenericMessage; import org.springframework.stereotype.Component; import org.springframework.test.context.ContextConfiguration; @@ -123,7 +126,10 @@ public class IntegrationFlowTests { @Autowired @Qualifier("flow1QueueChannel") - private PollableChannel outputChannel; + private AbstractPollableChannel outputChannel; + + @Autowired + private TestChannelInterceptor testChannelInterceptor; @Autowired @Qualifier("inputChannel") @@ -251,6 +257,9 @@ public class IntegrationFlowTests { assertNotNull(message); assertEquals("" + i, message.getPayload()); } + + assertTrue(this.outputChannel.getChannelInterceptors().contains(this.testChannelInterceptor)); + assertEquals(new Integer(10), this.testChannelInterceptor.getInvoked()); } @Test @@ -1094,6 +1103,24 @@ public class IntegrationFlowTests { } + @Component + @GlobalChannelInterceptor(patterns = "flow1QueueChannel") + public static class TestChannelInterceptor extends ChannelInterceptorAdapter { + + private final AtomicInteger invoked = new AtomicInteger(); + + @Override + public Message preSend(Message message, MessageChannel channel) { + this.invoked.incrementAndGet(); + return message; + } + + public Integer getInvoked() { + return invoked.get(); + } + + } + private static class TestPojo { private String name;