Search in sources :

Example 1 with WebSocketTestClient

use of spark.embeddedserver.jetty.websocket.WebSocketTestClient in project spark by perwendel.

the class GenericIntegrationTest method testWebSocketConversation.

@Test
public void testWebSocketConversation() throws Exception {
    String uri = "ws://localhost:4567/ws";
    WebSocketClient client = new WebSocketClient();
    WebSocketTestClient ws = new WebSocketTestClient();
    try {
        client.start();
        client.connect(ws, URI.create(uri), new ClientUpgradeRequest());
        ws.awaitClose(30, TimeUnit.SECONDS);
    } finally {
        client.stop();
    }
    List<String> events = WebSocketTestHandler.events;
    Assert.assertEquals(3, events.size(), 3);
    Assert.assertEquals("onConnect", events.get(0));
    Assert.assertEquals("onMessage: Hi Spark!", events.get(1));
    Assert.assertEquals("onClose: 1000 Bye!", events.get(2));
}
Also used : WebSocketTestClient(spark.embeddedserver.jetty.websocket.WebSocketTestClient) ClientUpgradeRequest(org.eclipse.jetty.websocket.client.ClientUpgradeRequest) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Test(org.junit.Test)

Aggregations

ClientUpgradeRequest (org.eclipse.jetty.websocket.client.ClientUpgradeRequest)1 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)1 Test (org.junit.Test)1 WebSocketTestClient (spark.embeddedserver.jetty.websocket.WebSocketTestClient)1