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