Polishing
This commit is contained in:
@@ -52,6 +52,7 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public abstract void sampleConfiguration();
|
||||
|
||||
@@ -79,6 +80,7 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
@Test
|
||||
public abstract void jmsListeners();
|
||||
|
||||
|
||||
/**
|
||||
* Test for {@link SampleBean} discovery. If a factory with the default name
|
||||
* is set, an endpoint will use it automatically
|
||||
@@ -92,18 +94,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
assertEquals(1, simpleFactory.getListenerContainers().size());
|
||||
}
|
||||
|
||||
@Component
|
||||
static class SampleBean {
|
||||
|
||||
@JmsListener(destination = "myQueue")
|
||||
public void defaultHandle(String msg) {
|
||||
}
|
||||
|
||||
@JmsListener(containerFactory = "simpleFactory", destination = "myQueue")
|
||||
public void simpleHandle(String msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link FullBean} discovery. In this case, no default is set because
|
||||
* all endpoints provide a default registry. This shows that the default factory
|
||||
@@ -127,29 +117,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
assertEquals("queueOut", destination);
|
||||
}
|
||||
|
||||
@Component
|
||||
static class FullBean {
|
||||
|
||||
@JmsListener(id = "listener1", containerFactory = "simpleFactory", destination = "queueIn",
|
||||
selector = "mySelector", subscription = "mySubscription", concurrency = "1-10")
|
||||
@SendTo("queueOut")
|
||||
public String fullHandle(String msg) {
|
||||
return "reply";
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
static class FullConfigurableBean {
|
||||
|
||||
@JmsListener(id = "${jms.listener.id}", containerFactory = "${jms.listener.containerFactory}",
|
||||
destination = "${jms.listener.destination}", selector = "${jms.listener.selector}",
|
||||
subscription = "${jms.listener.subscription}", concurrency = "${jms.listener.concurrency}")
|
||||
@SendTo("${jms.listener.sendTo}")
|
||||
public String fullHandle(String msg) {
|
||||
return "reply";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link CustomBean} and an manually endpoint registered
|
||||
* with "myCustomEndpointId". The custom endpoint does not provide
|
||||
@@ -179,14 +146,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
customRegistry.getListenerContainer("myCustomEndpointId"));
|
||||
}
|
||||
|
||||
@Component
|
||||
static class CustomBean {
|
||||
|
||||
@JmsListener(id = "listenerId", containerFactory = "customFactory", destination = "myQueue")
|
||||
public void customHandle(String msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link DefaultBean} that does not define the container
|
||||
* factory to use as a default is registered with an explicit
|
||||
@@ -208,13 +167,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
assertEquals(1, defaultFactory.getListenerContainers().size());
|
||||
}
|
||||
|
||||
static class DefaultBean {
|
||||
|
||||
@JmsListener(destination = "myQueue")
|
||||
public void handleIt(String msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
|
||||
* in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
|
||||
@@ -234,14 +186,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
|
||||
}
|
||||
|
||||
@Component
|
||||
static class ValidationBean {
|
||||
|
||||
@JmsListener(containerFactory = "defaultFactory", destination = "myQueue")
|
||||
public void defaultHandle(@Validated String msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link JmsListenerRepeatableBean} and {@link JmsListenersBean} that validates that the
|
||||
* {@code @JmsListener} annotation is repeatable and generate one specific container per annotation.
|
||||
@@ -264,6 +208,71 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
assertEquals("2-10", second.getConcurrency());
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
static class SampleBean {
|
||||
|
||||
@JmsListener(destination = "myQueue")
|
||||
public void defaultHandle(String msg) {
|
||||
}
|
||||
|
||||
@JmsListener(containerFactory = "simpleFactory", destination = "myQueue")
|
||||
public void simpleHandle(String msg) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
static class FullBean {
|
||||
|
||||
@JmsListener(id = "listener1", containerFactory = "simpleFactory", destination = "queueIn",
|
||||
selector = "mySelector", subscription = "mySubscription", concurrency = "1-10")
|
||||
@SendTo("queueOut")
|
||||
public String fullHandle(String msg) {
|
||||
return "reply";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
static class FullConfigurableBean {
|
||||
|
||||
@JmsListener(id = "${jms.listener.id}", containerFactory = "${jms.listener.containerFactory}",
|
||||
destination = "${jms.listener.destination}", selector = "${jms.listener.selector}",
|
||||
subscription = "${jms.listener.subscription}", concurrency = "${jms.listener.concurrency}")
|
||||
@SendTo("${jms.listener.sendTo}")
|
||||
public String fullHandle(String msg) {
|
||||
return "reply";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
static class CustomBean {
|
||||
|
||||
@JmsListener(id = "listenerId", containerFactory = "customFactory", destination = "myQueue")
|
||||
public void customHandle(String msg) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class DefaultBean {
|
||||
|
||||
@JmsListener(destination = "myQueue")
|
||||
public void handleIt(String msg) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
static class ValidationBean {
|
||||
|
||||
@JmsListener(containerFactory = "defaultFactory", destination = "myQueue")
|
||||
public void defaultHandle(@Validated String msg) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
static class JmsListenerRepeatableBean {
|
||||
|
||||
@@ -271,9 +280,9 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
@JmsListener(id = "second", destination = "anotherQueue", concurrency = "2-10")
|
||||
public void repeatableHandle(String msg) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
static class JmsListenersBean {
|
||||
|
||||
@@ -283,9 +292,9 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
})
|
||||
public void repeatableHandle(String msg) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class TestValidator implements Validator {
|
||||
|
||||
@Override
|
||||
@@ -301,4 +310,5 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.jms.listener.adapter.ListenerExecutionFailedException
|
||||
import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenTests {
|
||||
@@ -75,6 +74,7 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void defaultContainerFactory() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"annotation-driven-default-container-factory.xml", getClass());
|
||||
@@ -82,6 +82,7 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"annotation-driven-custom-handler-method-factory.xml", getClass());
|
||||
@@ -92,6 +93,7 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void jmsListenerIsRepeatable() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"annotation-driven-jms-listener-repeatable.xml", getClass());
|
||||
@@ -99,12 +101,14 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void jmsListeners() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"annotation-driven-jms-listeners.xml", getClass());
|
||||
testJmsListenerRepeatable(context);
|
||||
}
|
||||
|
||||
|
||||
static class CustomJmsListenerConfigurer implements JmsListenerConfigurer {
|
||||
|
||||
private MessageListener messageListener;
|
||||
@@ -121,6 +125,6 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||
public void setMessageListener(MessageListener messageListener) {
|
||||
this.messageListener = messageListener;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void sampleConfiguration() {
|
||||
@@ -113,6 +114,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void jmsListenerIsRepeatable() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
EnableJmsDefaultContainerFactoryConfig.class, JmsListenerRepeatableBean.class);
|
||||
@@ -120,6 +122,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void jmsListeners() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
EnableJmsDefaultContainerFactoryConfig.class, JmsListenersBean.class);
|
||||
@@ -150,6 +153,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
assertTrue("Should have been stopped " + container, container.isStopped());
|
||||
}
|
||||
|
||||
|
||||
@EnableJms
|
||||
@Configuration
|
||||
static class EnableJmsSampleConfig {
|
||||
@@ -165,6 +169,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EnableJms
|
||||
@Configuration
|
||||
static class EnableJmsFullConfig {
|
||||
@@ -175,6 +180,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EnableJms
|
||||
@Configuration
|
||||
@PropertySource("classpath:/org/springframework/jms/annotation/jms-listener.properties")
|
||||
@@ -191,6 +197,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableJms
|
||||
static class EnableJmsCustomConfig implements JmsListenerConfigurer {
|
||||
@@ -228,6 +235,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableJms
|
||||
static class EnableJmsCustomContainerFactoryConfig implements JmsListenerConfigurer {
|
||||
@@ -243,6 +251,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableJms
|
||||
static class EnableJmsDefaultContainerFactoryConfig {
|
||||
@@ -253,6 +262,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableJms
|
||||
static class EnableJmsHandlerMethodFactoryConfig implements JmsListenerConfigurer {
|
||||
@@ -275,6 +285,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
@Lazy
|
||||
static class LazyBean {
|
||||
|
||||
@@ -49,9 +49,6 @@ import static org.mockito.Mockito.*;
|
||||
*/
|
||||
public class JmsListenerContainerFactoryTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final ConnectionFactory connectionFactory = new StubConnectionFactory();
|
||||
|
||||
private final DestinationResolver destinationResolver = new DynamicDestinationResolver();
|
||||
@@ -61,6 +58,10 @@ public class JmsListenerContainerFactoryTests {
|
||||
private final TransactionManager transactionManager = mock(TransactionManager.class);
|
||||
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void createSimpleContainer() {
|
||||
SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
|
||||
@@ -148,6 +149,7 @@ public class JmsListenerContainerFactoryTests {
|
||||
assertSame(backOff, new DirectFieldAccessor(container).getPropertyValue("backOff"));
|
||||
}
|
||||
|
||||
|
||||
private void setDefaultJmsConfig(AbstractJmsListenerContainerFactory<?> factory) {
|
||||
factory.setConnectionFactory(connectionFactory);
|
||||
factory.setDestinationResolver(destinationResolver);
|
||||
|
||||
@@ -30,9 +30,6 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class JmsListenerEndpointRegistrarTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final JmsListenerEndpointRegistrar registrar = new JmsListenerEndpointRegistrar();
|
||||
|
||||
private final JmsListenerEndpointRegistry registry = new JmsListenerEndpointRegistry();
|
||||
@@ -40,12 +37,17 @@ public class JmsListenerEndpointRegistrarTests {
|
||||
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
|
||||
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
registrar.setEndpointRegistry(registry);
|
||||
registrar.setBeanFactory(new StaticListableBeanFactory());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void registerNullEndpoint() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -21,18 +21,19 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JmsListenerEndpointRegistryTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final JmsListenerEndpointRegistry registry = new JmsListenerEndpointRegistry();
|
||||
|
||||
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
|
||||
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void createWithNullEndpoint() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
@@ -59,6 +60,7 @@ public class JmsListenerEndpointRegistryTests {
|
||||
registry.registerListenerContainer(createEndpoint("test", "queue"), containerFactory);
|
||||
}
|
||||
|
||||
|
||||
private SimpleJmsListenerEndpoint createEndpoint(String id, String destinationName) {
|
||||
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
||||
endpoint.setId(id);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -41,6 +41,7 @@ public class JmsListenerEndpointTests {
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void setupJmsMessageContainerFullConfig() {
|
||||
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
|
||||
@@ -112,5 +113,4 @@ public class JmsListenerEndpointTests {
|
||||
endpoint.setupListenerContainer(container);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -71,12 +71,6 @@ import static org.mockito.BDDMockito.*;
|
||||
*/
|
||||
public class MethodJmsListenerEndpointTests {
|
||||
|
||||
@Rule
|
||||
public final TestName name = new TestName();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
|
||||
|
||||
private final DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
|
||||
@@ -84,11 +78,19 @@ public class MethodJmsListenerEndpointTests {
|
||||
private final JmsEndpointSampleBean sample = new JmsEndpointSampleBean();
|
||||
|
||||
|
||||
@Rule
|
||||
public final TestName name = new TestName();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
initializeFactory(factory);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void createMessageListenerNoFactory() {
|
||||
MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint();
|
||||
@@ -401,8 +403,10 @@ public class MethodJmsListenerEndpointTests {
|
||||
listener.onMessage(createSimpleJmsTextMessage("test"), session); // Message<String> as Message<Integer>
|
||||
}
|
||||
|
||||
|
||||
private MessagingMessageListenerAdapter createInstance(
|
||||
DefaultMessageHandlerMethodFactory factory, Method method, MessageListenerContainer container) {
|
||||
|
||||
MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint();
|
||||
endpoint.setBean(sample);
|
||||
endpoint.setMethod(method);
|
||||
@@ -410,8 +414,7 @@ public class MethodJmsListenerEndpointTests {
|
||||
return endpoint.createMessageListener(container);
|
||||
}
|
||||
|
||||
private MessagingMessageListenerAdapter createInstance(
|
||||
DefaultMessageHandlerMethodFactory factory, Method method) {
|
||||
private MessagingMessageListenerAdapter createInstance(DefaultMessageHandlerMethodFactory factory, Method method) {
|
||||
return createInstance(factory, method, new SimpleMessageListenerContainer());
|
||||
}
|
||||
|
||||
@@ -575,8 +578,8 @@ public class MethodJmsListenerEndpointTests {
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
static class MyBean implements Serializable {
|
||||
private String name;
|
||||
|
||||
private String name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -26,13 +26,13 @@ import org.springframework.jms.listener.adapter.MessageListenerAdapter;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class SimpleJmsListenerEndpointTests {
|
||||
|
||||
private final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
|
||||
|
||||
|
||||
@Test
|
||||
public void createListener() {
|
||||
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
||||
@@ -40,4 +40,5 @@ public class SimpleJmsListenerEndpointTests {
|
||||
endpoint.setMessageListener(messageListener);
|
||||
assertSame(messageListener, endpoint.createMessageListener(container));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user