use of io.vertx.ext.web.handler.graphql.ApolloWSMessageType in project vertx-web by vert-x3.
the class ApolloWSHandlerTest method testSubscriptionWsCallWithConnectionParams.
@Test
public void testSubscriptionWsCallWithConnectionParams() {
int countInConnectionParams = 2;
client.webSocket("/graphql", onSuccess(websocket -> {
websocket.exceptionHandler(this::fail);
websocket.endHandler(v -> testComplete());
AtomicInteger counter = new AtomicInteger();
websocket.textMessageHandler(text -> {
JsonObject obj = new JsonObject(text);
ApolloWSMessageType type = ApolloWSMessageType.from(obj.getString("type"));
if (type.equals(CONNECTION_KEEP_ALIVE)) {
return;
}
int current = counter.getAndIncrement();
if (current == 0) {
assertEquals(CONNECTION_ACK, type);
} else if (current == 1) {
assertEquals(DATA, type);
int val = obj.getJsonObject("payload").getJsonObject("data").getJsonObject("counter").getInteger("count");
assertEquals(countInConnectionParams, val);
} else if (current == 2) {
assertEquals(COMPLETE, type);
websocket.close();
} else {
fail();
}
});
JsonObject messageInit = new JsonObject().put("payload", new JsonObject().put("count", countInConnectionParams)).put("type", "connection_init").put("id", "1");
JsonObject message = new JsonObject().put("payload", new JsonObject().put("query", "subscription Subscription { counter { count } }")).put("type", "start").put("id", "1");
websocket.write(messageInit.toBuffer());
websocket.write(message.toBuffer());
}));
await();
}
Aggregations