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());
}
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());
}
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"));
}
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());
}
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);
}
Aggregations