Search in sources :

Example 1 with AdapterConnectCloseSocket

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

the class EventDriverFactoryTest method testAdapterConnectCloseSocket.

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

Example 2 with AdapterConnectCloseSocket

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

the class EventDriverTest method testAdapter_ConnectClose.

@Test
public void testAdapter_ConnectClose() throws Exception {
    AdapterConnectCloseSocket socket = new AdapterConnectCloseSocket();
    EventDriver driver = wrap(socket);
    try (LocalWebSocketSession conn = new CloseableLocalWebSocketSession(container, testname, driver)) {
        conn.open();
        driver.incomingFrame(new CloseInfo(StatusCode.NORMAL).asFrame());
        socket.capture.assertEventCount(2);
        socket.capture.pop().assertEventStartsWith("onWebSocketConnect");
        socket.capture.pop().assertEventStartsWith("onWebSocketClose");
    }
}
Also used : LocalWebSocketSession(org.eclipse.jetty.websocket.common.io.LocalWebSocketSession) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) AdapterConnectCloseSocket(examples.AdapterConnectCloseSocket) CloseableLocalWebSocketSession(org.eclipse.jetty.websocket.common.io.CloseableLocalWebSocketSession) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Aggregations

AdapterConnectCloseSocket (examples.AdapterConnectCloseSocket)2 Test (org.junit.Test)2 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)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