|
23 | 23 | import java.util.concurrent.ConcurrentHashMap;
|
24 | 24 |
|
25 | 25 | import org.hamcrest.Matchers;
|
26 |
| -import org.junit.Before; |
| 26 | + |
27 | 27 | import org.junit.Test;
|
28 | 28 |
|
| 29 | +import org.springframework.context.ApplicationContext; |
29 | 30 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
30 | 31 | import org.springframework.context.annotation.Bean;
|
31 | 32 | import org.springframework.context.annotation.Configuration;
|
32 | 33 | import org.springframework.context.support.StaticApplicationContext;
|
33 | 34 | import org.springframework.messaging.Message;
|
34 | 35 | import org.springframework.messaging.MessageHandler;
|
35 |
| -import org.springframework.messaging.converter.*; |
| 36 | +import org.springframework.messaging.converter.ByteArrayMessageConverter; |
| 37 | +import org.springframework.messaging.converter.CompositeMessageConverter; |
| 38 | +import org.springframework.messaging.converter.ContentTypeResolver; |
| 39 | +import org.springframework.messaging.converter.DefaultContentTypeResolver; |
| 40 | +import org.springframework.messaging.converter.MappingJackson2MessageConverter; |
| 41 | +import org.springframework.messaging.converter.MessageConverter; |
| 42 | +import org.springframework.messaging.converter.StringMessageConverter; |
36 | 43 | import org.springframework.messaging.handler.annotation.MessageMapping;
|
37 | 44 | import org.springframework.messaging.handler.annotation.SendTo;
|
38 | 45 | import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
|
|
42 | 49 | import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
43 | 50 | import org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry;
|
44 | 51 | import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
|
45 |
| -import org.springframework.messaging.simp.user.UserDestinationMessageHandler; |
46 |
| -import org.springframework.messaging.simp.user.UserSessionRegistry; |
47 | 52 | import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
|
48 | 53 | import org.springframework.messaging.simp.stomp.StompCommand;
|
49 | 54 | import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
| 55 | +import org.springframework.messaging.simp.user.UserDestinationMessageHandler; |
| 56 | +import org.springframework.messaging.simp.user.UserSessionRegistry; |
50 | 57 | import org.springframework.messaging.support.AbstractSubscribableChannel;
|
51 | 58 | import org.springframework.messaging.support.ChannelInterceptor;
|
52 | 59 | import org.springframework.messaging.support.ChannelInterceptorAdapter;
|
|
61 | 68 | import org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean;
|
62 | 69 |
|
63 | 70 | import static org.junit.Assert.*;
|
64 |
| -import static org.mockito.Mockito.mock; |
| 71 | +import static org.mockito.Mockito.*; |
65 | 72 |
|
66 | 73 | /**
|
67 | 74 | * Test fixture for {@link AbstractMessageBrokerConfiguration}.
|
|
72 | 79 | */
|
73 | 80 | public class MessageBrokerConfigurationTests {
|
74 | 81 |
|
75 |
| - private AnnotationConfigApplicationContext simpleBrokerContext; |
76 |
| - |
77 |
| - private AnnotationConfigApplicationContext brokerRelayContext; |
78 |
| - |
79 |
| - private AnnotationConfigApplicationContext defaultContext; |
80 |
| - |
81 |
| - private AnnotationConfigApplicationContext customContext; |
82 |
| - |
83 |
| - |
84 |
| - @Before |
85 |
| - public void setupOnce() { |
86 |
| - |
87 |
| - this.simpleBrokerContext = new AnnotationConfigApplicationContext(); |
88 |
| - this.simpleBrokerContext.register(SimpleBrokerConfig.class); |
89 |
| - this.simpleBrokerContext.refresh(); |
90 |
| - |
91 |
| - this.brokerRelayContext = new AnnotationConfigApplicationContext(); |
92 |
| - this.brokerRelayContext.register(BrokerRelayConfig.class); |
93 |
| - this.brokerRelayContext.refresh(); |
94 |
| - |
95 |
| - this.defaultContext = new AnnotationConfigApplicationContext(); |
96 |
| - this.defaultContext.register(DefaultConfig.class); |
97 |
| - this.defaultContext.refresh(); |
98 |
| - |
99 |
| - this.customContext = new AnnotationConfigApplicationContext(); |
100 |
| - this.customContext.register(CustomConfig.class); |
101 |
| - this.customContext.refresh(); |
102 |
| - } |
| 82 | + private ApplicationContext defaultContext = new AnnotationConfigApplicationContext(DefaultConfig.class); |
| 83 | + private ApplicationContext simpleBrokerContext = new AnnotationConfigApplicationContext(SimpleBrokerConfig.class); |
| 84 | + private ApplicationContext brokerRelayContext = new AnnotationConfigApplicationContext(BrokerRelayConfig.class); |
| 85 | + private ApplicationContext customContext = new AnnotationConfigApplicationContext(CustomConfig.class); |
103 | 86 |
|
104 | 87 |
|
105 | 88 | @Test
|
106 | 89 | public void clientInboundChannel() {
|
107 |
| - |
108 | 90 | TestChannel channel = this.simpleBrokerContext.getBean("clientInboundChannel", TestChannel.class);
|
109 | 91 | Set<MessageHandler> handlers = channel.getSubscribers();
|
110 | 92 |
|
@@ -194,7 +176,6 @@ public void clientOutboundChannelUsedBySimpleBroker() {
|
194 | 176 |
|
195 | 177 | @Test
|
196 | 178 | public void clientOutboundChannelCustomized() {
|
197 |
| - |
198 | 179 | AbstractSubscribableChannel channel = this.customContext.getBean(
|
199 | 180 | "clientOutboundChannel", AbstractSubscribableChannel.class);
|
200 | 181 |
|
@@ -274,7 +255,6 @@ public void brokerChannelUsedByUserDestinationMessageHandler() {
|
274 | 255 |
|
275 | 256 | @Test
|
276 | 257 | public void brokerChannelCustomized() {
|
277 |
| - |
278 | 258 | AbstractSubscribableChannel channel = this.customContext.getBean(
|
279 | 259 | "brokerChannel", AbstractSubscribableChannel.class);
|
280 | 260 |
|
@@ -305,7 +285,6 @@ public void configureMessageConvertersDefault() {
|
305 | 285 |
|
306 | 286 | @Test
|
307 | 287 | public void threadPoolSizeDefault() {
|
308 |
| - |
309 | 288 | String name = "clientInboundChannelExecutor";
|
310 | 289 | ThreadPoolTaskExecutor executor = this.defaultContext.getBean(name, ThreadPoolTaskExecutor.class);
|
311 | 290 | assertEquals(Runtime.getRuntime().availableProcessors() * 2, executor.getCorePoolSize());
|
@@ -340,7 +319,6 @@ protected boolean configureMessageConverters(List<MessageConverter> messageConve
|
340 | 319 |
|
341 | 320 | @Test
|
342 | 321 | public void configureMessageConvertersCustomAndDefault() {
|
343 |
| - |
344 | 322 | final MessageConverter testConverter = mock(MessageConverter.class);
|
345 | 323 |
|
346 | 324 | AbstractMessageBrokerConfiguration config = new AbstractMessageBrokerConfiguration() {
|
@@ -541,6 +519,7 @@ public void validate(Object target, Errors errors) {
|
541 | 519 | }
|
542 | 520 | }
|
543 | 521 |
|
| 522 | + @SuppressWarnings("serial") |
544 | 523 | private static class CustomThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
|
545 | 524 | }
|
546 | 525 |
|
|
0 commit comments