@Test public void testPerformOpeningHandshake() { Channel channelMock = EasyMock.createMock(Channel.class); DefaultChannelPipeline pipeline = createPipeline(channelMock); EasyMock.expect(channelMock.pipeline()).andReturn(pipeline); // capture the http response in order to verify the headers Capture<HttpResponse> res = new Capture<HttpResponse>(); EasyMock.expect(channelMock.write(capture(res))) .andReturn(new DefaultChannelFuture(channelMock, true)); replay(channelMock); HttpRequest req = new DefaultHttpRequest(HTTP_1_1, HttpMethod.GET, "/chat"); req.setHeader(Names.HOST, "server.example.com"); req.setHeader(Names.UPGRADE, WEBSOCKET.toLowerCase()); req.setHeader(Names.CONNECTION, "Upgrade"); req.setHeader(Names.SEC_WEBSOCKET_KEY, "dGhlIHNhbXBsZSBub25jZQ=="); req.setHeader(Names.SEC_WEBSOCKET_ORIGIN, "http://example.com"); req.setHeader(Names.SEC_WEBSOCKET_PROTOCOL, "chat, superchat"); req.setHeader(Names.SEC_WEBSOCKET_VERSION, "13"); WebSocketServerHandshaker13 handsaker = new WebSocketServerHandshaker13("ws://example.com/chat", "chat", false, Integer.MAX_VALUE); handsaker.handshake(channelMock, req); Assert.assertEquals( "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.getValue().getHeader(Names.SEC_WEBSOCKET_ACCEPT)); Assert.assertEquals("chat", res.getValue().getHeader(Names.SEC_WEBSOCKET_PROTOCOL)); }