Search in sources :

Example 11 with TestPrincipal

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

the class DefaultUserDestinationResolverTests method handleMessageForDestinationWithDotSeparator.

// SPR-14044
@Test
public void handleMessageForDestinationWithDotSeparator() {
    AntPathMatcher pathMatcher = new AntPathMatcher();
    pathMatcher.setPathSeparator(".");
    this.resolver.setPathMatcher(pathMatcher);
    TestPrincipal user = new TestPrincipal("joe");
    String destination = "/user/joe/jms.queue.call";
    Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "123", destination);
    UserDestinationResult actual = this.resolver.resolveDestination(message);
    assertEquals(1, actual.getTargetDestinations().size());
    assertEquals("jms.queue.call-user123", actual.getTargetDestinations().iterator().next());
    assertEquals("/user/jms.queue.call", actual.getSubscribeDestination());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.Test)

Example 12 with TestPrincipal

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

the class StompSubProtocolHandlerTests method handleMessageToClientWithSimpHeartbeat.

@Test
public void handleMessageToClientWithSimpHeartbeat() {
    SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.HEARTBEAT);
    accessor.setSessionId("s1");
    accessor.setUser(new TestPrincipal("joe"));
    Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
    this.protocolHandler.handleMessageToClient(this.session, ackMessage);
    assertEquals(1, this.session.getSentMessages().size());
    TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
    assertEquals("\n", actual.getPayload());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) TextMessage(org.springframework.web.socket.TextMessage) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 13 with TestPrincipal

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

the class StompSubProtocolHandlerTests method setup.

@Before
public void setup() {
    this.protocolHandler = new StompSubProtocolHandler();
    this.channel = Mockito.mock(MessageChannel.class);
    this.messageCaptor = ArgumentCaptor.forClass(Message.class);
    when(this.channel.send(any())).thenReturn(true);
    this.session = new TestWebSocketSession();
    this.session.setId("s1");
    this.session.setPrincipal(new TestPrincipal("joe"));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) TextMessage(org.springframework.web.socket.TextMessage) Message(org.springframework.messaging.Message) WebSocketMessage(org.springframework.web.socket.WebSocketMessage) BinaryMessage(org.springframework.web.socket.BinaryMessage) TestWebSocketSession(org.springframework.web.socket.handler.TestWebSocketSession) TestPrincipal(org.springframework.messaging.simp.TestPrincipal) Before(org.junit.Before)

Example 14 with TestPrincipal

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

the class DefaultUserDestinationResolverTests method handleSubscribeForDestinationWithoutLeadingSlash.

// SPR-14044
@Test
public void handleSubscribeForDestinationWithoutLeadingSlash() {
    AntPathMatcher pathMatcher = new AntPathMatcher();
    pathMatcher.setPathSeparator(".");
    this.resolver.setPathMatcher(pathMatcher);
    TestPrincipal user = new TestPrincipal("joe");
    String destination = "/user/jms.queue.call";
    Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, user, "123", destination);
    UserDestinationResult actual = this.resolver.resolveDestination(message);
    assertEquals(1, actual.getTargetDestinations().size());
    assertEquals("jms.queue.call-user123", actual.getTargetDestinations().iterator().next());
    assertEquals(destination, actual.getSubscribeDestination());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.Test)

Example 15 with TestPrincipal

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

the class DefaultUserDestinationResolverTests method ignoreMessage.

@Test
public void ignoreMessage() {
    // no destination
    TestPrincipal user = new TestPrincipal("joe");
    Message<?> message = createMessage(SimpMessageType.MESSAGE, user, "123", null);
    UserDestinationResult actual = this.resolver.resolveDestination(message);
    assertNull(actual);
    // not a user destination
    message = createMessage(SimpMessageType.MESSAGE, user, "123", "/queue/foo");
    actual = this.resolver.resolveDestination(message);
    assertNull(actual);
    // subscribe + not a user destination
    message = createMessage(SimpMessageType.SUBSCRIBE, user, "123", "/queue/foo");
    actual = this.resolver.resolveDestination(message);
    assertNull(actual);
    // no match on message type
    message = createMessage(SimpMessageType.CONNECT, user, "123", "user/joe/queue/foo");
    actual = this.resolver.resolveDestination(message);
    assertNull(actual);
}
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