use of org.springframework.messaging.simp.user.SimpUser in project spring-framework by spring-projects.
the class DefaultSimpUserRegistryTests method nullSessionId.
@Test
public void nullSessionId() throws Exception {
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
TestPrincipal user = new TestPrincipal("joe");
Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(event);
SimpUser simpUser = registry.getUser("joe");
assertThat(simpUser.getSession(null)).isNull();
}
use of org.springframework.messaging.simp.user.SimpUser in project spring-framework by spring-projects.
the class DefaultSimpUserRegistryTests method addOneSessionId.
@Test
public void addOneSessionId() {
TestPrincipal user = new TestPrincipal("joe");
Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
registry.onApplicationEvent(event);
SimpUser simpUser = registry.getUser("joe");
assertThat(simpUser).isNotNull();
assertThat(registry.getUserCount()).isEqualTo(1);
assertThat(simpUser.getSessions().size()).isEqualTo(1);
assertThat(simpUser.getSession("123")).isNotNull();
}
use of org.springframework.messaging.simp.user.SimpUser in project spring-framework by spring-projects.
the class DefaultSimpUserRegistryTests method addMultipleSessionIds.
@Test
public void addMultipleSessionIds() {
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
TestPrincipal user = new TestPrincipal("joe");
Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(event);
message = createMessage(SimpMessageType.CONNECT_ACK, "456");
event = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(event);
message = createMessage(SimpMessageType.CONNECT_ACK, "789");
event = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(event);
SimpUser simpUser = registry.getUser("joe");
assertThat(simpUser).isNotNull();
assertThat(registry.getUserCount()).isEqualTo(1);
assertThat(simpUser.getSessions().size()).isEqualTo(3);
assertThat(simpUser.getSession("123")).isNotNull();
assertThat(simpUser.getSession("456")).isNotNull();
assertThat(simpUser.getSession("789")).isNotNull();
}
use of org.springframework.messaging.simp.user.SimpUser in project spring-framework by spring-projects.
the class DefaultSimpUserRegistryTests method removeSessionIds.
@Test
public void removeSessionIds() {
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
TestPrincipal user = new TestPrincipal("joe");
Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
SessionConnectedEvent connectedEvent = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(connectedEvent);
message = createMessage(SimpMessageType.CONNECT_ACK, "456");
connectedEvent = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(connectedEvent);
message = createMessage(SimpMessageType.CONNECT_ACK, "789");
connectedEvent = new SessionConnectedEvent(this, message, user);
registry.onApplicationEvent(connectedEvent);
SimpUser simpUser = registry.getUser("joe");
assertThat(simpUser).isNotNull();
assertThat(simpUser.getSessions().size()).isEqualTo(3);
CloseStatus status = CloseStatus.GOING_AWAY;
message = createMessage(SimpMessageType.DISCONNECT, "456");
SessionDisconnectEvent disconnectEvent = new SessionDisconnectEvent(this, message, "456", status, user);
registry.onApplicationEvent(disconnectEvent);
message = createMessage(SimpMessageType.DISCONNECT, "789");
disconnectEvent = new SessionDisconnectEvent(this, message, "789", status, user);
registry.onApplicationEvent(disconnectEvent);
assertThat(simpUser.getSessions().size()).isEqualTo(1);
assertThat(simpUser.getSession("123")).isNotNull();
}
Aggregations