Home / Class/ WebSocketServerProtocolHandlerTest Class — netty Architecture

WebSocketServerProtocolHandlerTest Class — netty Architecture

Architecture documentation for the WebSocketServerProtocolHandlerTest class in WebSocketServerProtocolHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  7afc952d_7109_096b_f81d_bf3293e37581["WebSocketServerProtocolHandlerTest"]
  be0e257a_741a_5c7f_593d_0534daf86a59["WebSocketServerProtocolHandlerTest.java"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|defined in| be0e257a_741a_5c7f_593d_0534daf86a59
  37fd3e8f_9f62_9300_b987_c9a465534987["setUp()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| 37fd3e8f_9f62_9300_b987_c9a465534987
  91ce99b1_e335_e375_fe9e_cc717868379b["testHttpUpgradeRequestFull()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| 91ce99b1_e335_e375_fe9e_cc717868379b
  bad1f52c_fb80_51d5_0471_2b05b6c6c86d["testHttpUpgradeRequestNonFull()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| bad1f52c_fb80_51d5_0471_2b05b6c6c86d
  e39e5cc5_b5e7_302c_1168_3c2e459c4003["testHttpUpgradeRequest0()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| e39e5cc5_b5e7_302c_1168_3c2e459c4003
  f515d385_d4a3_a1fe_bca9_82e54f5a5af3["testWebSocketServerProtocolHandshakeHandlerReplacedBeforeHandshake()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| f515d385_d4a3_a1fe_bca9_82e54f5a5af3
  9347a476_c384_e3d7_5be7_b167d7509a97["testHttpUpgradeRequestInvalidUpgradeHeader()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| 9347a476_c384_e3d7_5be7_b167d7509a97
  bd5c87f6_81ae_fccc_d5ef_77abe1e0e6e1["testHttpUpgradeRequestMissingWSKeyHeader()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| bd5c87f6_81ae_fccc_d5ef_77abe1e0e6e1
  bccac56d_f218_d352_47bd_9f365425b97c["testCreateUTF8Validator()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| bccac56d_f218_d352_47bd_9f365425b97c
  b7a0fac2_887f_0b3e_ff2c_a4dd93270712["testDoNotCreateUTF8Validator()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| b7a0fac2_887f_0b3e_ff2c_a4dd93270712
  3e43da83_ebd0_8c2d_4db5_151262971455["testHandleTextFrame()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| 3e43da83_ebd0_8c2d_4db5_151262971455
  efaee56c_a4ba_56bf_fab7_4caa5e94692f["testCheckWebSocketPathStartWithSlash()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| efaee56c_a4ba_56bf_fab7_4caa5e94692f
  8c8de3ea_ff5c_f8bf_252e_bf28c1f471a0["testCheckValidWebSocketPath()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| 8c8de3ea_ff5c_f8bf_252e_bf28c1f471a0
  f7db3d74_d600_26b2_58d7_6d4d1832dedf["testCheckInvalidWebSocketPath()"]
  7afc952d_7109_096b_f81d_bf3293e37581 -->|method| f7db3d74_d600_26b2_58d7_6d4d1832dedf

Relationship Graph

Source Code

codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java lines 56–519

public class WebSocketServerProtocolHandlerTest {

    private final Queue<FullHttpResponse> responses = new ArrayDeque<FullHttpResponse>();

    @BeforeEach
    public void setUp() {
        responses.clear();
    }

    @Test
    public void testHttpUpgradeRequestFull() {
        testHttpUpgradeRequest0(true);
    }

    @Test
    public void testHttpUpgradeRequestNonFull() {
        testHttpUpgradeRequest0(false);
    }

    private void testHttpUpgradeRequest0(boolean full) {
        EmbeddedChannel ch = createChannel(new MockOutboundHandler());
        ChannelHandlerContext handshakerCtx = ch.pipeline().context(WebSocketServerProtocolHandshakeHandler.class);
        writeUpgradeRequest(ch, full);

        FullHttpResponse response = responses.remove();
        assertEquals(SWITCHING_PROTOCOLS, response.status());
        response.release();
        assertNotNull(WebSocketServerProtocolHandler.getHandshaker(handshakerCtx.channel()));
        assertFalse(ch.finish());
    }

    @Test
    public void testWebSocketServerProtocolHandshakeHandlerReplacedBeforeHandshake() {
        EmbeddedChannel ch = createChannel(new MockOutboundHandler());
        ChannelHandlerContext handshakerCtx = ch.pipeline().context(WebSocketServerProtocolHandshakeHandler.class);
        ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
            @Override
            public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
                if (evt instanceof WebSocketServerProtocolHandler.HandshakeComplete) {
                    // We should have removed the handler already.
                    assertNull(ctx.pipeline().context(WebSocketServerProtocolHandshakeHandler.class));
                }
            }
        });
        writeUpgradeRequest(ch);

        FullHttpResponse response = responses.remove();
        assertEquals(SWITCHING_PROTOCOLS, response.status());
        response.release();
        assertNotNull(WebSocketServerProtocolHandler.getHandshaker(handshakerCtx.channel()));
        assertFalse(ch.finish());
    }

    @Test
    public void testHttpUpgradeRequestInvalidUpgradeHeader() {
        EmbeddedChannel ch = createChannel();
        FullHttpRequest httpRequestWithEntity = new WebSocketRequestBuilder().httpVersion(HTTP_1_1)
                .method(HttpMethod.GET)
                .uri("/test")
                .connection("Upgrade")
                .version00()
                .upgrade("BogusSocket")
                .build();

        ch.writeInbound(httpRequestWithEntity);

        FullHttpResponse response = responses.remove();
        assertEquals(BAD_REQUEST, response.status());
        assertEquals("not a WebSocket handshake request: missing upgrade", getResponseMessage(response));
        response.release();
        assertFalse(ch.finish());
    }

    @Test
    public void testHttpUpgradeRequestMissingWSKeyHeader() {
        EmbeddedChannel ch = createChannel();
        HttpRequest httpRequest = new WebSocketRequestBuilder().httpVersion(HTTP_1_1)
                .method(HttpMethod.GET)
                .uri("/test")
                .key(null)
                .connection("Upgrade")

Frequently Asked Questions

What is the WebSocketServerProtocolHandlerTest class?
WebSocketServerProtocolHandlerTest is a class in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java.
Where is WebSocketServerProtocolHandlerTest defined?
WebSocketServerProtocolHandlerTest is defined in codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandlerTest.java at line 56.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free