INT-2439 PollerParser adviceChain.add(customBean)

Fix PollerParser#configureAdviceChain for adding 'customBeanDefinition' into 'adviceChain' List.
PollerParserTests: adding <tx:advice> as customElement into poller's <advice-chain>.
This commit is contained in:
Artem Bilan
2012-02-16 15:33:44 +02:00
committed by Gary Russell
parent a3df39ea28
commit 37c7e3c2c6
3 changed files with 35 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 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.
@@ -45,6 +45,7 @@ import org.springframework.util.xml.DomUtils;
* @author Mark Fisher
* @author Marius Bogoevici
* @author Oleg Zhurakousky
* @author Artem Bilan
*/
public class PollerParser extends AbstractBeanDefinitionParser {
@@ -273,6 +274,7 @@ public class PollerParser extends AbstractBeanDefinitionParser {
parserContext.getReaderContext().error(
"failed to parse custom element '" + localName + "'", childElement);
}
adviceChain.add(customBeanDefinition);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 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.
@@ -19,11 +19,15 @@ package org.springframework.integration.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertSame;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.aopalliance.aop.Advice;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -32,10 +36,14 @@ import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.scheduling.PollerMetadata;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.scheduling.support.PeriodicTrigger;
import org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource;
import org.springframework.transaction.interceptor.TransactionAttributeSource;
import org.springframework.transaction.interceptor.TransactionInterceptor;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Artem Bilan
*/
public class PollerParserTests {
@@ -78,11 +86,19 @@ public class PollerParserTests {
assertNotNull(poller);
PollerMetadata metadata = (PollerMetadata) poller;
assertNotNull(metadata.getAdviceChain());
assertEquals(3, metadata.getAdviceChain().size());
assertEquals(context.getBean("adviceBean1"), metadata.getAdviceChain().get(0));
assertEquals(4, metadata.getAdviceChain().size());
assertSame(context.getBean("adviceBean1"), metadata.getAdviceChain().get(0));
assertEquals(TestAdviceBean.class, metadata.getAdviceChain().get(1).getClass());
assertEquals(2, ((TestAdviceBean) metadata.getAdviceChain().get(1)).getId());
assertEquals(context.getBean("adviceBean3"), metadata.getAdviceChain().get(2));
assertSame(context.getBean("adviceBean3"), metadata.getAdviceChain().get(2));
Advice txAdvice = metadata.getAdviceChain().get(3);
assertEquals(TransactionInterceptor.class, txAdvice.getClass());
TransactionAttributeSource transactionAttributeSource = ((TransactionInterceptor) txAdvice).getTransactionAttributeSource();
assertEquals(NameMatchTransactionAttributeSource.class, transactionAttributeSource.getClass());
HashMap nameMap = TestUtils.getPropertyValue(transactionAttributeSource, "nameMap", HashMap.class);
assertEquals(1, nameMap.size());
assertEquals("{*=PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly}", nameMap.toString());
}
@Test

View File

@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<beans:bean id="transactionManager" class="org.springframework.integration.util.TestTransactionManager"/>
<poller id="poller">
<interval-trigger interval="5000"/>
@@ -15,6 +19,11 @@
<beans:constructor-arg value="2"/>
</beans:bean>
<ref bean="adviceBean3"/>
<tx:advice>
<tx:attributes>
<tx:method name="*" read-only="true" propagation="REQUIRES_NEW"/>
</tx:attributes>
</tx:advice>
</advice-chain>
</poller>