Search in sources :

Example 16 with TestPrincipal

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

the class DefaultUserDestinationResolverTests method handleSubscribe.

@Test
public void handleSubscribe() {
    TestPrincipal user = new TestPrincipal("joe");
    String sourceDestination = "/user/queue/foo";
    Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, 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(sourceDestination, actual.getSubscribeDestination());
    assertEquals(user.getName(), actual.getUser());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) Test(org.junit.Test)

Example 17 with TestPrincipal

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

the class StompBrokerRelayMessageHandlerTests method message.

private Message<byte[]> message(StompCommand command, String sessionId, String user, String destination) {
    StompHeaderAccessor accessor = StompHeaderAccessor.create(command);
    if (sessionId != null) {
        accessor.setSessionId(sessionId);
    }
    if (user != null) {
        accessor.setUser(new TestPrincipal(user));
    }
    if (destination != null) {
        accessor.setDestination(destination);
    }
    accessor.setLeaveMutable(true);
    return MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal)

Example 18 with TestPrincipal

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

the class StompBrokerRelayMessageHandlerTests method connectMessage.

private Message<byte[]> connectMessage(String sessionId, String user) {
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.CONNECT);
    headers.setSessionId(sessionId);
    headers.setUser(new TestPrincipal(user));
    return MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal)

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