use of org.springframework.graphql.web.TestWebSocketClient in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method pingHandling.
@Test
void pingHandling() {
TestWebSocketClient client = new TestWebSocketClient(new PingResponseHandler(this.result1));
WebSocketGraphQlTransport transport = createTransport(client);
StepVerifier.create(transport.execute(new GraphQlRequest("{Query1}"))).expectNext(this.result1).expectComplete().verify(TIMEOUT);
assertActualClientMessages(client.getConnection(0), GraphQlMessage.connectionInit(null), GraphQlMessage.pong(null), GraphQlMessage.subscribe("1", new GraphQlRequest("{Query1}")));
}
use of org.springframework.graphql.web.TestWebSocketClient in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method start.
@Test
void start() {
MockGraphQlWebSocketServer handler = new MockGraphQlWebSocketServer();
handler.connectionInitHandler(payload -> Mono.just(Collections.singletonMap("key", payload.get("key") + "Ack")));
TestWebSocketClient client = new TestWebSocketClient(handler);
Map<String, String> initPayload = Collections.singletonMap("key", "valueInit");
AtomicReference<Map<String, Object>> connectionAckRef = new AtomicReference<>();
WebSocketGraphQlTransport transport = new WebSocketGraphQlTransport(URI.create("/"), HttpHeaders.EMPTY, client, ClientCodecConfigurer.create(), initPayload, connectionAckRef::set);
transport.start().block(TIMEOUT);
assertThat(client.getConnection(0).isOpen()).isTrue();
assertThat(connectionAckRef.get()).isEqualTo(Collections.singletonMap("key", "valueInitAck"));
assertActualClientMessages(client.getConnection(0), GraphQlMessage.connectionInit(initPayload));
}
use of org.springframework.graphql.web.TestWebSocketClient in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method errorBeforeConnectionAck.
@Test
void errorBeforeConnectionAck() {
// Errors before GraphQL session initialized should be routed, no hanging on start
MockGraphQlWebSocketServer handler = new MockGraphQlWebSocketServer();
handler.connectionInitHandler(initPayload -> Mono.error(new IllegalStateException("boo")));
TestWebSocketClient client = new TestWebSocketClient(handler);
StepVerifier.create(createTransport(client).start()).expectErrorMessage("boo").verify(TIMEOUT);
}
use of org.springframework.graphql.web.TestWebSocketClient in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method errorDuringResponseHandling.
@Test
void errorDuringResponseHandling() {
// Response handling errors that close the connection should terminate outstanding requests
TestWebSocketClient client = new TestWebSocketClient(new UnexpectedResponseHandler());
WebSocketGraphQlTransport transport = createTransport(client);
String expectedMessage = "disconnected with CloseStatus[code=1002, reason=null]";
StepVerifier.create(transport.execute(new GraphQlRequest("{Query1}"))).expectErrorSatisfies(ex -> assertThat(ex).hasMessageEndingWith(expectedMessage)).verify(TIMEOUT);
}
Aggregations