use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class EventDriverTest method testListenerPingPong.
@Test
public void testListenerPingPong() throws Exception {
ListenerPingPongSocket socket = new ListenerPingPongSocket();
EventDriver driver = wrap(socket);
try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
conn.start();
conn.open();
driver.incomingFrame(new PingFrame().setPayload("PING"));
driver.incomingFrame(new PongFrame().setPayload("PONG"));
driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
socket.capture.assertEventCount(4);
socket.capture.pop().assertEventStartsWith("onWebSocketConnect");
socket.capture.pop().assertEventStartsWith("onWebSocketPing(");
socket.capture.pop().assertEventStartsWith("onWebSocketPong(");
socket.capture.pop().assertEventStartsWith("onWebSocketClose(1000,");
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class EventDriverTest method testAnnotated_Error.
@Test
public void testAnnotated_Error() throws Exception {
AnnotatedTextSocket socket = new AnnotatedTextSocket();
EventDriver driver = wrap(socket);
try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
conn.open();
driver.incomingError(new WebSocketException("oof"));
driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
socket.capture.assertEventCount(3);
socket.capture.pop().assertEventStartsWith("onConnect");
socket.capture.pop().assertEventStartsWith("onError(WebSocketException: oof)");
socket.capture.pop().assertEventStartsWith("onClose(1000,");
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase7_3 method testCase7_3_5GenerateCloseWithStatusMaxReason.
@Test
public void testCase7_3_5GenerateCloseWithStatusMaxReason() {
StringBuilder message = new StringBuilder();
for (int i = 0; i < 123; ++i) {
message.append("*");
}
CloseInfo close = new CloseInfo(1000, message.toString());
ByteBuffer actual = UnitGenerator.generate(close.asFrame());
ByteBuffer expected = ByteBuffer.allocate(132);
byte[] messageBytes = message.toString().getBytes(StandardCharsets.UTF_8);
expected.put(new byte[] { (byte) 0x88 });
// no masking
byte b = 0x00;
b |= (messageBytes.length + 2) & 0x7F;
expected.put(b);
expected.putShort((short) 1000);
expected.put(messageBytes);
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase7_3 method testCase7_3_4GenerateCloseWithStatusReason.
@Test
public void testCase7_3_4GenerateCloseWithStatusReason() {
String message = "bad cough";
byte[] messageBytes = message.getBytes();
CloseInfo close = new CloseInfo(1000, message);
ByteBuffer actual = UnitGenerator.generate(close.asFrame());
ByteBuffer expected = ByteBuffer.allocate(32);
expected.put(new byte[] { (byte) 0x88 });
// no masking
byte b = 0x00;
b |= (message.length() + 2) & 0x7F;
expected.put(b);
expected.putShort((short) 1000);
expected.put(messageBytes);
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase7_3 method testCase7_3_3GenerateCloseWithStatus.
@Test
public void testCase7_3_3GenerateCloseWithStatus() {
CloseInfo close = new CloseInfo(1000);
ByteBuffer actual = UnitGenerator.generate(close.asFrame());
ByteBuffer expected = ByteBuffer.allocate(5);
expected.put(new byte[] { (byte) 0x88, (byte) 0x02, 0x03, (byte) 0xe8 });
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Aggregations