Search in sources :

Example 6 with TestWebSocketSession

use of org.springframework.web.socket.handler.TestWebSocketSession in project spring-framework by spring-projects.

the class SubProtocolWebSocketHandlerTests method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    this.webSocketHandler = new SubProtocolWebSocketHandler(this.inClientChannel, this.outClientChannel);
    given(stompHandler.getSupportedProtocols()).willReturn(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"));
    given(mqttHandler.getSupportedProtocols()).willReturn(Arrays.asList("MQTT"));
    this.session = new TestWebSocketSession();
    this.session.setId("1");
    this.session.setOpen(true);
}
Also used : TestWebSocketSession(org.springframework.web.socket.handler.TestWebSocketSession) Before(org.junit.Before)

Example 7 with TestWebSocketSession

use of org.springframework.web.socket.handler.TestWebSocketSession in project spring-framework by spring-projects.

the class WebSocketMessageBrokerConfigurationSupportTests method webSocketHandlerDecorator.

@Test
public void webSocketHandlerDecorator() throws Exception {
    ApplicationContext config = createConfig(WebSocketHandlerDecoratorConfig.class);
    WebSocketHandler handler = config.getBean(SubProtocolWebSocketHandler.class);
    assertNotNull(handler);
    SimpleUrlHandlerMapping mapping = (SimpleUrlHandlerMapping) config.getBean("stompWebSocketHandlerMapping");
    WebSocketHttpRequestHandler httpHandler = (WebSocketHttpRequestHandler) mapping.getHandlerMap().get("/test");
    handler = httpHandler.getWebSocketHandler();
    WebSocketSession session = new TestWebSocketSession("id");
    handler.afterConnectionEstablished(session);
    assertEquals(true, session.getAttributes().get("decorated"));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) TestWebSocketSession(org.springframework.web.socket.handler.TestWebSocketSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) SubProtocolWebSocketHandler(org.springframework.web.socket.messaging.SubProtocolWebSocketHandler) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) WebSocketSession(org.springframework.web.socket.WebSocketSession) TestWebSocketSession(org.springframework.web.socket.handler.TestWebSocketSession) Test(org.junit.Test)

Aggregations

TestWebSocketSession (org.springframework.web.socket.handler.TestWebSocketSession)7 Test (org.junit.Test)4 Before (org.junit.Before)3 TextMessage (org.springframework.web.socket.TextMessage)3 SubProtocolWebSocketHandler (org.springframework.web.socket.messaging.SubProtocolWebSocketHandler)3 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 ApplicationContext (org.springframework.context.ApplicationContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)2 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)2 WebSocketSession (org.springframework.web.socket.WebSocketSession)2 WebSocketHttpRequestHandler (org.springframework.web.socket.server.support.WebSocketHttpRequestHandler)2 Map (java.util.Map)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 CustomScopeConfigurer (org.springframework.beans.factory.config.CustomScopeConfigurer)1 Message (org.springframework.messaging.Message)1 MessageChannel (org.springframework.messaging.MessageChannel)1 MessageHandler (org.springframework.messaging.MessageHandler)1 TestPrincipal (org.springframework.messaging.simp.TestPrincipal)1 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)1