Home / Class/ WebSocketUtf8FrameValidatorTest Class — netty Architecture

WebSocketUtf8FrameValidatorTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  5afab092_8064_6a0f_9ed4_1e250f5e1864["WebSocketUtf8FrameValidatorTest"]
  0e621966_a390_255d_2438_d99427b65e37["WebSocketUtf8FrameValidatorTest.java"]
  5afab092_8064_6a0f_9ed4_1e250f5e1864 -->|defined in| 0e621966_a390_255d_2438_d99427b65e37
  46156f08_5673_a12e_74ce_f8d4501fc82b["testCorruptedFrameExceptionInFinish()"]
  5afab092_8064_6a0f_9ed4_1e250f5e1864 -->|method| 46156f08_5673_a12e_74ce_f8d4501fc82b
  f1f644d2_4cd9_2bc1_ce04_4163d43765a8["testCorruptedFrameExceptionInCheck()"]
  5afab092_8064_6a0f_9ed4_1e250f5e1864 -->|method| f1f644d2_4cd9_2bc1_ce04_4163d43765a8
  44b1aa56_9599_c486_92ef_e9d0d005e327["testNotCloseOnProtocolViolation()"]
  5afab092_8064_6a0f_9ed4_1e250f5e1864 -->|method| 44b1aa56_9599_c486_92ef_e9d0d005e327
  075307d9_7dd0_b9cd_2ddc_c08b5b2f727c["assertCorruptedFrameExceptionHandling()"]
  5afab092_8064_6a0f_9ed4_1e250f5e1864 -->|method| 075307d9_7dd0_b9cd_2ddc_c08b5b2f727c
  4465a9b4_f855_1e65_4b93_458fca5d3b29["testCloseWithStatusInTheMiddleOfFragmentAllowed()"]
  5afab092_8064_6a0f_9ed4_1e250f5e1864 -->|method| 4465a9b4_f855_1e65_4b93_458fca5d3b29
  3b02e38e_b43b_54f0_01a8_b99abf74f451["testPingInTheMiddleOfFragmentAllowed()"]
  5afab092_8064_6a0f_9ed4_1e250f5e1864 -->|method| 3b02e38e_b43b_54f0_01a8_b99abf74f451
  fb2b533a_7a42_ed94_a704_43f5b0f0e67d["testPongInTheMiddleOfFragmentAllowed()"]
  5afab092_8064_6a0f_9ed4_1e250f5e1864 -->|method| fb2b533a_7a42_ed94_a704_43f5b0f0e67d
  24378039_d1c3_e383_ad9b_907fe444ebde["testControlFrameInTheMiddleOfFragmentAllowed()"]
  5afab092_8064_6a0f_9ed4_1e250f5e1864 -->|method| 24378039_d1c3_e383_ad9b_907fe444ebde

Relationship Graph

Source Code

codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketUtf8FrameValidatorTest.java lines 29–101

public class WebSocketUtf8FrameValidatorTest {

    @Test
    public void testCorruptedFrameExceptionInFinish() {
        assertCorruptedFrameExceptionHandling(new byte[]{-50});
    }

    @Test
    public void testCorruptedFrameExceptionInCheck() {
        assertCorruptedFrameExceptionHandling(new byte[]{-8, -120, -128, -128, -128});
    }

    @Test
    void testNotCloseOnProtocolViolation() {
        final EmbeddedChannel channel = new EmbeddedChannel(new Utf8FrameValidator(false));
        final TextWebSocketFrame frame = new TextWebSocketFrame(Unpooled.copiedBuffer(new byte[] { -50 }));
        assertThrows(CorruptedWebSocketFrameException.class, new Executable() {
            @Override
            public void execute() throws Throwable {
                channel.writeInbound(frame);
            }
        }, "bytes are not UTF-8");

        assertTrue(channel.isActive());
        assertFalse(channel.finish());
        assertEquals(0, frame.refCnt());
    }

    private void assertCorruptedFrameExceptionHandling(byte[] data) {
        final EmbeddedChannel channel = new EmbeddedChannel(new Utf8FrameValidator());
        final TextWebSocketFrame frame = new TextWebSocketFrame(Unpooled.copiedBuffer(data));
        assertThrows(CorruptedWebSocketFrameException.class, new Executable() {
            @Override
            public void execute() throws Throwable {
                channel.writeInbound(frame);
            }
        }, "bytes are not UTF-8");

        assertFalse(channel.isActive());

        CloseWebSocketFrame closeFrame = channel.readOutbound();
        assertNotNull(closeFrame);
        assertEquals("bytes are not UTF-8", closeFrame.reasonText());
        assertEquals(1007, closeFrame.statusCode());
        assertTrue(closeFrame.release());

        assertEquals(0, frame.refCnt());
        assertFalse(channel.finish());
    }

    @Test
    void testCloseWithStatusInTheMiddleOfFragmentAllowed() {
        testControlFrameInTheMiddleOfFragmentAllowed(new CloseWebSocketFrame(WebSocketCloseStatus.NORMAL_CLOSURE));
    }

    @Test
    void testPingInTheMiddleOfFragmentAllowed() {
        testControlFrameInTheMiddleOfFragmentAllowed(new PingWebSocketFrame(Unpooled.EMPTY_BUFFER));
    }

    @Test
    void testPongInTheMiddleOfFragmentAllowed() {
        testControlFrameInTheMiddleOfFragmentAllowed(new PongWebSocketFrame(Unpooled.EMPTY_BUFFER));
    }

    private static void testControlFrameInTheMiddleOfFragmentAllowed(WebSocketFrame controlFrame) {
        final EmbeddedChannel channel = new EmbeddedChannel(new Utf8FrameValidator(false));
        final TextWebSocketFrame frame = new TextWebSocketFrame(false, 0, "text");
        assertTrue(channel.writeInbound(frame));
        assertTrue(channel.writeInbound(controlFrame));
        assertTrue(channel.finishAndReleaseAll());
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free