use of org.springframework.graphql.web.TestWebSocketConnection 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