JmsListener/ScheduledAnnotationBeanPostProcessor uses SmartInitializingSingleton instead of ContextRefreshedEvent
Also reducing the container dependencies to BeanFactory instead of ApplicationContext, wherever possible. Issue: SPR-12039
This commit is contained in:
@@ -40,6 +40,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class JmsListenerAnnotationBeanPostProcessorTests {
|
||||
|
||||
@@ -62,9 +63,7 @@ public class JmsListenerAnnotationBeanPostProcessorTests {
|
||||
methodEndpoint.setupListenerContainer(listenerContainer);
|
||||
assertNotNull(listenerContainer.getMessageListener());
|
||||
|
||||
context.start();
|
||||
assertTrue("Should have been started " + container, container.isStarted());
|
||||
|
||||
context.close(); // Close and stop the listeners
|
||||
assertTrue("Should have been stopped " + container, container.isStopped());
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.jms.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -31,7 +29,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
@@ -44,8 +42,9 @@ import org.springframework.messaging.handler.invocation.InvocableHandlerMethod;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class DefaultJmsHandlerMethodFactoryTests {
|
||||
@@ -160,15 +159,13 @@ public class DefaultJmsHandlerMethodFactoryTests {
|
||||
|
||||
private DefaultJmsHandlerMethodFactory createInstance() {
|
||||
DefaultJmsHandlerMethodFactory factory = new DefaultJmsHandlerMethodFactory();
|
||||
factory.setApplicationContext(new StaticApplicationContext());
|
||||
factory.setBeanFactory(new StaticListableBeanFactory());
|
||||
return factory;
|
||||
}
|
||||
|
||||
private Method getListenerMethod(String methodName, Class<?>... parameterTypes) {
|
||||
Method method = ReflectionUtils.findMethod(SampleBean.class,
|
||||
methodName, parameterTypes);
|
||||
assertNotNull("no method found with name " + methodName
|
||||
+ " and parameters " + Arrays.toString(parameterTypes));
|
||||
Method method = ReflectionUtils.findMethod(SampleBean.class, methodName, parameterTypes);
|
||||
assertNotNull("no method found with name " + methodName + " and parameters " + Arrays.toString(parameterTypes));
|
||||
return method;
|
||||
}
|
||||
|
||||
@@ -187,6 +184,7 @@ public class DefaultJmsHandlerMethodFactoryTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class CustomHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,14 +16,10 @@
|
||||
|
||||
package org.springframework.jms.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageListener;
|
||||
@@ -33,7 +29,7 @@ import javax.jms.TextMessage;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||
import org.springframework.jms.StubTextMessage;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
import org.springframework.jms.listener.SessionAwareMessageListener;
|
||||
@@ -42,8 +38,10 @@ import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JmsListenerContainerFactoryIntegrationTests {
|
||||
@@ -54,6 +52,7 @@ public class JmsListenerContainerFactoryIntegrationTests {
|
||||
|
||||
private final JmsEndpointSampleBean sample = new JmsEndpointSampleBean();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
initializeFactory(factory);
|
||||
@@ -70,16 +69,6 @@ public class JmsListenerContainerFactoryIntegrationTests {
|
||||
assertListenerMethodInvocation("expectFooBarUpperCase");
|
||||
}
|
||||
|
||||
static class JmsEndpointSampleBean {
|
||||
|
||||
private final Map<String, Boolean> invocations = new HashMap<String, Boolean>();
|
||||
|
||||
public void expectFooBarUpperCase(@Payload String msg) {
|
||||
invocations.put("expectFooBarUpperCase", true);
|
||||
assertEquals("Unexpected payload message", "FOO-BAR", msg);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void invokeListener(JmsListenerEndpoint endpoint, Message message) throws JMSException {
|
||||
DefaultMessageListenerContainer messageListenerContainer =
|
||||
@@ -112,21 +101,31 @@ public class JmsListenerContainerFactoryIntegrationTests {
|
||||
}
|
||||
|
||||
private Method getListenerMethod(String methodName, Class<?>... parameterTypes) {
|
||||
Method method = ReflectionUtils.findMethod(JmsEndpointSampleBean.class,
|
||||
methodName, parameterTypes);
|
||||
assertNotNull("no method found with name " + methodName
|
||||
+ " and parameters " + Arrays.toString(parameterTypes));
|
||||
Method method = ReflectionUtils.findMethod(JmsEndpointSampleBean.class, methodName, parameterTypes);
|
||||
assertNotNull("no method found with name " + methodName + " and parameters " + Arrays.toString(parameterTypes));
|
||||
return method;
|
||||
}
|
||||
|
||||
|
||||
private void initializeFactory(DefaultJmsHandlerMethodFactory factory) {
|
||||
factory.setApplicationContext(new StaticApplicationContext());
|
||||
factory.setBeanFactory(new StaticListableBeanFactory());
|
||||
factory.afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
static class JmsEndpointSampleBean {
|
||||
|
||||
private final Map<String, Boolean> invocations = new HashMap<String, Boolean>();
|
||||
|
||||
public void expectFooBarUpperCase(@Payload String msg) {
|
||||
invocations.put("expectFooBarUpperCase", true);
|
||||
assertEquals("Unexpected payload message", "FOO-BAR", msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class UpperCaseMessageConverter implements MessageConverter {
|
||||
|
||||
@Override
|
||||
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
|
||||
return new StubTextMessage(object.toString().toUpperCase());
|
||||
@@ -138,6 +137,5 @@ public class JmsListenerContainerFactoryIntegrationTests {
|
||||
return content.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,17 +16,16 @@
|
||||
|
||||
package org.springframework.jms.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JmsListenerEndpointRegistrarTests {
|
||||
@@ -40,10 +39,11 @@ public class JmsListenerEndpointRegistrarTests {
|
||||
|
||||
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
registrar.setEndpointRegistry(registry);
|
||||
registrar.setApplicationContext(new StaticApplicationContext());
|
||||
registrar.setBeanFactory(new StaticListableBeanFactory());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,16 +16,11 @@
|
||||
|
||||
package org.springframework.jms.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.InvalidDestinationException;
|
||||
import javax.jms.JMSException;
|
||||
@@ -41,16 +36,16 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||
import org.springframework.jms.StubTextMessage;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
import org.springframework.jms.listener.MessageListenerContainer;
|
||||
import org.springframework.jms.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.jms.listener.adapter.ReplyFailureException;
|
||||
import org.springframework.jms.listener.adapter.ListenerExecutionFailedException;
|
||||
import org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter;
|
||||
import org.springframework.jms.support.JmsMessageHeaderAccessor;
|
||||
import org.springframework.jms.listener.adapter.ReplyFailureException;
|
||||
import org.springframework.jms.support.JmsHeaders;
|
||||
import org.springframework.jms.support.JmsMessageHeaderAccessor;
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
@@ -65,8 +60,12 @@ import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class MethodJmsListenerEndpointTests {
|
||||
@@ -83,6 +82,7 @@ public class MethodJmsListenerEndpointTests {
|
||||
|
||||
private final JmsEndpointSampleBean sample = new JmsEndpointSampleBean();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
initializeFactory(factory);
|
||||
@@ -375,10 +375,8 @@ public class MethodJmsListenerEndpointTests {
|
||||
}
|
||||
|
||||
private Method getListenerMethod(String methodName, Class<?>... parameterTypes) {
|
||||
Method method = ReflectionUtils.findMethod(JmsEndpointSampleBean.class,
|
||||
methodName, parameterTypes);
|
||||
assertNotNull("no method found with name " + methodName
|
||||
+ " and parameters " + Arrays.toString(parameterTypes));
|
||||
Method method = ReflectionUtils.findMethod(JmsEndpointSampleBean.class, methodName, parameterTypes);
|
||||
assertNotNull("no method found with name " + methodName + " and parameters " + Arrays.toString(parameterTypes));
|
||||
return method;
|
||||
}
|
||||
|
||||
@@ -395,12 +393,11 @@ public class MethodJmsListenerEndpointTests {
|
||||
}
|
||||
|
||||
private void initializeFactory(DefaultJmsHandlerMethodFactory factory) {
|
||||
factory.setApplicationContext(new StaticApplicationContext());
|
||||
factory.setBeanFactory(new StaticListableBeanFactory());
|
||||
factory.afterPropertiesSet();
|
||||
}
|
||||
|
||||
private Validator testValidator(final String invalidValue) {
|
||||
|
||||
return new Validator() {
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
@@ -520,11 +517,11 @@ public class MethodJmsListenerEndpointTests {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
static class MyBean implements Serializable {
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import javax.jms.TextMessage;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||
import org.springframework.jms.StubTextMessage;
|
||||
import org.springframework.jms.config.DefaultJmsHandlerMethodFactory;
|
||||
import org.springframework.jms.support.JmsHeaders;
|
||||
@@ -38,7 +38,6 @@ import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class MessagingMessageListenerAdapterTests {
|
||||
@@ -124,7 +123,7 @@ public class MessagingMessageListenerAdapterTests {
|
||||
}
|
||||
|
||||
private void initializeFactory(DefaultJmsHandlerMethodFactory factory) {
|
||||
factory.setApplicationContext(new StaticApplicationContext());
|
||||
factory.setBeanFactory(new StaticListableBeanFactory());
|
||||
factory.afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user