DeflateFrameClientExtensionHandshaker implements WebSocketClientExtensionHandshaker { @Override public WebSocketClientExtension handshakeExtension(WebSocketExtensionData extensionData) { if (!X_WEBKIT_DEFLATE_FRAME_EXTENSION.equals(extensionData.name()) && !DEFLATE_FRAME_EXTENSION.equals(extensionData.name())) { return null; } if (extensionData.parameters().isEmpty()) { return new DeflateFrameClientExtension(compressionLevel); } else { return null; } } DeflateFrameClientExtensionHandshaker(boolean useWebkitExtensionName);  DeflateFrameClientExtensionHandshaker(int compressionLevel, boolean useWebkitExtensionName); @Override WebSocketExtensionData newRequestData(); @Override WebSocketClientExtension handshakeExtension(WebSocketExtensionData extensionData);  }
@Test public void testNormalHandshake() { DeflateFrameClientExtensionHandshaker handshaker = new DeflateFrameClientExtensionHandshaker(false); WebSocketClientExtension extension = handshaker.handshakeExtension( new WebSocketExtensionData(DEFLATE_FRAME_EXTENSION, Collections.<String, String>emptyMap())); assertNotNull(extension); assertEquals(WebSocketClientExtension.RSV1, extension.rsv()); assertTrue(extension.newExtensionDecoder() instanceof PerFrameDeflateDecoder); assertTrue(extension.newExtensionEncoder() instanceof PerFrameDeflateEncoder); }
@Test public void testFailedHandshake() { DeflateFrameClientExtensionHandshaker handshaker = new DeflateFrameClientExtensionHandshaker(false); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("invalid", "12"); WebSocketClientExtension extension = handshaker.handshakeExtension( new WebSocketExtensionData(DEFLATE_FRAME_EXTENSION, parameters)); assertNull(extension); }