use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework-debug by Joker-5.
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);
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
assertThat(actual.getPayload()).isEqualTo("\n");
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework-debug by Joker-5.
the class WebSocketAnnotationMethodMessageHandlerTests method globalException.
@Test
public void globalException() throws Exception {
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
headers.setSessionId("session1");
headers.setSessionAttributes(new ConcurrentHashMap<>());
headers.setDestination("/exception");
Message<?> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
this.messageHandler.handleMessage(message);
TestControllerAdvice controllerAdvice = this.applicationContext.getBean(TestControllerAdvice.class);
assertThat(controllerAdvice.isExceptionHandled()).isTrue();
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework-debug by Joker-5.
the class DefaultSimpUserRegistryTests method createMessage.
private Message<byte[]> createMessage(SimpMessageType type, String sessionId, String subscriptionId, String destination) {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(type);
accessor.setSessionId(sessionId);
if (destination != null) {
accessor.setDestination(destination);
}
if (subscriptionId != null) {
accessor.setSubscriptionId(subscriptionId);
}
return MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders());
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework-debug by Joker-5.
the class SendToMethodReturnValueHandlerTests method sendToUserDefaultDestination.
@Test
public void sendToUserDefaultDestination() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1";
TestUser user = new TestUser();
Message<?> inputMessage = createMessage(sessionId, "sub1", "/app", "/dest", user);
this.handler.handleReturnValue(PAYLOAD, this.sendToUserDefaultDestReturnType, inputMessage);
verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
assertThat(accessor.getSessionId()).isNull();
assertThat(accessor.getSubscriptionId()).isNull();
assertThat(accessor.getDestination()).isEqualTo(("/user/" + user.getName() + "/queue/dest"));
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework-debug by Joker-5.
the class SendToMethodReturnValueHandlerTests method sendToUserWithUserNameProvider.
@Test
public void sendToUserWithUserNameProvider() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1";
TestUser user = new UniqueUser();
Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, user);
this.handler.handleReturnValue(PAYLOAD, this.sendToUserReturnType, inputMessage);
verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());
SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
assertThat(accessor.getDestination()).isEqualTo("/user/Me myself and I/dest1");
accessor = getCapturedAccessor(1);
assertThat(accessor.getDestination()).isEqualTo("/user/Me myself and I/dest2");
}
Aggregations