Search in sources :

Example 6 with TestPrincipal

use of org.springframework.messaging.simp.TestPrincipal in project spring-framework by spring-projects.

the class DefaultUserDestinationResolverTests method handleMessage.

@Test
public void handleMessage() {
    TestPrincipal user = new TestPrincipal("joe");
    String sourceDestination = "/user/joe/queue/foo";
    Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "123", sourceDestination);
    UserDestinationResult actual = this.resolver.resolveDestination(message);
    assertEquals(sourceDestination, actual.getSourceDestination());
    assertEquals(1, actual.getTargetDestinations().size());
    assertEquals("/queue/foo-user123", actual.getTargetDestinations().iterator().next());
    assertEquals("/user/queue/foo", actual.getSubscribeDestination());
    assertEquals(user.getName(), actual.getUser());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) Test(org.junit.Test)

Example 7 with TestPrincipal

use of org.springframework.messaging.simp.TestPrincipal in project spring-framework by spring-projects.

the class DefaultUserDestinationResolverTests method handleMessageEncodedUserName.

@Test
public void handleMessageEncodedUserName() {
    String userName = "http://joe.openid.example.org/";
    TestSimpUser simpUser = new TestSimpUser(userName);
    simpUser.addSessions(new TestSimpSession("openid123"));
    when(this.registry.getUser(userName)).thenReturn(simpUser);
    String destination = "/user/" + StringUtils.replace(userName, "/", "%2F") + "/queue/foo";
    Message<?> message = createMessage(SimpMessageType.MESSAGE, new TestPrincipal("joe"), null, destination);
    UserDestinationResult actual = this.resolver.resolveDestination(message);
    assertEquals(1, actual.getTargetDestinations().size());
    assertEquals("/queue/foo-useropenid123", actual.getTargetDestinations().iterator().next());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) Test(org.junit.Test)

Example 8 with TestPrincipal

use of org.springframework.messaging.simp.TestPrincipal in project spring-framework by spring-projects.

the class DefaultUserDestinationResolverTests method handleSubscribeOneUserMultipleSessions.

// SPR-11325
@Test
public void handleSubscribeOneUserMultipleSessions() {
    TestSimpUser simpUser = new TestSimpUser("joe");
    simpUser.addSessions(new TestSimpSession("123"), new TestSimpSession("456"));
    when(this.registry.getUser("joe")).thenReturn(simpUser);
    TestPrincipal user = new TestPrincipal("joe");
    Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, user, "456", "/user/queue/foo");
    UserDestinationResult actual = this.resolver.resolveDestination(message);
    assertEquals(1, actual.getTargetDestinations().size());
    assertEquals("/queue/foo-user456", actual.getTargetDestinations().iterator().next());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) Test(org.junit.Test)

Example 9 with TestPrincipal

use of org.springframework.messaging.simp.TestPrincipal in project spring-framework by spring-projects.

the class DefaultUserDestinationResolverTests method handleMessageToOtherUser.

// SPR-12444
@Test
public void handleMessageToOtherUser() {
    TestSimpUser otherSimpUser = new TestSimpUser("anna");
    otherSimpUser.addSessions(new TestSimpSession("456"));
    when(this.registry.getUser("anna")).thenReturn(otherSimpUser);
    TestPrincipal user = new TestPrincipal("joe");
    TestPrincipal otherUser = new TestPrincipal("anna");
    String sourceDestination = "/user/anna/queue/foo";
    Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "456", sourceDestination);
    UserDestinationResult actual = this.resolver.resolveDestination(message);
    assertEquals(sourceDestination, actual.getSourceDestination());
    assertEquals(1, actual.getTargetDestinations().size());
    assertEquals("/queue/foo-user456", actual.getTargetDestinations().iterator().next());
    assertEquals("/user/queue/foo", actual.getSubscribeDestination());
    assertEquals(otherUser.getName(), actual.getUser());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) Test(org.junit.Test)

Example 10 with TestPrincipal

use of org.springframework.messaging.simp.TestPrincipal in project spring-framework by spring-projects.

the class DefaultUserDestinationResolverTests method handleUnsubscribe.

@Test
public void handleUnsubscribe() {
    TestPrincipal user = new TestPrincipal("joe");
    Message<?> message = createMessage(SimpMessageType.UNSUBSCRIBE, user, "123", "/user/queue/foo");
    UserDestinationResult actual = this.resolver.resolveDestination(message);
    assertEquals(1, actual.getTargetDestinations().size());
    assertEquals("/queue/foo-user123", actual.getTargetDestinations().iterator().next());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) Test(org.junit.Test)

Aggregations

TestPrincipal (org.springframework.messaging.simp.TestPrincipal)18 Test (org.junit.Test)15 Message (org.springframework.messaging.Message)4 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)3 MessageHeaders (org.springframework.messaging.MessageHeaders)2 AntPathMatcher (org.springframework.util.AntPathMatcher)2 TextMessage (org.springframework.web.socket.TextMessage)2 Before (org.junit.Before)1 MessageChannel (org.springframework.messaging.MessageChannel)1 BinaryMessage (org.springframework.web.socket.BinaryMessage)1 WebSocketMessage (org.springframework.web.socket.WebSocketMessage)1 TestWebSocketSession (org.springframework.web.socket.handler.TestWebSocketSession)1