use of org.springframework.graphql.web.WebSocketInterceptor in project spring-graphql by spring-projects.
the class GraphQlWebSocketHandlerTests method connectionInitRejected.
@Test
void connectionInitRejected() {
TestWebSocketSession session = handle(Flux.just(toWebSocketMessage("{\"type\":\"connection_init\"}")), new WebSocketInterceptor() {
@Override
public Mono<Object> handleConnectionInitialization(String sessionId, Map<String, Object> payload) {
return Mono.error(new IllegalStateException());
}
});
StepVerifier.create(session.getOutput()).verifyComplete();
StepVerifier.create(session.closeStatus()).expectNext(new CloseStatus(4401, "Unauthorized")).expectComplete().verify(TIMEOUT);
}
use of org.springframework.graphql.web.WebSocketInterceptor in project spring-graphql by spring-projects.
the class GraphQlWebSocketHandlerTests method connectionClosedHandling.
@Test
void connectionClosedHandling() throws Exception {
CloseStatus closeStatus = CloseStatus.PROTOCOL_ERROR;
AtomicBoolean called = new AtomicBoolean();
WebSocketInterceptor interceptor = new WebSocketInterceptor() {
@Override
public void handleConnectionClosed(String sessionId, int status, Map<String, Object> payload) {
called.set(true);
assertThat(sessionId).isEqualTo("1");
assertThat(status).isEqualTo(closeStatus.getCode());
assertThat(payload).hasSize(1).containsEntry("key", "A");
}
};
GraphQlWebSocketHandler handler = initWebSocketHandler(interceptor);
handle(handler, new TextMessage("{\"type\":\"connection_init\",\"payload\":{\"key\":\"A\"}}"));
StepVerifier.create(session.getOutput()).expectNextCount(1).then(// Complete output Flux
this.session::close).expectComplete().verify(TIMEOUT);
handler.afterConnectionClosed(this.session, closeStatus);
assertThat(called).isTrue();
}
use of org.springframework.graphql.web.WebSocketInterceptor in project spring-graphql by spring-projects.
the class GraphQlWebSocketHandlerTests method connectionInitRejected.
@Test
void connectionInitRejected() throws Exception {
WebSocketInterceptor interceptor = new WebSocketInterceptor() {
@Override
public Mono<Object> handleConnectionInitialization(String sessionId, Map<String, Object> payload) {
return Mono.error(new IllegalStateException());
}
};
handle(initWebSocketHandler(interceptor), new TextMessage("{\"type\":\"connection_init\"}"));
StepVerifier.create(session.closeStatus()).expectNext(new CloseStatus(4401, "Unauthorized")).expectComplete().verify(TIMEOUT);
}
use of org.springframework.graphql.web.WebSocketInterceptor in project spring-graphql by spring-projects.
the class GraphQlWebSocketHandlerTests method connectionInitHandling.
@Test
void connectionInitHandling() {
TestWebSocketSession session = handle(Flux.just(toWebSocketMessage("{\"type\":\"connection_init\",\"payload\":{\"key\":\"A\"}}")), 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"));
}
});
StepVerifier.create(session.getOutput()).consumeNextWith((message) -> {
GraphQlMessage actual = decode(message);
assertThat(actual.resolvedType()).isEqualTo(GraphQlMessageType.CONNECTION_ACK);
assertThat(actual.<Map<String, Object>>getPayload()).containsEntry("key", "A acknowledged");
}).expectComplete().verify(TIMEOUT);
}
use of org.springframework.graphql.web.WebSocketInterceptor in project spring-graphql by spring-projects.
the class GraphQlWebSocketHandlerTests method connectionClosedHandling.
@Test
void connectionClosedHandling() {
CloseStatus closeStatus = CloseStatus.PROTOCOL_ERROR;
AtomicBoolean called = new AtomicBoolean();
TestWebSocketSession session = handle(Flux.just(toWebSocketMessage("{\"type\":\"connection_init\",\"payload\":{\"key\":\"A\"}}")), new WebSocketInterceptor() {
@Override
public void handleConnectionClosed(String sessionId, int status, Map<String, Object> payload) {
called.set(true);
assertThat(sessionId).isEqualTo("1");
assertThat(status).isEqualTo(closeStatus.getCode());
assertThat(payload).hasSize(1).containsEntry("key", "A");
}
});
StepVerifier.create(session.getOutput()).expectNextCount(1).verifyComplete();
StepVerifier.create(session.close(closeStatus)).verifyComplete();
assertThat(called).isTrue();
}
Aggregations