@Test
public void testOutgoingFragmentedMessage() throws InterruptedException {

    PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
    ext.setPolicy(WebSocketPolicy.newServerPolicy());
    ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
    ext.setConfig(config);
    // Setup capture of outgoing frames
    OutgoingFramesCapture capture = new OutgoingFramesCapture();
    // Wire up stack
    ext.setNextOutgoingFrames(capture);
    Frame txtFrame = new TextFrame().setPayload("Hello ").setFin(false);
    Frame con1Frame = new ContinuationFrame().setPayload("World").setFin(false);
    Frame con2Frame = new ContinuationFrame().setPayload("!").setFin(true);
    ext.outgoingFrame(txtFrame, null);
    ext.outgoingFrame(con1Frame, null);
    ext.outgoingFrame(con2Frame, null);
    capture.assertFrameCount(3);
    WebSocketFrame capturedFrame;
    capturedFrame = capture.getFrames().poll(1, TimeUnit.SECONDS);
    assertEquals(OpCode.TEXT, capturedFrame.getOpCode());
    assertFalse(capturedFrame.isFin());
    assertTrue(capturedFrame.isRsv1());
    assertFalse(capturedFrame.isRsv2());
    assertFalse(capturedFrame.isRsv3());
    capturedFrame = capture.getFrames().poll(1, TimeUnit.SECONDS);
    assertEquals(OpCode.CONTINUATION, capturedFrame.getOpCode());
    assertFalse(capturedFrame.isFin());
    assertFalse(capturedFrame.isRsv1());
    assertFalse(capturedFrame.isRsv2());
    assertFalse(capturedFrame.isRsv3());
    capturedFrame = capture.getFrames().poll(1, TimeUnit.SECONDS);
    assertEquals(OpCode.CONTINUATION, capturedFrame.getOpCode());
    assertTrue(capturedFrame.isFin());
    assertFalse(capturedFrame.isRsv1());
    assertFalse(capturedFrame.isRsv2());
    assertFalse(capturedFrame.isRsv3());
}