use of org.springframework.messaging.simp.SimpMessageSendingOperations in project spring-framework by spring-projects.
the class WebSocketAnnotationMethodMessageHandlerTests method setUp.
@BeforeEach
public void setUp() throws Exception {
this.applicationContext = new StaticApplicationContext();
this.applicationContext.registerSingleton("controller", TestController.class);
this.applicationContext.registerSingleton("controllerAdvice", TestControllerAdvice.class);
this.applicationContext.refresh();
SubscribableChannel channel = Mockito.mock(SubscribableChannel.class);
SimpMessageSendingOperations brokerTemplate = new SimpMessagingTemplate(channel);
this.messageHandler = new TestWebSocketAnnotationMethodMessageHandler(brokerTemplate, channel, channel);
this.messageHandler.setApplicationContext(this.applicationContext);
this.messageHandler.afterPropertiesSet();
}
use of org.springframework.messaging.simp.SimpMessageSendingOperations in project spring-framework by spring-projects.
the class SendToMethodReturnValueHandlerTests method testHeadersToSend.
@Test
public void testHeadersToSend() throws Exception {
Message<?> message = createMessage("sess1", "sub1", "/app", "/dest", null);
SimpMessageSendingOperations messagingTemplate = mock(SimpMessageSendingOperations.class);
SendToMethodReturnValueHandler handler = new SendToMethodReturnValueHandler(messagingTemplate, false);
handler.handleReturnValue(PAYLOAD, this.noAnnotationsReturnType, message);
ArgumentCaptor<MessageHeaders> captor = ArgumentCaptor.forClass(MessageHeaders.class);
verify(messagingTemplate).convertAndSend(eq("/topic/dest"), eq(PAYLOAD), captor.capture());
MessageHeaders headers = captor.getValue();
SimpMessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers, SimpMessageHeaderAccessor.class);
assertThat(accessor).isNotNull();
assertThat(accessor.isMutable()).isTrue();
assertThat(accessor.getSessionId()).isEqualTo("sess1");
assertThat(accessor.getSubscriptionId()).as("Subscription id should not be copied").isNull();
assertThat(accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER)).isEqualTo(this.noAnnotationsReturnType);
}
Aggregations