WebSocketEndpoint extends AbstractEndpoint { public WebSocketEndpoint(WebSocketEndpointConfiguration endpointConfiguration) { super(endpointConfiguration); } WebSocketEndpoint(WebSocketEndpointConfiguration endpointConfiguration); @Override SelectiveConsumer createConsumer(); @Override Producer createProducer(); @Override WebSocketEndpointConfiguration getEndpointConfiguration(); void setWebSocketHandler(CitrusWebSocketHandler handler);  }
@Test public void testWebSocketEndpoint() throws Exception { WebSocketServerEndpointConfiguration endpointConfiguration = new WebSocketServerEndpointConfiguration(); WebSocketEndpoint webSocketEndpoint = new WebSocketEndpoint(endpointConfiguration); String endpointUri = "/test"; CitrusWebSocketHandler handler = new CitrusWebSocketHandler(); endpointConfiguration.setHandler(handler); final String requestBody = "<TestRequest><Message>Hello World!</Message></TestRequest>"; final Message responseMessage = new DefaultMessage("<TestResponse><Message>Hello World!</Message></TestResponse>"); endpointConfiguration.setEndpointUri(endpointUri); reset(session); when(session.getId()).thenReturn("test-socket-1"); when(session.isOpen()).thenReturn(true); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { org.springframework.web.socket.WebSocketMessage request = (org.springframework.web.socket.WebSocketMessage) invocation.getArguments()[0]; Assert.assertTrue(TextMessage.class.isInstance(request)); Assert.assertEquals(((TextMessage)request).getPayload(), responseMessage.getPayload(String.class)); Assert.assertTrue(request.isLast()); return null; } }).when(session).sendMessage(any(org.springframework.web.socket.WebSocketMessage.class)); handler.afterConnectionEstablished(session); handler.handleMessage(session, new TextMessage(requestBody)); WebSocketMessage requestMessage = (WebSocketMessage) webSocketEndpoint.createConsumer().receive(context); Assert.assertEquals(requestMessage.getPayload(), requestBody); Assert.assertTrue(requestMessage.isLast()); webSocketEndpoint.createProducer().send(responseMessage, context); }