diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java index 06c4517054..7bdc6e9f87 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java @@ -127,6 +127,7 @@ public class SourcePollingChannelAdapterFactoryBean implements FactoryBean, Bean spca.setTaskExecutor(this.pollerMetadata.getTaskExecutor()); spca.setTransactionManager(this.pollerMetadata.getTransactionManager()); spca.setTransactionDefinition(this.pollerMetadata.getTransactionDefinition()); + spca.setAdviceChain(this.pollerMetadata.getAdviceChain()); spca.setAutoStartup(this.autoStartup); spca.setBeanName(this.beanName); spca.setBeanFactory(this.beanFactory); diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java new file mode 100644 index 0000000000..e4e505a196 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java @@ -0,0 +1,85 @@ +/* + * Copyright 2002-2008 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.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.aopalliance.aop.Advice; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; + +import org.junit.Test; + +import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.core.Message; +import org.springframework.integration.message.MessageSource; +import org.springframework.integration.message.StringMessage; +import org.springframework.integration.scheduling.IntervalTrigger; +import org.springframework.integration.scheduling.PollerMetadata; +import org.springframework.integration.util.TestUtils; +import org.springframework.integration.util.TestUtils.TestApplicationContext; +import org.springframework.util.ClassUtils; + +/** + * @author Mark Fisher + */ +public class SourcePollingChannelAdapterFactoryBeanTests { + + @Test + public void testAdviceChain() throws Exception { + SourcePollingChannelAdapterFactoryBean factoryBean = new SourcePollingChannelAdapterFactoryBean(); + QueueChannel outputChannel = new QueueChannel(); + TestApplicationContext context = TestUtils.createTestApplicationContext(); + factoryBean.setBeanFactory(context.getBeanFactory()); + factoryBean.setBeanClassLoader(ClassUtils.getDefaultClassLoader()); + factoryBean.setOutputChannel(outputChannel); + factoryBean.setSource(new TestSource()); + PollerMetadata pollerMetadata = new PollerMetadata(); + List adviceChain = new ArrayList(); + final AtomicBoolean adviceApplied = new AtomicBoolean(false); + adviceChain.add(new MethodInterceptor() { + public Object invoke(MethodInvocation invocation) throws Throwable { + adviceApplied.set(true); + return invocation.proceed(); + } + }); + pollerMetadata.setTrigger(new IntervalTrigger(5000)); + pollerMetadata.setMaxMessagesPerPoll(1); + pollerMetadata.setAdviceChain(adviceChain); + factoryBean.setPollerMetadata(pollerMetadata); + factoryBean.setAutoStartup(true); + factoryBean.afterPropertiesSet(); + context.refresh(); + Message message = outputChannel.receive(30000); + assertEquals("test", message.getPayload()); + assertTrue("adviceChain was not applied", adviceApplied.get()); + } + + + private static class TestSource implements MessageSource { + + public Message receive() { + return new StringMessage("test"); + } + } + +}