|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.jms.annotation;
|
18 | 18 |
|
| 19 | +import java.lang.annotation.Retention; |
| 20 | +import java.lang.annotation.RetentionPolicy; |
| 21 | + |
19 | 22 | import javax.jms.JMSException;
|
20 | 23 | import javax.jms.MessageListener;
|
21 | 24 |
|
22 | 25 | import org.hamcrest.core.Is;
|
| 26 | + |
23 | 27 | import org.junit.Rule;
|
24 | 28 | import org.junit.Test;
|
25 | 29 | import org.junit.rules.ExpectedException;
|
|
32 | 36 | import org.springframework.context.annotation.Lazy;
|
33 | 37 | import org.springframework.context.annotation.PropertySource;
|
34 | 38 | import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
| 39 | +import org.springframework.core.annotation.AliasFor; |
35 | 40 | import org.springframework.jms.config.JmsListenerContainerTestFactory;
|
36 | 41 | import org.springframework.jms.config.JmsListenerEndpointRegistrar;
|
37 | 42 | import org.springframework.jms.config.JmsListenerEndpointRegistry;
|
38 | 43 | import org.springframework.jms.config.MessageListenerTestContainer;
|
| 44 | +import org.springframework.jms.config.MethodJmsListenerEndpoint; |
39 | 45 | import org.springframework.jms.config.SimpleJmsListenerEndpoint;
|
40 | 46 | import org.springframework.jms.listener.adapter.ListenerExecutionFailedException;
|
41 | 47 | import org.springframework.jms.listener.adapter.MessageListenerAdapter;
|
|
48 | 54 |
|
49 | 55 | /**
|
50 | 56 | * @author Stephane Nicoll
|
| 57 | + * @author Sam Brannen |
51 | 58 | */
|
52 | 59 | public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
53 | 60 |
|
@@ -130,11 +137,33 @@ public void jmsListeners() {
|
130 | 137 | }
|
131 | 138 |
|
132 | 139 | @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") |
133 | 163 | public void unknownFactory() {
|
134 | 164 | thrown.expect(BeanCreationException.class);
|
135 | 165 | thrown.expectMessage("customFactory"); // Not found
|
136 |
| - new AnnotationConfigApplicationContext( |
137 |
| - EnableJmsSampleConfig.class, CustomBean.class); |
| 166 | + new AnnotationConfigApplicationContext(EnableJmsSampleConfig.class, CustomBean.class); |
138 | 167 | }
|
139 | 168 |
|
140 | 169 | @Test
|
@@ -295,4 +324,36 @@ public void handle(String msg) {
|
295 | 324 | }
|
296 | 325 | }
|
297 | 326 |
|
| 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 | + |
298 | 359 | }
|
0 commit comments