Search in sources :

Example 1 with SimpUser

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();
}
Also used : TestPrincipal(org.springframework.core.testfixture.security.TestPrincipal) SimpUser(org.springframework.messaging.simp.user.SimpUser) Test(org.junit.jupiter.api.Test)

Example 2 with SimpUser

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();
}
Also used : TestPrincipal(org.springframework.core.testfixture.security.TestPrincipal) SimpUser(org.springframework.messaging.simp.user.SimpUser) Test(org.junit.jupiter.api.Test)

Example 3 with SimpUser

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();
}
Also used : TestPrincipal(org.springframework.core.testfixture.security.TestPrincipal) SimpUser(org.springframework.messaging.simp.user.SimpUser) Test(org.junit.jupiter.api.Test)

Example 4 with SimpUser

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();
}
Also used : TestPrincipal(org.springframework.core.testfixture.security.TestPrincipal) SimpUser(org.springframework.messaging.simp.user.SimpUser) CloseStatus(org.springframework.web.socket.CloseStatus) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 TestPrincipal (org.springframework.core.testfixture.security.TestPrincipal)4 SimpUser (org.springframework.messaging.simp.user.SimpUser)4 CloseStatus (org.springframework.web.socket.CloseStatus)1