use of com.yahoo.elide.core.datastore.DataStoreIterableBuilder in project elide by yahoo.
the class SubscriptionWebSocketTest method testRootSubscription.
@Test
void testRootSubscription() throws IOException {
SubscriptionWebSocket endpoint = SubscriptionWebSocket.builder().executorService(executorService).elide(elide).build();
Book book1 = new Book();
book1.setTitle("Book 1");
book1.setId(1);
Book book2 = new Book();
book2.setTitle("Book 2");
book2.setId(2);
when(dataStoreTransaction.loadObjects(any(), any())).thenReturn(new DataStoreIterableBuilder(List.of(book1, book2)).build());
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\":{\"book\":{\"id\":\"1\",\"title\":\"Book 1\"}}}}", "{\"type\":\"next\",\"id\":\"1\",\"payload\":{\"data\":{\"book\":{\"id\":\"2\",\"title\":\"Book 2\"}}}}", "{\"type\":\"complete\",\"id\":\"1\"}");
ArgumentCaptor<String> message = ArgumentCaptor.forClass(String.class);
verify(remote, times(4)).sendText(message.capture());
assertEquals(expected, message.getAllValues());
}
Aggregations