Search in sources :

Example 1 with SimpMessageSendingOperations

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();
}
Also used : SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) SimpMessageSendingOperations(org.springframework.messaging.simp.SimpMessageSendingOperations) SubscribableChannel(org.springframework.messaging.SubscribableChannel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SimpMessageSendingOperations

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);
}
Also used : SimpMessageSendingOperations(org.springframework.messaging.simp.SimpMessageSendingOperations) MessageHeaders(org.springframework.messaging.MessageHeaders) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.jupiter.api.Test)

Aggregations

SimpMessageSendingOperations (org.springframework.messaging.simp.SimpMessageSendingOperations)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1 MessageHeaders (org.springframework.messaging.MessageHeaders)1 SubscribableChannel (org.springframework.messaging.SubscribableChannel)1 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)1 SimpMessagingTemplate (org.springframework.messaging.simp.SimpMessagingTemplate)1