use of com.yahoo.elide.graphql.subscriptions.websocket.SubscriptionWebSocket in project elide by yahoo.
the class SubscriptionWebSocketTest method testSubscribeBeforeInit.
@Test
void testSubscribeBeforeInit() throws IOException {
SubscriptionWebSocket endpoint = SubscriptionWebSocket.builder().executorService(executorService).elide(elide).build();
endpoint.onOpen(session);
Subscribe subscribe = Subscribe.builder().id("1").payload(Subscribe.Payload.builder().query("subscription {book(topic: ADDED) {id title}}").build()).build();
endpoint.onMessage(session, mapper.writeValueAsString(subscribe));
verify(remote, never()).sendText(any());
ArgumentCaptor<CloseReason> closeReason = ArgumentCaptor.forClass(CloseReason.class);
verify(session, times(1)).close(closeReason.capture());
assertEquals(UNAUTHORIZED, closeReason.getValue());
}
use of com.yahoo.elide.graphql.subscriptions.websocket.SubscriptionWebSocket in project elide by yahoo.
the class SubscriptionWebSocketTest method testErrorPriorToStream.
@Test
void testErrorPriorToStream() throws IOException {
SubscriptionWebSocket endpoint = SubscriptionWebSocket.builder().executorService(executorService).elide(elide).build();
reset(dataStoreTransaction);
when(dataStoreTransaction.loadObjects(any(), any())).thenThrow(new BadRequestException("Bad Request"));
ConnectionInit init = new ConnectionInit();
endpoint.onOpen(session);
endpoint.onMessage(session, mapper.writeValueAsString(init));
Subscribe subscribe = Subscribe.builder().id("1").payload(Subscribe.Payload.builder().query("subscription {book(topic: ADDED) {id title}}").build()).build();
endpoint.onMessage(session, mapper.writeValueAsString(subscribe));
List<String> expected = List.of("{\"type\":\"connection_ack\"}", "{\"type\":\"next\",\"id\":\"1\",\"payload\":{\"data\":null,\"errors\":[{\"message\":\"Exception while fetching data (/book) : Bad Request\",\"locations\":[{\"line\":1,\"column\":15}],\"path\":[\"book\"],\"extensions\":{\"classification\":\"DataFetchingException\"}}]}}", "{\"type\":\"complete\",\"id\":\"1\"}");
ArgumentCaptor<String> message = ArgumentCaptor.forClass(String.class);
verify(remote, times(3)).sendText(message.capture());
assertEquals(expected, message.getAllValues());
}
use of com.yahoo.elide.graphql.subscriptions.websocket.SubscriptionWebSocket in project elide by yahoo.
the class SubscriptionWebSocketTest method testInvalidJson.
@Test
void testInvalidJson() throws IOException {
SubscriptionWebSocket endpoint = SubscriptionWebSocket.builder().executorService(executorService).elide(elide).build();
// Missing payload field
String invalid = "{ \"type\": \"subscribe\"}";
ConnectionInit init = new ConnectionInit();
endpoint.onOpen(session);
endpoint.onMessage(session, mapper.writeValueAsString(init));
endpoint.onMessage(session, invalid);
ArgumentCaptor<String> message = ArgumentCaptor.forClass(String.class);
verify(remote, times(1)).sendText(message.capture());
assertEquals("{\"type\":\"connection_ack\"}", message.getAllValues().get(0));
ArgumentCaptor<CloseReason> closeReason = ArgumentCaptor.forClass(CloseReason.class);
verify(session, times(1)).close(closeReason.capture());
assertEquals(INVALID_MESSAGE, closeReason.getValue());
}
Aggregations