use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.
the class TestABCase1_2 method testParse65535ByteBinaryCase1_2_6.
@Test
public void testParse65535ByteBinaryCase1_2_6() {
int length = 65535;
ByteBuffer expected = ByteBuffer.allocate(length + 5);
expected.put(new byte[] { (byte) 0x82 });
// no masking
byte b = 0x00;
b |= 0x7E;
expected.put(b);
expected.put(new byte[] { (byte) 0xff, (byte) 0xff });
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
expected.flip();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
policy.setMaxBinaryMessageSize(length);
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(expected);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.BINARY, 1);
Frame pActual = capture.getFrames().poll();
Assert.assertThat("BinaryFrame.payloadLength", pActual.getPayloadLength(), is(length));
// Assert.assertEquals("BinaryFrame.payload",length,pActual.getPayloadData().length);
}
use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.
the class TestABCase1_2 method testParse125ByteBinaryCase1_2_2.
@Test
public void testParse125ByteBinaryCase1_2_2() {
int length = 125;
ByteBuffer expected = ByteBuffer.allocate(length + 5);
expected.put(new byte[] { (byte) 0x82 });
// no masking
byte b = 0x00;
b |= length & 0x7F;
expected.put(b);
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
expected.flip();
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(expected);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.BINARY, 1);
Frame pActual = capture.getFrames().poll();
Assert.assertThat("BinaryFrame.payloadLength", pActual.getPayloadLength(), is(length));
// Assert.assertEquals("BinaryFrame.payload",length,pActual.getPayloadData().length);
}
use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.
the class TestABCase1_2 method testParseEmptyBinaryCase1_2_1.
@Test
public void testParseEmptyBinaryCase1_2_1() {
ByteBuffer expected = ByteBuffer.allocate(5);
expected.put(new byte[] { (byte) 0x82, (byte) 0x00 });
expected.flip();
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(expected);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.BINARY, 1);
Frame pActual = capture.getFrames().poll();
Assert.assertThat("BinaryFrame.payloadLength", pActual.getPayloadLength(), is(0));
// Assert.assertNull("BinaryFrame.payload",pActual.getPayloadData());
}
use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.
the class ClientCloseTest method confirmServerReceivedCloseFrame.
private void confirmServerReceivedCloseFrame(IBlockheadServerConnection serverConn, int expectedCloseCode, Matcher<String> closeReasonMatcher) throws IOException, TimeoutException {
IncomingFramesCapture serverCapture = serverConn.readFrames(1, 30, TimeUnit.SECONDS);
serverCapture.assertNoErrors();
serverCapture.assertFrameCount(1);
serverCapture.assertHasFrame(OpCode.CLOSE, 1);
WebSocketFrame frame = serverCapture.getFrames().poll();
assertThat("Server received close frame", frame.getOpCode(), is(OpCode.CLOSE));
CloseInfo closeInfo = new CloseInfo(frame);
assertThat("Server received close code", closeInfo.getStatusCode(), is(expectedCloseCode));
if (closeReasonMatcher == null) {
assertThat("Server received close reason", closeInfo.getReason(), nullValue());
} else {
assertThat("Server received close reason", closeInfo.getReason(), closeReasonMatcher);
}
}
use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.
the class IdentityExtensionTest method testIncomingFrames.
/**
* Verify that incoming frames are unmodified
*/
@Test
public void testIncomingFrames() {
IncomingFramesCapture capture = new IncomingFramesCapture();
Extension ext = new IdentityExtension();
ext.setNextIncomingFrames(capture);
Frame frame = new TextFrame().setPayload("hello");
ext.incomingFrame(frame);
capture.assertFrameCount(1);
capture.assertHasFrame(OpCode.TEXT, 1);
WebSocketFrame actual = capture.getFrames().poll();
Assert.assertThat("Frame.opcode", actual.getOpCode(), is(OpCode.TEXT));
Assert.assertThat("Frame.fin", actual.isFin(), is(true));
Assert.assertThat("Frame.rsv1", actual.isRsv1(), is(false));
Assert.assertThat("Frame.rsv2", actual.isRsv2(), is(false));
Assert.assertThat("Frame.rsv3", actual.isRsv3(), is(false));
ByteBuffer expected = BufferUtil.toBuffer("hello", StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength", actual.getPayloadLength(), is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload", expected, actual.getPayload().slice());
}
Aggregations