org.springframework.messaging.simp.TestPrincipal Java Examples
The following examples show how to use
org.springframework.messaging.simp.TestPrincipal.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleBrokerMessageHandlerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void readWriteIntervalCalculation() throws Exception { this.messageHandler.setHeartbeatValue(new long[] {1, 1}); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.start(); ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L)); Runnable heartbeatTask = taskCaptor.getValue(); assertNotNull(heartbeatTask); String id = "sess1"; TestPrincipal user = new TestPrincipal("joe"); Message<String> connectMessage = createConnectMessage(id, user, new long[] {10000, 10000}); this.messageHandler.handleMessage(connectMessage); Thread.sleep(10); heartbeatTask.run(); verify(this.clientOutChannel, times(1)).send(this.messageCaptor.capture()); List<Message<?>> messages = this.messageCaptor.getAllValues(); assertEquals(1, messages.size()); assertEquals(SimpMessageType.CONNECT_ACK, messages.get(0).getHeaders().get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); }
Example #2
Source File: DefaultUserDestinationResolverTests.java From java-technology-stack with MIT License | 6 votes |
@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); }
Example #3
Source File: DefaultUserDestinationResolverTests.java From java-technology-stack with MIT License | 6 votes |
@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()); }
Example #4
Source File: DefaultUserDestinationResolverTests.java From java-technology-stack with MIT License | 6 votes |
@Test // SPR-12444 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()); }
Example #5
Source File: SimpleBrokerMessageHandlerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void readWriteIntervalCalculation() throws Exception { this.messageHandler.setHeartbeatValue(new long[] {1, 1}); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.start(); ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L)); Runnable heartbeatTask = taskCaptor.getValue(); assertNotNull(heartbeatTask); String id = "sess1"; TestPrincipal user = new TestPrincipal("joe"); Message<String> connectMessage = createConnectMessage(id, user, new long[] {10000, 10000}); this.messageHandler.handleMessage(connectMessage); Thread.sleep(10); heartbeatTask.run(); verify(this.clientOutChannel, times(1)).send(this.messageCaptor.capture()); List<Message<?>> messages = this.messageCaptor.getAllValues(); assertEquals(1, messages.size()); assertEquals(SimpMessageType.CONNECT_ACK, messages.get(0).getHeaders().get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); }
Example #6
Source File: DefaultUserDestinationResolverTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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()); }
Example #7
Source File: DefaultUserDestinationResolverTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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()); }
Example #8
Source File: DefaultUserDestinationResolverTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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); }
Example #9
Source File: DefaultUserDestinationResolverTests.java From spring-analysis-note with MIT License | 6 votes |
@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); }
Example #10
Source File: DefaultUserDestinationResolverTests.java From spring-analysis-note with MIT License | 6 votes |
@Test // SPR-12444 public void handleMessageToOtherUser() { TestSimpUser otherSimpUser = new TestSimpUser("anna"); otherSimpUser.addSessions(new TestSimpSession("456")); given(this.registry.getUser("anna")).willReturn(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()); }
Example #11
Source File: DefaultUserDestinationResolverTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void handleMessageEncodedUserName() { String userName = "https://joe.openid.example.org/"; TestSimpUser simpUser = new TestSimpUser(userName); simpUser.addSessions(new TestSimpSession("openid123")); given(this.registry.getUser(userName)).willReturn(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()); }
Example #12
Source File: SimpleBrokerMessageHandlerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void readWriteIntervalCalculation() throws Exception { this.messageHandler.setHeartbeatValue(new long[] {1, 1}); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.start(); ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L)); Runnable heartbeatTask = taskCaptor.getValue(); assertNotNull(heartbeatTask); String id = "sess1"; TestPrincipal user = new TestPrincipal("joe"); Message<String> connectMessage = createConnectMessage(id, user, new long[] {10000, 10000}); this.messageHandler.handleMessage(connectMessage); Thread.sleep(10); heartbeatTask.run(); verify(this.clientOutboundChannel, times(1)).send(this.messageCaptor.capture()); List<Message<?>> messages = this.messageCaptor.getAllValues(); assertEquals(1, messages.size()); assertEquals(SimpMessageType.CONNECT_ACK, messages.get(0).getHeaders().get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); }
Example #13
Source File: SimpleBrokerMessageHandlerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void connect() { this.messageHandler.start(); String id = "sess1"; Message<String> connectMessage = createConnectMessage(id, new TestPrincipal("joe"), null); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.handleMessage(connectMessage); verify(this.clientOutboundChannel, times(1)).send(this.messageCaptor.capture()); Message<?> connectAckMessage = this.messageCaptor.getValue(); SimpMessageHeaderAccessor connectAckHeaders = SimpMessageHeaderAccessor.wrap(connectAckMessage); assertEquals(connectMessage, connectAckHeaders.getHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER)); assertEquals(id, connectAckHeaders.getSessionId()); assertEquals("joe", connectAckHeaders.getUser().getName()); assertArrayEquals(new long[] {10000, 10000}, SimpMessageHeaderAccessor.getHeartbeat(connectAckHeaders.getMessageHeaders())); }
Example #14
Source File: StompSubProtocolHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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")); }
Example #15
Source File: SimpleBrokerMessageHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void writeInactivity() throws Exception { this.messageHandler.setHeartbeatValue(new long[] {1, 0}); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.start(); ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L)); Runnable heartbeatTask = taskCaptor.getValue(); assertNotNull(heartbeatTask); String id = "sess1"; TestPrincipal user = new TestPrincipal("joe"); Message<String> connectMessage = createConnectMessage(id, user, new long[] {0, 1}); this.messageHandler.handleMessage(connectMessage); Thread.sleep(10); heartbeatTask.run(); verify(this.clientOutboundChannel, times(2)).send(this.messageCaptor.capture()); List<Message<?>> messages = this.messageCaptor.getAllValues(); assertEquals(2, messages.size()); MessageHeaders headers = messages.get(0).getHeaders(); assertEquals(SimpMessageType.CONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); headers = messages.get(1).getHeaders(); assertEquals(SimpMessageType.HEARTBEAT, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); assertEquals(id, headers.get(SimpMessageHeaderAccessor.SESSION_ID_HEADER)); assertEquals(user, headers.get(SimpMessageHeaderAccessor.USER_HEADER)); }
Example #16
Source File: UserDestinationMessageHandlerTests.java From java-technology-stack with MIT License | 5 votes |
private Message<?> createWith(SimpMessageType type, String user, String sessionId, String destination) { SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(type); if (destination != null) { headers.setDestination(destination); } if (user != null) { headers.setUser(new TestPrincipal(user)); } if (sessionId != null) { headers.setSessionId(sessionId); } return MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build(); }
Example #17
Source File: SimpleBrokerMessageHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void subscribeDisconnectPublish() { String sess1 = "sess1"; String sess2 = "sess2"; startSession(sess1); startSession(sess2); this.messageHandler.handleMessage(createSubscriptionMessage(sess1, "sub1", "/foo")); this.messageHandler.handleMessage(createSubscriptionMessage(sess1, "sub2", "/foo")); this.messageHandler.handleMessage(createSubscriptionMessage(sess1, "sub3", "/bar")); this.messageHandler.handleMessage(createSubscriptionMessage(sess2, "sub1", "/foo")); this.messageHandler.handleMessage(createSubscriptionMessage(sess2, "sub2", "/foo")); this.messageHandler.handleMessage(createSubscriptionMessage(sess2, "sub3", "/bar")); SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.DISCONNECT); headers.setSessionId(sess1); headers.setUser(new TestPrincipal("joe")); Message<byte[]> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders()); this.messageHandler.handleMessage(message); this.messageHandler.handleMessage(createMessage("/foo", "message1")); this.messageHandler.handleMessage(createMessage("/bar", "message2")); verify(this.clientOutChannel, times(4)).send(this.messageCaptor.capture()); Message<?> captured = this.messageCaptor.getAllValues().get(2); assertEquals(SimpMessageType.DISCONNECT_ACK, SimpMessageHeaderAccessor.getMessageType(captured.getHeaders())); assertSame(message, captured.getHeaders().get(SimpMessageHeaderAccessor.DISCONNECT_MESSAGE_HEADER)); assertEquals(sess1, SimpMessageHeaderAccessor.getSessionId(captured.getHeaders())); assertEquals("joe", SimpMessageHeaderAccessor.getUser(captured.getHeaders()).getName()); assertTrue(messageCaptured(sess2, "sub1", "/foo")); assertTrue(messageCaptured(sess2, "sub2", "/foo")); assertTrue(messageCaptured(sess2, "sub3", "/bar")); }
Example #18
Source File: SimpleBrokerMessageHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void readInactivity() throws Exception { this.messageHandler.setHeartbeatValue(new long[] {0, 1}); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.start(); ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L)); Runnable heartbeatTask = taskCaptor.getValue(); assertNotNull(heartbeatTask); String id = "sess1"; TestPrincipal user = new TestPrincipal("joe"); Message<String> connectMessage = createConnectMessage(id, user, new long[] {1, 0}); this.messageHandler.handleMessage(connectMessage); Thread.sleep(10); heartbeatTask.run(); verify(this.clientOutChannel, atLeast(2)).send(this.messageCaptor.capture()); List<Message<?>> messages = this.messageCaptor.getAllValues(); assertEquals(2, messages.size()); MessageHeaders headers = messages.get(0).getHeaders(); assertEquals(SimpMessageType.CONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); headers = messages.get(1).getHeaders(); assertEquals(SimpMessageType.DISCONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); assertEquals(id, headers.get(SimpMessageHeaderAccessor.SESSION_ID_HEADER)); assertEquals(user, headers.get(SimpMessageHeaderAccessor.USER_HEADER)); }
Example #19
Source File: SimpleBrokerMessageHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void writeInactivity() throws Exception { this.messageHandler.setHeartbeatValue(new long[] {1, 0}); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.start(); ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L)); Runnable heartbeatTask = taskCaptor.getValue(); assertNotNull(heartbeatTask); String id = "sess1"; TestPrincipal user = new TestPrincipal("joe"); Message<String> connectMessage = createConnectMessage(id, user, new long[] {0, 1}); this.messageHandler.handleMessage(connectMessage); Thread.sleep(10); heartbeatTask.run(); verify(this.clientOutChannel, times(2)).send(this.messageCaptor.capture()); List<Message<?>> messages = this.messageCaptor.getAllValues(); assertEquals(2, messages.size()); MessageHeaders headers = messages.get(0).getHeaders(); assertEquals(SimpMessageType.CONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); headers = messages.get(1).getHeaders(); assertEquals(SimpMessageType.HEARTBEAT, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); assertEquals(id, headers.get(SimpMessageHeaderAccessor.SESSION_ID_HEADER)); assertEquals(user, headers.get(SimpMessageHeaderAccessor.USER_HEADER)); }
Example #20
Source File: SimpleBrokerMessageHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void readInactivity() throws Exception { this.messageHandler.setHeartbeatValue(new long[] {0, 1}); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.start(); ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L)); Runnable heartbeatTask = taskCaptor.getValue(); assertNotNull(heartbeatTask); String id = "sess1"; TestPrincipal user = new TestPrincipal("joe"); Message<String> connectMessage = createConnectMessage(id, user, new long[] {1, 0}); this.messageHandler.handleMessage(connectMessage); Thread.sleep(10); heartbeatTask.run(); verify(this.clientOutboundChannel, atLeast(2)).send(this.messageCaptor.capture()); List<Message<?>> messages = this.messageCaptor.getAllValues(); assertEquals(2, messages.size()); MessageHeaders headers = messages.get(0).getHeaders(); assertEquals(SimpMessageType.CONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); headers = messages.get(1).getHeaders(); assertEquals(SimpMessageType.DISCONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER)); assertEquals(id, headers.get(SimpMessageHeaderAccessor.SESSION_ID_HEADER)); assertEquals(user, headers.get(SimpMessageHeaderAccessor.USER_HEADER)); }
Example #21
Source File: SimpleBrokerMessageHandlerTests.java From java-technology-stack with MIT License | 5 votes |
private Message<String> startSession(String id) { this.messageHandler.start(); Message<String> connectMessage = createConnectMessage(id, new TestPrincipal("joe"), null); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.handleMessage(connectMessage); verify(this.clientOutChannel, times(1)).send(this.messageCaptor.capture()); reset(this.clientOutChannel); return connectMessage; }
Example #22
Source File: StompSubProtocolHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@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")); }
Example #23
Source File: StompSubProtocolHandlerTests.java From java-technology-stack with MIT License | 5 votes |
@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()); }
Example #24
Source File: StompBrokerRelayMessageHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
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()); }
Example #25
Source File: DefaultUserDestinationResolverTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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()); }
Example #26
Source File: DefaultUserDestinationResolverTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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()); }
Example #27
Source File: DefaultUserDestinationResolverTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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()); }
Example #28
Source File: StompSubProtocolHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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()); }
Example #29
Source File: DefaultUserDestinationResolverTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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()); }
Example #30
Source File: SimpleBrokerMessageHandlerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void subcribeDisconnectPublish() { String sess1 = "sess1"; String sess2 = "sess2"; this.messageHandler.start(); this.messageHandler.handleMessage(createSubscriptionMessage(sess1, "sub1", "/foo")); this.messageHandler.handleMessage(createSubscriptionMessage(sess1, "sub2", "/foo")); this.messageHandler.handleMessage(createSubscriptionMessage(sess1, "sub3", "/bar")); this.messageHandler.handleMessage(createSubscriptionMessage(sess2, "sub1", "/foo")); this.messageHandler.handleMessage(createSubscriptionMessage(sess2, "sub2", "/foo")); this.messageHandler.handleMessage(createSubscriptionMessage(sess2, "sub3", "/bar")); SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.DISCONNECT); headers.setSessionId(sess1); headers.setUser(new TestPrincipal("joe")); Message<byte[]> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders()); this.messageHandler.handleMessage(message); this.messageHandler.handleMessage(createMessage("/foo", "message1")); this.messageHandler.handleMessage(createMessage("/bar", "message2")); verify(this.clientOutboundChannel, times(4)).send(this.messageCaptor.capture()); Message<?> captured = this.messageCaptor.getAllValues().get(0); assertEquals(SimpMessageType.DISCONNECT_ACK, SimpMessageHeaderAccessor.getMessageType(captured.getHeaders())); assertEquals(sess1, SimpMessageHeaderAccessor.getSessionId(captured.getHeaders())); assertEquals("joe", SimpMessageHeaderAccessor.getUser(captured.getHeaders()).getName()); assertTrue(messageCaptured(sess2, "sub1", "/foo")); assertTrue(messageCaptured(sess2, "sub2", "/foo")); assertTrue(messageCaptured(sess2, "sub3", "/bar")); }