@Deployment(testable = false)
public static WebArchive deploy() throws URISyntaxException {
return ShrinkWrap.create(WebArchive.class)
.addClass(MyAsyncEndpointText.class)
.addClass(MyAsyncEndpointByteBuffer.class);
}
cd javaee7-samples/websocket/endpoint-async/Now we are ready to start testing. You can run all the tests in this sample by executing:
mvn test
Or you can run individual tests by executing one of the following:mvn test -Dtest=MyAsyncEndpointTest
@Deployment(testable = false)
public static WebArchive deploy() throws URISyntaxException {
return ShrinkWrap.create(WebArchive.class)
.addClass(MyAsyncEndpointText.class)
.addClass(MyAsyncEndpointByteBuffer.class);
}
@Test
public void shouldReceiveAsyncTextMessage() throws URISyntaxException, IOException, DeploymentException {
MyAsyncEndpointTextClient endpoint = new MyAsyncEndpointTextClient();
Session session = connectToEndpoint(endpoint, "text");
session.getAsyncRemote().sendText(TEST_MESSAGE);
await().untilCall(to(endpoint).getReceivedMessage(), is(equalTo(TEST_MESSAGE)));
}
@Test
public void shouldReceiveAsyncByteBufferMessage() throws URISyntaxException, IOException, DeploymentException {
final ByteBuffer buffer = ByteBuffer.wrap(TEST_MESSAGE.getBytes());
MyAsyncEndpointByteBufferClient endpoint = new MyAsyncEndpointByteBufferClient();
Session session = connectToEndpoint(endpoint, "bytebuffer");
session.getAsyncRemote().sendBinary(buffer);
await().untilCall(to(endpoint).getReceivedMessage(), is(notNullValue()));
String receivedString = bufferToString(endpoint.getReceivedMessage());
assertThat(receivedString, is(equalTo(TEST_MESSAGE)));
}
There's a lot more about JavaEE to cover. If you're ready to learn more, check out the other available samples.
git clone git://github.com/javaee-samples/javaee7-samples.git
cd javaee7-samples/websocket/endpoint-async/
Do the changes as you see fit and send a pull request!
Good Luck!