use of org.springframework.graphql.web.WebSocketInterceptor in project spring-graphql by spring-projects.
the class GraphQlWebSocketHandlerTests method connectionInitHandling.
@Test
void connectionInitHandling() throws Exception {
WebSocketInterceptor interceptor = new WebSocketInterceptor() {
@Override
public Mono<Object> handleConnectionInitialization(String sessionId, Map<String, Object> payload) {
Object value = payload.get("key");
return Mono.just(Collections.singletonMap("key", value + " acknowledged"));
}
};
handle(initWebSocketHandler(interceptor), new TextMessage("{\"type\":\"connection_init\",\"payload\":{\"key\":\"A\"}}"));
StepVerifier.create(session.getOutput()).consumeNextWith((webSocketMessage) -> {
GraphQlMessage message = decode(webSocketMessage);
assertThat(message.resolvedType()).isEqualTo(GraphQlMessageType.CONNECTION_ACK);
assertThat(message.<Map<String, Object>>getPayload()).containsEntry("key", "A acknowledged");
}).then(// Complete output Flux
this.session::close).expectComplete().verify(TIMEOUT);
}
Aggregations