Search in sources :

Example 1 with ListenerBasicSocket

use of examples.ListenerBasicSocket in project jetty.project by eclipse.

the class EventDriverFactoryTest method testListenerBasicSocket.

/**
     * Test Case for no exceptions and 5 methods (implement WebSocketListener)
     */
@Test
public void testListenerBasicSocket() {
    EventDriverFactory factory = new EventDriverFactory(new SimpleContainerScope(WebSocketPolicy.newClientPolicy()));
    ListenerBasicSocket socket = new ListenerBasicSocket();
    EventDriver driver = factory.wrap(socket);
    String classId = ListenerBasicSocket.class.getSimpleName();
    Assert.assertThat("EventDriver for " + classId, driver, instanceOf(JettyListenerEventDriver.class));
}
Also used : ListenerBasicSocket(examples.ListenerBasicSocket) Matchers.containsString(org.hamcrest.Matchers.containsString) SimpleContainerScope(org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope) Test(org.junit.Test)

Example 2 with ListenerBasicSocket

use of examples.ListenerBasicSocket in project jetty.project by eclipse.

the class EventDriverTest method testListenerBasic_Text.

@Test
public void testListenerBasic_Text() throws Exception {
    ListenerBasicSocket socket = new ListenerBasicSocket();
    EventDriver driver = wrap(socket);
    try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
        conn.start();
        conn.open();
        driver.incomingFrame(new TextFrame().setPayload("Hello World"));
        driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
        socket.capture.assertEventCount(3);
        socket.capture.pop().assertEventStartsWith("onWebSocketConnect");
        socket.capture.pop().assertEventStartsWith("onWebSocketText(\"Hello World\")");
        socket.capture.pop().assertEventStartsWith("onWebSocketClose(1000,");
    }
}
Also used : LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) ListenerBasicSocket(examples.ListenerBasicSocket) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Aggregations

ListenerBasicSocket (examples.ListenerBasicSocket)2 Test (org.junit.Test)2 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)1 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)1 CloseableLocalWebSocketSession (org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession)1 LocalWebSocketSession (org.eclipse.jetty.websocket.common.io.LocalWebSocketSession)1 SimpleContainerScope (org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1