Search in sources :

Example 31 with Session

use of javax.websocket.Session in project javaee7-samples by javaee-samples.

the class MyEndpointTest method testEndpointByteBuffer.

/**
     * The basic test method for the class {@link MyEndpointByteBuffer}
     *
     * @throws URISyntaxException
     * @throws DeploymentException
     * @throws IOException
     */
@Test
public void testEndpointByteBuffer() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
    MyEndpointClient.latch = new CountDownLatch(1);
    Session session = connectToServer("bytebuffer");
    assertNotNull(session);
    assertTrue(MyEndpointClient.latch.await(2, TimeUnit.SECONDS));
    assertNotNull(MyEndpointClient.response);
    assertArrayEquals(RESPONSE.getBytes(), MyEndpointClient.response);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Session(javax.websocket.Session) Test(org.junit.Test)

Example 32 with Session

use of javax.websocket.Session in project javaee7-samples by javaee-samples.

the class ChatTest method testConnect.

@Test
public void testConnect() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
    ChatClientEndpoint1.latch = new CountDownLatch(1);
    final Session session1 = connectToServer(ChatClientEndpoint1.class);
    assertNotNull(session1);
    assertTrue(ChatClientEndpoint1.latch.await(2, TimeUnit.SECONDS));
    assertEquals(ChatClientEndpoint1.TEXT, ChatClientEndpoint1.response);
    ChatClientEndpoint1.latch = new CountDownLatch(1);
    ChatClientEndpoint2.latch = new CountDownLatch(1);
    final Session session2 = connectToServer(ChatClientEndpoint2.class);
    assertNotNull(session2);
    assertTrue(ChatClientEndpoint1.latch.await(2, TimeUnit.SECONDS));
    assertTrue(ChatClientEndpoint2.latch.await(2, TimeUnit.SECONDS));
    assertEquals(ChatClientEndpoint2.TEXT, ChatClientEndpoint1.response);
    assertEquals(ChatClientEndpoint2.TEXT, ChatClientEndpoint2.response);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Session(javax.websocket.Session) Test(org.junit.Test)

Example 33 with Session

use of javax.websocket.Session in project javaee7-samples by javaee-samples.

the class MyClientTest method testEndpoint.

@Test
public void testEndpoint() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
    final String JSON = "{\"apple\":\"red\",\"banana\":\"yellow\"}";
    Session session = connectToServer(MyClient.class);
    assertNotNull(session);
    assertTrue(MyClient.latch.await(2, TimeUnit.SECONDS));
    assertEquals(JSON, MyClient.response.toString());
}
Also used : Session(javax.websocket.Session) Test(org.junit.Test)

Example 34 with Session

use of javax.websocket.Session in project javaee7-samples by javaee-samples.

the class MyEndpointTest method testBinaryEndpoint.

@Test
public void testBinaryEndpoint() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
    MyEndpointBinaryClient.latch = new CountDownLatch(1);
    final String TEXT = "Hello World!";
    Session session = connectToServer(MyEndpointBinaryClient.class);
    assertNotNull(session);
    session.addMessageHandler(new MessageHandler.Whole<ByteBuffer>() {

        @Override
        public void onMessage(ByteBuffer binary) {
            assertEquals(TEXT, binary);
        }
    });
    assertTrue(MyEndpointBinaryClient.latch.await(2, TimeUnit.SECONDS));
}
Also used : MessageHandler(javax.websocket.MessageHandler) CountDownLatch(java.util.concurrent.CountDownLatch) ByteBuffer(java.nio.ByteBuffer) Session(javax.websocket.Session) Test(org.junit.Test)

Example 35 with Session

use of javax.websocket.Session in project javaee7-samples by javaee-samples.

the class MyEndpointTest method testEndpointInputStream.

@Test
public void testEndpointInputStream() throws DeploymentException, IOException, URISyntaxException, InterruptedException {
    MyEndpointInputStreamClient.latch = new CountDownLatch(1);
    Session session = connectToServer(MyEndpointInputStreamClient.class, "inputstream");
    assertNotNull(session);
    assertTrue(MyEndpointInputStreamClient.latch.await(2, TimeUnit.SECONDS));
    assertNotNull(MyEndpointInputStreamClient.response);
    assertArrayEquals(TEXT.getBytes(), MyEndpointInputStreamClient.response);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Session(javax.websocket.Session) Test(org.junit.Test)

Aggregations

Session (javax.websocket.Session)115 Test (org.junit.Test)92 URI (java.net.URI)73 WebSocketContainer (javax.websocket.WebSocketContainer)42 Endpoint (javax.websocket.Endpoint)39 CountDownLatch (java.util.concurrent.CountDownLatch)34 Context (org.apache.catalina.Context)31 DefaultServlet (org.apache.catalina.servlets.DefaultServlet)31 Tomcat (org.apache.catalina.startup.Tomcat)31 EndpointConfig (javax.websocket.EndpointConfig)29 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)27 UndertowSession (io.undertow.websockets.jsr.UndertowSession)25 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)23 ServerEndpoint (javax.websocket.server.ServerEndpoint)20 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)16 IOException (java.io.IOException)16 AnnotatedClientEndpoint (io.undertow.websockets.jsr.test.annotated.AnnotatedClientEndpoint)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)15 FrameChecker (io.undertow.websockets.utils.FrameChecker)14