Skip to content

Commit 4742aa0

Browse files
committed
Test @JmsListener as a merged composed annotation
Issue: SPR-13973
1 parent 2353f39 commit 4742aa0

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

spring-jms/src/test/java/org/springframework/jms/annotation/EnableJmsTests.java

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,14 @@
1616

1717
package org.springframework.jms.annotation;
1818

19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
1922
import javax.jms.JMSException;
2023
import javax.jms.MessageListener;
2124

2225
import org.hamcrest.core.Is;
26+
2327
import org.junit.Rule;
2428
import org.junit.Test;
2529
import org.junit.rules.ExpectedException;
@@ -32,10 +36,12 @@
3236
import org.springframework.context.annotation.Lazy;
3337
import org.springframework.context.annotation.PropertySource;
3438
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
39+
import org.springframework.core.annotation.AliasFor;
3540
import org.springframework.jms.config.JmsListenerContainerTestFactory;
3641
import org.springframework.jms.config.JmsListenerEndpointRegistrar;
3742
import org.springframework.jms.config.JmsListenerEndpointRegistry;
3843
import org.springframework.jms.config.MessageListenerTestContainer;
44+
import org.springframework.jms.config.MethodJmsListenerEndpoint;
3945
import org.springframework.jms.config.SimpleJmsListenerEndpoint;
4046
import org.springframework.jms.listener.adapter.ListenerExecutionFailedException;
4147
import org.springframework.jms.listener.adapter.MessageListenerAdapter;
@@ -48,6 +54,7 @@
4854

4955
/**
5056
* @author Stephane Nicoll
57+
* @author Sam Brannen
5158
*/
5259
public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
5360

@@ -130,11 +137,33 @@ public void jmsListeners() {
130137
}
131138

132139
@Test
140+
public void composedJmsListeners() {
141+
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
142+
EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
143+
JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory",
144+
JmsListenerContainerTestFactory.class);
145+
assertEquals(2, simpleFactory.getListenerContainers().size());
146+
147+
MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
148+
"first").getEndpoint();
149+
assertEquals("first", first.getId());
150+
assertEquals("orderQueue", first.getDestination());
151+
assertNull(first.getConcurrency());
152+
153+
MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
154+
"second").getEndpoint();
155+
assertEquals("second", second.getId());
156+
assertEquals("billingQueue", second.getDestination());
157+
assertEquals("2-10", second.getConcurrency());
158+
}
159+
}
160+
161+
@Test
162+
@SuppressWarnings("resource")
133163
public void unknownFactory() {
134164
thrown.expect(BeanCreationException.class);
135165
thrown.expectMessage("customFactory"); // Not found
136-
new AnnotationConfigApplicationContext(
137-
EnableJmsSampleConfig.class, CustomBean.class);
166+
new AnnotationConfigApplicationContext(EnableJmsSampleConfig.class, CustomBean.class);
138167
}
139168

140169
@Test
@@ -295,4 +324,36 @@ public void handle(String msg) {
295324
}
296325
}
297326

327+
328+
@JmsListener(destination = "orderQueue")
329+
@Retention(RetentionPolicy.RUNTIME)
330+
private @interface OrderQueueListener {
331+
332+
@AliasFor(annotation = JmsListener.class)
333+
String id() default "";
334+
335+
@AliasFor(annotation = JmsListener.class)
336+
String concurrency() default "";
337+
}
338+
339+
@JmsListener(destination = "billingQueue")
340+
@Retention(RetentionPolicy.RUNTIME)
341+
private @interface BillingQueueListener {
342+
343+
@AliasFor(annotation = JmsListener.class)
344+
String id() default "";
345+
346+
@AliasFor(annotation = JmsListener.class)
347+
String concurrency() default "";
348+
}
349+
350+
@Component
351+
static class ComposedJmsListenersBean {
352+
353+
@OrderQueueListener(id = "first")
354+
@BillingQueueListener(id = "second", concurrency = "2-10")
355+
public void repeatableHandle(String msg) {
356+
}
357+
}
358+
298359
}

0 commit comments

Comments
 (0)