Java Reference
In-Depth Information
WebSockets testing
We introduced the topic of WebSockets in the earlier chapters. Now let's see how we can
test them. To do this in plain Java, we will need a WebSocket client implementation; be
sure to add Tyrus to your pom.xml file:
For this example, we will use Tyrus as a base code from Chapter 8 , Adding WebSockets .
Our test realizes a simple scenario. Using the REST API, we reserve a seat, and as a We-
bSocket client, we wait for a message broadcasting information concerning new reserva-
tions. Let's look at the code:
public class TicketServiceTest {
private static final String WEBSOCKET_URL =
private static final String SEAT_RESOURCE_URL =
public static Archive<?> createTestArchive() { // [1]
public void shouldReceiveMessageOnBooking() throws
Exception {
// given
Search WWH ::

Custom Search