Search in sources :

Example 11 with GraphQlRequest

use of org.springframework.graphql.GraphQlRequest in project spring-graphql by spring-projects.

the class MockWebSocketGraphQlTransportTests method requestStream.

@Test
void requestStream() {
    GraphQlRequest request = this.mockServer.expectOperation("{Sub1}").andStream(Flux.just(this.result1, result2));
    StepVerifier.create(this.transport.executeSubscription(request)).expectNext(this.result1, result2).expectComplete().verify(TIMEOUT);
    assertActualClientMessages(GraphQlMessage.connectionInit(null), GraphQlMessage.subscribe("1", request));
}
Also used : GraphQlRequest(org.springframework.graphql.GraphQlRequest) Test(org.junit.jupiter.api.Test)

Example 12 with GraphQlRequest

use of org.springframework.graphql.GraphQlRequest in project spring-graphql by spring-projects.

the class MockWebSocketGraphQlTransportTests method errorDuringResponseHandling.

@Test
void errorDuringResponseHandling() {
    // Response handling errors that close the connection should terminate outstanding requests
    TestWebSocketClient client = new TestWebSocketClient(new UnexpectedResponseHandler());
    WebSocketGraphQlTransport transport = createTransport(client);
    String expectedMessage = "disconnected with CloseStatus[code=1002, reason=null]";
    StepVerifier.create(transport.execute(new GraphQlRequest("{Query1}"))).expectErrorSatisfies(ex -> assertThat(ex).hasMessageEndingWith(expectedMessage)).verify(TIMEOUT);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) GraphQlMessage(org.springframework.graphql.web.support.GraphQlMessage) StepVerifier(reactor.test.StepVerifier) WebSocketSession(org.springframework.web.reactive.socket.WebSocketSession) CloseStatus(org.springframework.web.reactive.socket.CloseStatus) WebSocketClient(org.springframework.web.reactive.socket.client.WebSocketClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestWebSocketClient(org.springframework.graphql.web.TestWebSocketClient) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExecutionResult(graphql.ExecutionResult) GraphQLError(graphql.GraphQLError) Duration(java.time.Duration) Map(java.util.Map) TestWebSocketConnection(org.springframework.graphql.web.TestWebSocketConnection) WebSocketHandler(org.springframework.web.reactive.socket.WebSocketHandler) URI(java.net.URI) MapExecutionResult(org.springframework.graphql.support.MapExecutionResult) HttpHeaders(org.springframework.http.HttpHeaders) GraphQlRequest(org.springframework.graphql.GraphQlRequest) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) GraphqlErrorBuilder(graphql.GraphqlErrorBuilder) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) ClientCodecConfigurer(org.springframework.http.codec.ClientCodecConfigurer) List(java.util.List) GraphQlMessageType(org.springframework.graphql.web.support.GraphQlMessageType) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) GraphQlRequest(org.springframework.graphql.GraphQlRequest) TestWebSocketClient(org.springframework.graphql.web.TestWebSocketClient) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)12 GraphQlRequest (org.springframework.graphql.GraphQlRequest)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 TestWebSocketClient (org.springframework.graphql.web.TestWebSocketClient)3 TestWebSocketConnection (org.springframework.graphql.web.TestWebSocketConnection)3 Mono (reactor.core.publisher.Mono)3 ExecutionResult (graphql.ExecutionResult)2 GraphQLError (graphql.GraphQLError)2 GraphqlErrorBuilder (graphql.GraphqlErrorBuilder)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Duration (java.time.Duration)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Collectors (java.util.stream.Collectors)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.when (org.mockito.Mockito.when)2