use of org.springframework.graphql.GraphQlRequest in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method requestError.
@Test
void requestError() {
GraphQlRequest request = this.mockServer.expectOperation("{Query1}").andRespondWithError(GraphqlErrorBuilder.newError().message("boo").build());
StepVerifier.create(this.transport.execute(request)).consumeNextWith(result -> {
assertThat(result.isDataPresent()).isFalse();
assertThat(result.getErrors()).extracting(GraphQLError::getMessage).containsExactly("boo");
}).expectComplete().verify(TIMEOUT);
assertActualClientMessages(GraphQlMessage.connectionInit(null), GraphQlMessage.subscribe("1", request));
}
use of org.springframework.graphql.GraphQlRequest 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.GraphQlRequest in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method stop.
@Test
void stop() {
// Start
this.transport.start().block(TIMEOUT);
assertThat(this.webSocketClient.getConnectionCount()).isEqualTo(1);
assertThat(this.webSocketClient.getConnection(0).isOpen()).isTrue();
// Stop
this.transport.stop().block(TIMEOUT);
assertThat(this.webSocketClient.getConnection(0).isOpen()).isFalse();
assertThat(this.webSocketClient.getConnection(0).closeStatus().block(TIMEOUT)).isEqualTo(CloseStatus.NORMAL);
// New requests are rejected
GraphQlRequest request = this.mockServer.expectOperation("{Query1}").andRespond(this.result1);
StepVerifier.create(this.transport.execute(request)).expectErrorMessage("WebSocketGraphQlTransport has been stopped").verify(TIMEOUT);
// Start
this.transport.start().block(TIMEOUT);
assertThat(this.webSocketClient.getConnectionCount()).isEqualTo(2);
assertThat(this.webSocketClient.getConnection(1).isOpen()).isTrue();
// Requests allowed again
request = this.mockServer.expectOperation("{Query1}").andRespond(this.result1);
StepVerifier.create(this.transport.execute(request)).expectNext(this.result1).expectComplete().verify(TIMEOUT);
}
use of org.springframework.graphql.GraphQlRequest in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method request.
@Test
void request() {
GraphQlRequest request = this.mockServer.expectOperation("{Query1}").andRespond(this.result1);
StepVerifier.create(this.transport.execute(request)).expectNext(this.result1).expectComplete().verify(TIMEOUT);
assertActualClientMessages(GraphQlMessage.connectionInit(null), GraphQlMessage.subscribe("1", request));
}
use of org.springframework.graphql.GraphQlRequest in project spring-graphql by spring-projects.
the class MockWebSocketGraphQlTransportTests method sessionIsCachedUntilClosed.
@Test
void sessionIsCachedUntilClosed() {
GraphQlRequest request1 = this.mockServer.expectOperation("{Query1}").andRespond(this.result1);
StepVerifier.create(this.transport.execute(request1)).expectNext(this.result1).expectComplete().verify(TIMEOUT);
assertThat(this.webSocketClient.getConnectionCount()).isEqualTo(1);
TestWebSocketConnection originalConnection = this.webSocketClient.getConnection(0);
GraphQlRequest request2 = this.mockServer.expectOperation("{Query2}").andRespond(this.result2);
StepVerifier.create(this.transport.execute(request2)).expectNext(this.result2).expectComplete().verify(TIMEOUT);
assertThat(this.webSocketClient.getConnectionCount()).isEqualTo(1);
assertThat(this.webSocketClient.getConnection(0)).isSameAs(originalConnection);
// Close the connection
originalConnection.closeServerSession(CloseStatus.NORMAL).block(TIMEOUT);
request1 = this.mockServer.expectOperation("{Query1}").andRespond(this.result1);
StepVerifier.create(this.transport.execute(request1)).expectNext(this.result1).expectComplete().verify(TIMEOUT);
assertThat(this.webSocketClient.getConnectionCount()).isEqualTo(2);
assertThat(this.webSocketClient.getConnection(1)).isNotSameAs(originalConnection);
}
Aggregations