|
17 | 17 | package org.springframework.messaging.simp.user;
|
18 | 18 |
|
19 | 19 | import java.nio.charset.StandardCharsets;
|
| 20 | +import java.util.Set; |
20 | 21 |
|
21 | 22 | import org.junit.jupiter.api.Test;
|
22 | 23 | import org.mockito.ArgumentCaptor;
|
@@ -98,6 +99,26 @@ void handleMessage() {
|
98 | 99 | assertThat(accessor.getFirstNativeHeader(ORIGINAL_DESTINATION)).isEqualTo("/user/queue/foo");
|
99 | 100 | }
|
100 | 101 |
|
| 102 | + @Test |
| 103 | + @SuppressWarnings("rawtypes") |
| 104 | + void handleMessageWithoutSessionIds() { |
| 105 | + UserDestinationResolver resolver = mock(); |
| 106 | + Message message = createWith(SimpMessageType.MESSAGE, "joe", null, "/user/joe/queue/foo"); |
| 107 | + UserDestinationResult result = new UserDestinationResult("/queue/foo-user123", Set.of("/queue/foo-user123"), "/user/queue/foo", "joe"); |
| 108 | + given(resolver.resolveDestination(message)).willReturn(result); |
| 109 | + |
| 110 | + given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); |
| 111 | + UserDestinationMessageHandler handler = new UserDestinationMessageHandler(new StubMessageChannel(), this.brokerChannel, resolver); |
| 112 | + handler.handleMessage(message); |
| 113 | + |
| 114 | + ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class); |
| 115 | + Mockito.verify(this.brokerChannel).send(captor.capture()); |
| 116 | + |
| 117 | + SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(captor.getValue()); |
| 118 | + assertThat(accessor.getDestination()).isEqualTo("/queue/foo-user123"); |
| 119 | + assertThat(accessor.getFirstNativeHeader(ORIGINAL_DESTINATION)).isEqualTo("/user/queue/foo"); |
| 120 | + } |
| 121 | + |
101 | 122 | @Test
|
102 | 123 | @SuppressWarnings("rawtypes")
|
103 | 124 | void handleMessageWithoutActiveSession() {
|
|
0 commit comments