use of org.springframework.graphql.web.support.GraphQlMessage 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);
}
use of org.springframework.graphql.web.support.GraphQlMessage in project spring-graphql by spring-projects.
the class GraphQlWebSocketHandlerTests method subscriptionExists.
@Test
void subscriptionExists() throws Exception {
handle(initWebSocketHandler(new ConsumeOneAndNeverCompleteInterceptor()), new TextMessage("{\"type\":\"connection_init\"}"), new TextMessage(BOOK_SUBSCRIPTION), new TextMessage(BOOK_SUBSCRIPTION));
// Collect messages until session closed
List<GraphQlMessage> messages = new ArrayList<>();
this.session.getOutput().subscribe((message) -> messages.add(decode(message)));
StepVerifier.create(this.session.closeStatus()).expectNext(new CloseStatus(4409, "Subscriber for " + SUBSCRIPTION_ID + " already exists")).expectComplete().verify(TIMEOUT);
assertThat(messages.size()).isEqualTo(2);
assertThat(messages.get(0).resolvedType()).isEqualTo(GraphQlMessageType.CONNECTION_ACK);
assertThat(messages.get(1).resolvedType()).isEqualTo(GraphQlMessageType.NEXT);
}
Aggregations