WebSocketNativeHandshakeHandler extends WebSocketHandlerAdapter { @Override public void processConnect(WebSocketChannel channel, WSURI uri, String[] protocols) { LOG.entering(CLASS_NAME, "connect", new Object[]{uri, protocols}); String[] nextProtocols; if (protocols == null || protocols.length == 0) { nextProtocols = new String[] { WebSocketHandshakeObject.KAAZING_EXTENDED_HANDSHAKE }; } else { nextProtocols = new String[protocols.length+1]; nextProtocols[0] = WebSocketHandshakeObject.KAAZING_EXTENDED_HANDSHAKE; for (int i=0; i<protocols.length; i++) { nextProtocols[i+1] = protocols[i]; } } nextHandler.processConnect(channel, uri, nextProtocols); } WebSocketNativeHandshakeHandler(); @Override void processConnect(WebSocketChannel channel, WSURI uri, String[] protocols); @Override void processAuthorize(WebSocketChannel channel, String authorizeToken); @Override void setNextHandler(final WebSocketHandler handler);  }
@Test public void testProcessConnect() throws URISyntaxException, Exception { Mockery context = new Mockery(); final WebSocketHandler nextHandler = context.mock(WebSocketHandler.class); final WebSocketHandlerListener listener = context.mock(WebSocketHandlerListener.class); context.checking(new Expectations() { { oneOf(nextHandler).setListener(with(aNonNull(WebSocketHandlerListener.class))); will(saveParameter("listener", 0)); oneOf(nextHandler).processConnect(with(aNonNull(WebSocketChannel.class)), with(aNonNull(WSURI.class)), with(equal(new String[] {"x-kaazing-handshake", "foo"}))); will(new CustomAction("will fire connectionOpen") { @Override public Object invoke(Invocation invocation) { WebSocketHandlerListener listener = (WebSocketHandlerListener)lookup("listener"); WebSocketChannel channel = (WebSocketChannel)invocation.getParameter(0); listener.connectionOpened(channel, "foo"); return null; } }); oneOf(listener).connectionOpened(with(aNonNull(WebSocketChannel.class)), with(aNull(String.class))); } }); WSURI uri = new WSURI("ws: WebSocketChannel channel = createNativeChannel(uri); WebSocketNativeHandshakeHandler handler = new WebSocketNativeHandshakeHandler(); handler.setNextHandler(nextHandler); handler.setListener(listener); handler.processConnect(channel, uri, new String[] {"foo"}); context.assertIsSatisfied(); }