|
19 | 19 | import static org.mockito.ArgumentMatchers.*; |
20 | 20 | import static org.mockito.Mockito.*; |
21 | 21 |
|
| 22 | +import java.util.Map; |
22 | 23 | import java.util.concurrent.atomic.AtomicReference; |
23 | 24 | import java.util.function.Consumer; |
24 | 25 |
|
25 | 26 | import org.junit.jupiter.api.Test; |
| 27 | +import org.mockito.ArgumentCaptor; |
26 | 28 |
|
27 | 29 | import org.springframework.beans.factory.BeanCreationException; |
28 | 30 | import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
29 | 31 | import org.springframework.context.ApplicationContext; |
30 | 32 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
31 | 33 | import org.springframework.context.annotation.Bean; |
32 | 34 | import org.springframework.context.annotation.Configuration; |
| 35 | +import org.springframework.core.env.MapPropertySource; |
33 | 36 | import org.springframework.data.redis.config.RedisListenerConfigUtils; |
34 | 37 | import org.springframework.data.redis.config.RedisListenerEndpointRegistry; |
35 | 38 | import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
@@ -62,6 +65,24 @@ void registersListenerWithDefaultContainer() { |
62 | 65 | assertThat(registryRef.get().isRunning()).isFalse(); |
63 | 66 | } |
64 | 67 |
|
| 68 | + @Test // GH-3393 |
| 69 | + void resolvesListenerTopicPlaceholder() { |
| 70 | + |
| 71 | + try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { |
| 72 | + context.getEnvironment().getPropertySources() |
| 73 | + .addFirst(new MapPropertySource("redis-listener-test", Map.of("app.my-channel", "my-channel"))); |
| 74 | + context.register(DefaultConfig.class, PlaceholderTopicService.class); |
| 75 | + context.refresh(); |
| 76 | + |
| 77 | + RedisMessageListenerContainer container = context.getBean("redisMessageListenerContainer", |
| 78 | + RedisMessageListenerContainer.class); |
| 79 | + ArgumentCaptor<Topic> topicCaptor = ArgumentCaptor.forClass(Topic.class); |
| 80 | + |
| 81 | + verify(container).addMessageListener(any(), topicCaptor.capture()); |
| 82 | + assertThat(topicCaptor.getValue().getTopic()).isEqualTo("my-channel"); |
| 83 | + } |
| 84 | + } |
| 85 | + |
65 | 86 | @Test // GH-3340 |
66 | 87 | void registersListenerWithNamedContainer() { |
67 | 88 |
|
@@ -140,6 +161,13 @@ public void handle(String msg) {} |
140 | 161 |
|
141 | 162 | } |
142 | 163 |
|
| 164 | + static class PlaceholderTopicService { |
| 165 | + |
| 166 | + @RedisListener(topic = "${app.my-channel}") |
| 167 | + public void handle(String msg) {} |
| 168 | + |
| 169 | + } |
| 170 | + |
143 | 171 | static class UnnamedContainerService { |
144 | 172 |
|
145 | 173 | @RedisListener(topic = "test-topic", container = "") |
|
0 commit comments