@Test
public void multipleWebSocketAndHandler() throws IOException, ServletException, ExecutionException, InterruptedException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault()
.getWebSocketProcessor(framework);
registerWebSocketHandler("/a", new WebSocketProcessor.WebSocketHandlerProxy(new EchoHandler()));
registerWebSocketHandler("/b", new WebSocketProcessor.WebSocketHandlerProxy(new EchoHandler() {
@Override
public void onTextMessage(WebSocket webSocket, String data) throws IOException {
webSocket.write("2" + data);
}
}));
AtmosphereRequest request = new AtmosphereRequest.Builder().destroyable(false).body("a").pathInfo("/a").build();
processor.open(w, request, AtmosphereResponse.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w, "a");
assertEquals(b.toString(), "a");
ByteArrayOutputStream b2 = new ByteArrayOutputStream();
final WebSocket w2 = new ArrayBaseWebSocket(b2);
request = new AtmosphereRequest.Builder().destroyable(false).body("b").pathInfo("/b").build();
processor.open(w2, request, AtmosphereResponse.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w2, "b");
// The WebSocketHandler is shared.
assertEquals(b2.toString(), "2b");
}