From 0570c2a447b62b79825a657f263aba4ecce69444 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 21 Mar 2013 11:09:33 -0400 Subject: [PATCH] AMQP-301 Remove Spring 3.1 Deprecations XmlBeanFactory is deprecated; replace with a DefaultListableBeanFactory loaded by an XmlBeanDefinitionReader. --- .../amqp/rabbit/config/AdminParserTests.java | 19 +++++++++++------- .../config/ConnectionFactoryParserTests.java | 11 ++++++---- .../rabbit/config/ExchangeParserTests.java | 11 ++++++---- .../config/ListenerContainerParserTests.java | 15 +++++++------- .../config/QueueParserIntegrationTests.java | 17 ++++++++++++---- .../amqp/rabbit/config/QueueParserTests.java | 20 +++++++++++++++---- .../config/RabbitNamespaceHandlerTests.java | 18 +++++++++++++---- .../rabbit/config/TemplateParserTests.java | 11 ++++++---- 8 files changed, 84 insertions(+), 38 deletions(-) diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/AdminParserTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/AdminParserTests.java index b98676df..080dc5b0 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/AdminParserTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/AdminParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2013 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 @@ -23,13 +23,15 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; -import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.ClassPathResource; import org.springframework.util.StringUtils; /** * * @author tomas.lukosius@opencredo.com + * @author Gary Russell * */ public final class AdminParserTests { @@ -65,7 +67,7 @@ public final class AdminParserTests { private void doTest() throws Exception { // Create context - XmlBeanFactory beanFactory = loadContext(); + DefaultListableBeanFactory beanFactory = loadContext(); if (beanFactory == null) { // Context was invalid return; @@ -91,15 +93,17 @@ public final class AdminParserTests { * Load application context. Fail if tests expects invalid spring-context, but spring-context is valid. * @return */ - private XmlBeanFactory loadContext() { - XmlBeanFactory beanFactory = null; + private DefaultListableBeanFactory loadContext() { + DefaultListableBeanFactory beanFactory = null; try { // Resource file name template: --context.xml ClassPathResource resource = new ClassPathResource(getClass().getSimpleName() + "-" + contextIndex + "-context.xml", getClass()); - beanFactory = new XmlBeanFactory(resource); + beanFactory = new DefaultListableBeanFactory(); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); + reader.loadBeanDefinitions(resource); if (!validContext) { - fail("Context " + resource + " suppose to fail"); + fail("Context " + resource + " failed to load"); } } catch (BeanDefinitionParsingException e) { if (validContext) { @@ -108,6 +112,7 @@ public final class AdminParserTests { } logger.warn("Failure was expected", e); + beanFactory = null; } return beanFactory; } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ConnectionFactoryParserTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ConnectionFactoryParserTests.java index 8e776576..a639a5b2 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ConnectionFactoryParserTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ConnectionFactoryParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2012 the original author or authors. + * Copyright 2010-2013 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 @@ -24,7 +24,8 @@ import org.junit.Before; import org.junit.Test; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.beans.DirectFieldAccessor; -import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.ClassPathResource; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @@ -38,11 +39,13 @@ import com.rabbitmq.client.Address; */ public final class ConnectionFactoryParserTests { - private XmlBeanFactory beanFactory; + private DefaultListableBeanFactory beanFactory; @Before public void setUpDefaultBeanFactory() throws Exception { - beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); + beanFactory = new DefaultListableBeanFactory(); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); + reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); } @Test diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ExchangeParserTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ExchangeParserTests.java index 59fb2140..b8ca0525 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ExchangeParserTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ExchangeParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -27,7 +27,8 @@ import org.springframework.amqp.core.DirectExchange; import org.springframework.amqp.core.FanoutExchange; import org.springframework.amqp.core.HeadersExchange; import org.springframework.amqp.core.TopicExchange; -import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.ClassPathResource; /** * @author Dave Syer @@ -38,11 +39,13 @@ import org.springframework.core.io.ClassPathResource; */ public final class ExchangeParserTests { - private XmlBeanFactory beanFactory; + private DefaultListableBeanFactory beanFactory; @Before public void setUp() throws Exception { - beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName()+"-context.xml", getClass())); + beanFactory = new DefaultListableBeanFactory(); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); + reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName()+"-context.xml", getClass())); } @Test diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ListenerContainerParserTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ListenerContainerParserTests.java index 91d9c5fa..4c60be06 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ListenerContainerParserTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/ListenerContainerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2012 the original author or authors. + * Copyright 2010-2013 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. @@ -35,10 +35,9 @@ import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter; import org.springframework.aop.MethodBeforeAdvice; import org.springframework.beans.DirectFieldAccessor; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; -import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.context.expression.StandardBeanExpressionResolver; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.ClassPathResource; @@ -50,12 +49,14 @@ import org.springframework.test.util.ReflectionTestUtils; */ public class ListenerContainerParserTests { - private BeanFactory beanFactory; + private DefaultListableBeanFactory beanFactory; @Before public void setUp() throws Exception { - beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); - ((ConfigurableBeanFactory)beanFactory).setBeanExpressionResolver(new StandardBeanExpressionResolver()); + beanFactory = new DefaultListableBeanFactory(); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); + reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); + beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver()); } @Test diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/QueueParserIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/QueueParserIntegrationTests.java index f6ac13d2..d054a265 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/QueueParserIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/QueueParserIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2013 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 @@ -25,19 +25,28 @@ import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.test.BrokerRunning; import org.springframework.amqp.rabbit.test.BrokerTestUtils; -import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.ClassPathResource; +/** + * @author Dave Syer + * @author Gary Russell + * @since 1.0 + * + */ public final class QueueParserIntegrationTests { @Rule public BrokerRunning brokerIsRunning = BrokerRunning.isRunning(); - private XmlBeanFactory beanFactory; + private DefaultListableBeanFactory beanFactory; @Before public void setUpDefaultBeanFactory() throws Exception { - beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); + beanFactory = new DefaultListableBeanFactory(); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); + reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); } @Test diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/QueueParserTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/QueueParserTests.java index 62f52414..2098b252 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/QueueParserTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/QueueParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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 @@ -25,16 +25,26 @@ import org.springframework.amqp.core.AnonymousQueue; import org.springframework.amqp.core.Queue; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.ClassPathResource; +/** + * @author Dave Syer + * @author Gary Russell + * @since 1.0 + * + */ public class QueueParserTests { protected BeanFactory beanFactory; @Before public void setUpDefaultBeanFactory() throws Exception { - beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); + DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); + reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); + this.beanFactory = beanFactory; } @Test @@ -111,7 +121,9 @@ public class QueueParserTests { @Test(expected=BeanDefinitionStoreException.class) public void testIllegalAnonymousQueue() throws Exception { - beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName() + DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); + reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "IllegalAnonymous-context.xml", getClass())); Queue queue = beanFactory.getBean("anonymous", Queue.class); assertNotNull(queue); diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/RabbitNamespaceHandlerTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/RabbitNamespaceHandlerTests.java index 16d035db..5d8f1fb0 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/RabbitNamespaceHandlerTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/RabbitNamespaceHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2013 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. @@ -33,16 +33,26 @@ import org.springframework.amqp.core.HeadersExchange; import org.springframework.amqp.core.Queue; import org.springframework.amqp.core.TopicExchange; import org.springframework.amqp.rabbit.core.RabbitAdmin; -import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.ClassPathResource; +/** + * @author Tomas Lukosius + * @author Dave Syer + * @author Gary Russell + * @since 1.0 + * + */ public final class RabbitNamespaceHandlerTests { - private XmlBeanFactory beanFactory; + private DefaultListableBeanFactory beanFactory; @Before public void setUp() throws Exception { - beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName()+"-context.xml", getClass())); + beanFactory = new DefaultListableBeanFactory(); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); + reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName()+"-context.xml", getClass())); } @Test diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/TemplateParserTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/TemplateParserTests.java index aee43e43..94ad8084 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/TemplateParserTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/config/TemplateParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2013 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 @@ -27,7 +27,8 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.support.converter.SerializerMessageConverter; import org.springframework.beans.DirectFieldAccessor; -import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.ClassPathResource; /** @@ -38,11 +39,13 @@ import org.springframework.core.io.ClassPathResource; */ public final class TemplateParserTests { - private XmlBeanFactory beanFactory; + private DefaultListableBeanFactory beanFactory; @Before public void setUpDefaultBeanFactory() throws Exception { - beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); + beanFactory = new DefaultListableBeanFactory(); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); + reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); } @Test