Package org.springframework.web.socket.handler

Examples of org.springframework.web.socket.handler.TestWebSocketSession



  @Before
  public void setup() {
    super.setUp();
    this.webSocketSession = new TestWebSocketSession();
    this.webSocketSession.setOpen(true);
  }
View Full Code Here


  public void setup() {
    this.protocolHandler = new StompSubProtocolHandler();
    this.channel = Mockito.mock(MessageChannel.class);
    this.messageCaptor = ArgumentCaptor.forClass(Message.class);

    this.session = new TestWebSocketSession();
    this.session.setId("s1");
    this.session.setPrincipal(new TestPrincipal("joe"));
  }
View Full Code Here

  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");
  }
View Full Code Here

    this.webSocketHandler.afterConnectionEstablished(session);
  }

  @Test
  public void checkSession() throws Exception {
    TestWebSocketSession session1 = new TestWebSocketSession("id1");
    TestWebSocketSession session2 = new TestWebSocketSession("id2");
    session1.setAcceptedProtocol("v12.stomp");
    session2.setAcceptedProtocol("v12.stomp");

    this.webSocketHandler.setProtocolHandlers(Arrays.asList(this.stompHandler));
    this.webSocketHandler.afterConnectionEstablished(session1);
    this.webSocketHandler.afterConnectionEstablished(session2);
    session1.setOpen(true);
    session2.setOpen(true);

    long sixtyOneSecondsAgo = System.currentTimeMillis() - 61 * 1000;
    new DirectFieldAccessor(this.webSocketHandler).setPropertyValue("lastSessionCheckTime", sixtyOneSecondsAgo);
    Map<String, ?> sessions = (Map<String, ?>) new DirectFieldAccessor(this.webSocketHandler).getPropertyValue("sessions");
    new DirectFieldAccessor(sessions.get("id1")).setPropertyValue("createTime", sixtyOneSecondsAgo);
    new DirectFieldAccessor(sessions.get("id2")).setPropertyValue("createTime", sixtyOneSecondsAgo);

    this.webSocketHandler.start();
    this.webSocketHandler.handleMessage(session1, new TextMessage("foo"));

    assertTrue(session1.isOpen());
    assertFalse(session2.isOpen());
    assertNull(session1.getCloseStatus());
    assertEquals(CloseStatus.SESSION_NOT_RELIABLE, session2.getCloseStatus());
  }
View Full Code Here

    assertTrue(handshakeHandler instanceof TestHandshakeHandler);
    List<HandshakeInterceptor> interceptors = wsHttpRequestHandler.getHandshakeInterceptors();
    assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
        instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));

    WebSocketSession session = new TestWebSocketSession("id");
    wsHttpRequestHandler.getWebSocketHandler().afterConnectionEstablished(session);
    assertEquals(true, session.getAttributes().get("decorated"));

    WebSocketHandler wsHandler = unwrapWebSocketHandler(wsHttpRequestHandler.getWebSocketHandler());
    assertNotNull(wsHandler);
    assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
View Full Code Here

    SubProtocolWebSocketHandler webSocketHandler = config.getBean(SubProtocolWebSocketHandler.class);

    List<ChannelInterceptor> interceptors = channel.getInterceptors();
    assertEquals(ImmutableMessageChannelInterceptor.class, interceptors.get(interceptors.size()-1).getClass());

    WebSocketSession session = new TestWebSocketSession("s1");
    webSocketHandler.afterConnectionEstablished(session);

    TextMessage textMessage = StompTextMessageBuilder.create(StompCommand.SEND).headers("destination:/foo").build();
    webSocketHandler.handleMessage(session, textMessage);
View Full Code Here

    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"));
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.socket.handler.TestWebSocketSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.