Search in sources :

Example 1 with CheckSocket

use of org.eclipse.jetty.cdi.websocket.CheckSocket in project jetty.project by eclipse.

the class CdiAppTest method testWebSocket_Info_DataFromCdi.

@Test
public void testWebSocket_Info_DataFromCdi() throws Exception {
    WebSocketClient client = new WebSocketClient();
    try {
        client.start();
        CheckSocket socket = new CheckSocket();
        client.connect(socket, serverWebsocketURI.resolve("/cdi-info"));
        socket.awaitOpen(2, TimeUnit.SECONDS);
        socket.sendText("data|stuff");
        socket.close(StatusCode.NORMAL, "Test complete");
        socket.awaitClose(2, TimeUnit.SECONDS);
        assertThat("Messages received", socket.getTextMessages().size(), is(2));
        String response = socket.getTextMessages().poll();
        System.out.println("[0]" + response);
        assertThat("Message[0]", response, containsString("Hello there stuff"));
        System.out.println("[1]" + socket.getTextMessages().poll());
    } finally {
        client.stop();
    }
}
Also used : CheckSocket(org.eclipse.jetty.cdi.websocket.CheckSocket) Matchers.containsString(org.hamcrest.Matchers.containsString) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Test(org.junit.Test)

Example 2 with CheckSocket

use of org.eclipse.jetty.cdi.websocket.CheckSocket in project jetty.project by eclipse.

the class CdiAppTest method testWebSocketActivated.

@Test
public void testWebSocketActivated() throws Exception {
    WebSocketClient client = new WebSocketClient();
    try {
        client.start();
        CheckSocket socket = new CheckSocket();
        client.connect(socket, serverWebsocketURI.resolve("/echo"));
        socket.awaitOpen(2, TimeUnit.SECONDS);
        socket.sendText("Hello");
        socket.close(StatusCode.NORMAL, "Test complete");
        socket.awaitClose(2, TimeUnit.SECONDS);
        assertThat("Messages received", socket.getTextMessages().size(), is(1));
        assertThat("Message[0]", socket.getTextMessages().poll(), is("Hello"));
    } finally {
        client.stop();
    }
}
Also used : CheckSocket(org.eclipse.jetty.cdi.websocket.CheckSocket) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Test(org.junit.Test)

Example 3 with CheckSocket

use of org.eclipse.jetty.cdi.websocket.CheckSocket in project jetty.project by eclipse.

the class BasicAppTest method testWebSocketEcho.

@Test
public void testWebSocketEcho() throws Exception {
    WebSocketClient client = new WebSocketClient();
    try {
        client.start();
        CheckSocket socket = new CheckSocket();
        client.connect(socket, serverWebsocketURI.resolve("/echo"));
        socket.awaitOpen(2, TimeUnit.SECONDS);
        socket.sendText("Hello World");
        socket.close(StatusCode.NORMAL, "Test complete");
        socket.awaitClose(2, TimeUnit.SECONDS);
        assertThat("Messages received", socket.getTextMessages().size(), is(1));
        String response = socket.getTextMessages().poll();
        System.err.println(response);
        assertThat("Message[0]", response, is("Hello World"));
    } finally {
        client.stop();
    }
}
Also used : CheckSocket(org.eclipse.jetty.cdi.websocket.CheckSocket) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Test(org.junit.Test)

Example 4 with CheckSocket

use of org.eclipse.jetty.cdi.websocket.CheckSocket in project jetty.project by eclipse.

the class CdiAppTest method testWebSocket_Info_FieldPresence.

@Test
public void testWebSocket_Info_FieldPresence() throws Exception {
    WebSocketClient client = new WebSocketClient();
    try {
        client.start();
        CheckSocket socket = new CheckSocket();
        client.connect(socket, serverWebsocketURI.resolve("/cdi-info"));
        socket.awaitOpen(2, TimeUnit.SECONDS);
        socket.sendText("info");
        socket.close(StatusCode.NORMAL, "Test complete");
        socket.awaitClose(2, TimeUnit.SECONDS);
        assertThat("Messages received", socket.getTextMessages().size(), is(1));
        String response = socket.getTextMessages().poll();
        System.err.println(response);
        assertThat("Message[0]", response, allOf(containsString("websocketSession is PRESENT"), containsString("httpSession is PRESENT"), containsString("servletContext is PRESENT")));
    } finally {
        client.stop();
    }
}
Also used : CheckSocket(org.eclipse.jetty.cdi.websocket.CheckSocket) Matchers.containsString(org.hamcrest.Matchers.containsString) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Test(org.junit.Test)

Aggregations

CheckSocket (org.eclipse.jetty.cdi.websocket.CheckSocket)4 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)4 Test (org.junit.Test)4 Matchers.containsString (org.hamcrest.Matchers.containsString)2