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);
}
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);
}
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());
}
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));
}
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);
}
Aggregations