|
|
|
@ -18,7 +18,6 @@ package org.springframework.messaging.simp.user; |
|
|
|
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.mockito.ArgumentCaptor; |
|
|
|
import org.mockito.ArgumentCaptor; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.mockito.Mockito; |
|
|
|
@ -41,31 +40,22 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; |
|
|
|
import static org.springframework.messaging.simp.SimpMessageHeaderAccessor.ORIGINAL_DESTINATION; |
|
|
|
import static org.springframework.messaging.simp.SimpMessageHeaderAccessor.ORIGINAL_DESTINATION; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unit tests for |
|
|
|
* Unit tests for {@link UserDestinationMessageHandler}. |
|
|
|
* {@link org.springframework.messaging.simp.user.UserDestinationMessageHandler}. |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class UserDestinationMessageHandlerTests { |
|
|
|
class UserDestinationMessageHandlerTests { |
|
|
|
|
|
|
|
|
|
|
|
private static final String SESSION_ID = "123"; |
|
|
|
private static final String SESSION_ID = "123"; |
|
|
|
|
|
|
|
|
|
|
|
private UserDestinationMessageHandler handler; |
|
|
|
private final SimpUserRegistry registry = mock(SimpUserRegistry.class); |
|
|
|
|
|
|
|
|
|
|
|
private SimpUserRegistry registry; |
|
|
|
private final SubscribableChannel brokerChannel = mock(SubscribableChannel.class); |
|
|
|
|
|
|
|
|
|
|
|
private SubscribableChannel brokerChannel; |
|
|
|
private final UserDestinationMessageHandler handler = new UserDestinationMessageHandler(new StubMessageChannel(), this.brokerChannel, new DefaultUserDestinationResolver(this.registry)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
|
|
|
|
public void setup() { |
|
|
|
|
|
|
|
this.registry = mock(SimpUserRegistry.class); |
|
|
|
|
|
|
|
this.brokerChannel = mock(SubscribableChannel.class); |
|
|
|
|
|
|
|
UserDestinationResolver resolver = new DefaultUserDestinationResolver(this.registry); |
|
|
|
|
|
|
|
this.handler = new UserDestinationMessageHandler(new StubMessageChannel(), this.brokerChannel, resolver); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void handleSubscribe() { |
|
|
|
@SuppressWarnings("rawtypes") |
|
|
|
|
|
|
|
void handleSubscribe() { |
|
|
|
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); |
|
|
|
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); |
|
|
|
this.handler.handleMessage(createWith(SimpMessageType.SUBSCRIBE, "joe", SESSION_ID, "/user/queue/foo")); |
|
|
|
this.handler.handleMessage(createWith(SimpMessageType.SUBSCRIBE, "joe", SESSION_ID, "/user/queue/foo")); |
|
|
|
|
|
|
|
|
|
|
|
@ -77,7 +67,8 @@ public class UserDestinationMessageHandlerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void handleUnsubscribe() { |
|
|
|
@SuppressWarnings("rawtypes") |
|
|
|
|
|
|
|
void handleUnsubscribe() { |
|
|
|
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); |
|
|
|
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); |
|
|
|
this.handler.handleMessage(createWith(SimpMessageType.UNSUBSCRIBE, "joe", "123", "/user/queue/foo")); |
|
|
|
this.handler.handleMessage(createWith(SimpMessageType.UNSUBSCRIBE, "joe", "123", "/user/queue/foo")); |
|
|
|
|
|
|
|
|
|
|
|
@ -89,7 +80,8 @@ public class UserDestinationMessageHandlerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void handleMessage() { |
|
|
|
@SuppressWarnings("rawtypes") |
|
|
|
|
|
|
|
void handleMessage() { |
|
|
|
TestSimpUser simpUser = new TestSimpUser("joe"); |
|
|
|
TestSimpUser simpUser = new TestSimpUser("joe"); |
|
|
|
simpUser.addSessions(new TestSimpSession("123")); |
|
|
|
simpUser.addSessions(new TestSimpSession("123")); |
|
|
|
given(this.registry.getUser("joe")).willReturn(simpUser); |
|
|
|
given(this.registry.getUser("joe")).willReturn(simpUser); |
|
|
|
@ -105,7 +97,8 @@ public class UserDestinationMessageHandlerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void handleMessageWithoutActiveSession() { |
|
|
|
@SuppressWarnings("rawtypes") |
|
|
|
|
|
|
|
void handleMessageWithoutActiveSession() { |
|
|
|
this.handler.setBroadcastDestination("/topic/unresolved"); |
|
|
|
this.handler.setBroadcastDestination("/topic/unresolved"); |
|
|
|
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); |
|
|
|
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); |
|
|
|
this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", "/user/joe/queue/foo")); |
|
|
|
this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", "/user/joe/queue/foo")); |
|
|
|
@ -125,7 +118,8 @@ public class UserDestinationMessageHandlerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void handleMessageFromBrokerWithActiveSession() { |
|
|
|
@SuppressWarnings("rawtypes") |
|
|
|
|
|
|
|
void handleMessageFromBrokerWithActiveSession() { |
|
|
|
TestSimpUser simpUser = new TestSimpUser("joe"); |
|
|
|
TestSimpUser simpUser = new TestSimpUser("joe"); |
|
|
|
simpUser.addSessions(new TestSimpSession("123")); |
|
|
|
simpUser.addSessions(new TestSimpSession("123")); |
|
|
|
given(this.registry.getUser("joe")).willReturn(simpUser); |
|
|
|
given(this.registry.getUser("joe")).willReturn(simpUser); |
|
|
|
@ -153,7 +147,7 @@ public class UserDestinationMessageHandlerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void handleMessageFromBrokerWithoutActiveSession() { |
|
|
|
void handleMessageFromBrokerWithoutActiveSession() { |
|
|
|
this.handler.setBroadcastDestination("/topic/unresolved"); |
|
|
|
this.handler.setBroadcastDestination("/topic/unresolved"); |
|
|
|
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); |
|
|
|
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
@ -170,7 +164,7 @@ public class UserDestinationMessageHandlerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void ignoreMessage() { |
|
|
|
void ignoreMessage() { |
|
|
|
|
|
|
|
|
|
|
|
// no destination
|
|
|
|
// no destination
|
|
|
|
this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", null)); |
|
|
|
this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", null)); |
|
|
|
|