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));
}
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)"));
}
}
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));
}
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));
}
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));
}
Aggregations