Search in sources :

Example 11 with CloseFrame

use of org.eclipse.jetty.websocket.common.frames.CloseFrame in project jetty.project by eclipse.

the class CloseInfoTest method testNormal.

/**
     * A test of NORMAL (1000)
     */
@Test
public void testNormal() {
    CloseInfo close = new CloseInfo(NORMAL);
    assertThat("close.code", close.getStatusCode(), is(NORMAL));
    assertThat("close.reason", close.getReason(), nullValue());
    CloseFrame frame = close.asFrame();
    assertThat("close frame op code", frame.getOpCode(), is(OpCode.CLOSE));
    assertThat("close frame payload length", frame.getPayloadLength(), is(2));
}
Also used : CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) Test(org.junit.Test)

Example 12 with CloseFrame

use of org.eclipse.jetty.websocket.common.frames.CloseFrame in project jetty.project by eclipse.

the class CloseInfoTest method testFailedTlsHandshake.

/**
     * A test of FAILED_TLS_HANDSHAKE (1007)
     */
@Test
public void testFailedTlsHandshake() {
    CloseInfo close = new CloseInfo(FAILED_TLS_HANDSHAKE);
    assertThat("close.code", close.getStatusCode(), is(FAILED_TLS_HANDSHAKE));
    assertThat("close.reason", close.getReason(), nullValue());
    try {
        @SuppressWarnings("unused") CloseFrame frame = close.asFrame();
        fail("Expected " + ProtocolException.class.getName());
    } catch (ProtocolException e) {
        // expected path
        assertThat("ProtocolException message", e.getMessage(), containsString("not allowed (per RFC6455)"));
    }
}
Also used : ProtocolException(org.eclipse.jetty.websocket.api.ProtocolException) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) Test(org.junit.Test)

Example 13 with CloseFrame

use of org.eclipse.jetty.websocket.common.frames.CloseFrame in project jetty.project by eclipse.

the class CloseInfoTest method testNoClose.

/**
     * A test where NO_CLOSE (1006) is provided
     */
@Test
public void testNoClose() {
    CloseInfo close = new CloseInfo(NO_CLOSE);
    assertThat("close.code", close.getStatusCode(), is(NO_CLOSE));
    assertThat("close.reason", close.getReason(), nullValue());
    CloseFrame frame = close.asFrame();
    assertThat("close frame op code", frame.getOpCode(), is(OpCode.CLOSE));
    // should result in no payload
    assertThat("close frame has payload", frame.hasPayload(), is(false));
    assertThat("close frame payload length", frame.getPayloadLength(), is(0));
}
Also used : CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) Test(org.junit.Test)

Example 14 with CloseFrame

use of org.eclipse.jetty.websocket.common.frames.CloseFrame in project jetty.project by eclipse.

the class CloseInfoTest method testFromFrame.

@Test
public void testFromFrame() {
    ByteBuffer payload = asByteBuffer(NORMAL, null);
    assertThat("payload length", payload.remaining(), is(2));
    CloseFrame frame = new CloseFrame();
    frame.setPayload(payload);
    // create from frame
    CloseInfo close = new CloseInfo(frame);
    assertThat("close.code", close.getStatusCode(), is(NORMAL));
    assertThat("close.reason", close.getReason(), nullValue());
    // and back again
    frame = close.asFrame();
    assertThat("close frame op code", frame.getOpCode(), is(OpCode.CLOSE));
    assertThat("close frame payload length", frame.getPayloadLength(), is(2));
}
Also used : CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 15 with CloseFrame

use of org.eclipse.jetty.websocket.common.frames.CloseFrame in project jetty.project by eclipse.

the class CloseInfoTest method testNoCode.

/**
     * A test where NO_CODE (1005) is provided
     */
@Test
public void testNoCode() {
    CloseInfo close = new CloseInfo(NO_CODE);
    assertThat("close.code", close.getStatusCode(), is(NO_CODE));
    assertThat("close.reason", close.getReason(), nullValue());
    CloseFrame frame = close.asFrame();
    assertThat("close frame op code", frame.getOpCode(), is(OpCode.CLOSE));
    // should result in no payload
    assertThat("close frame has payload", frame.hasPayload(), is(false));
    assertThat("close frame payload length", frame.getPayloadLength(), is(0));
}
Also used : CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) Test(org.junit.Test)

Aggregations

CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)20 Test (org.junit.Test)15 ByteBuffer (java.nio.ByteBuffer)10 ArrayList (java.util.ArrayList)6 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)6 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)6 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)4 ProtocolException (org.eclipse.jetty.websocket.api.ProtocolException)3 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)2 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)2 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)2 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)2 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)2 NotUtf8Exception (org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception)1 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)1 CloseException (org.eclipse.jetty.websocket.api.CloseException)1