|
15 | 15 | */
|
16 | 16 | package io.spring.sample.graphql;
|
17 | 17 |
|
| 18 | +import java.net.URI; |
| 19 | + |
| 20 | +import org.junit.jupiter.api.BeforeEach; |
18 | 21 | import org.junit.jupiter.api.Test;
|
19 | 22 | import reactor.core.publisher.Flux;
|
20 | 23 | import reactor.test.StepVerifier;
|
21 | 24 |
|
22 |
| -import org.springframework.beans.factory.annotation.Autowired; |
23 |
| -import org.springframework.boot.test.autoconfigure.graphql.GraphQlTest; |
24 |
| -import org.springframework.context.annotation.Import; |
| 25 | +import org.springframework.beans.factory.annotation.Value; |
| 26 | +import org.springframework.boot.test.context.SpringBootTest; |
| 27 | +import org.springframework.boot.web.server.LocalServerPort; |
25 | 28 | import org.springframework.graphql.test.tester.GraphQlTester;
|
| 29 | +import org.springframework.graphql.test.tester.WebSocketGraphQlTester; |
| 30 | +import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient; |
26 | 31 |
|
27 | 32 | /**
|
28 |
| - * GraphQL over WebSocket subscription tests. |
| 33 | + * GraphQL over WebSocket integration tests. |
29 | 34 | */
|
30 |
| -@GraphQlTest(SampleController.class) |
31 |
| -@Import(DataRepository.class) |
32 |
| -public class WebFluxWebSocketSampleSubscriptionTests { |
| 35 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
| 36 | +public class WebFluxWebSocketSampleIntegrationTests { |
| 37 | + |
| 38 | + @LocalServerPort |
| 39 | + private int port; |
| 40 | + |
| 41 | + @Value("http://localhost:${local.server.port}${spring.graphql.websocket.path}") |
| 42 | + private String baseUrl; |
33 | 43 |
|
34 |
| - @Autowired |
35 | 44 | private GraphQlTester graphQlTester;
|
36 | 45 |
|
37 | 46 |
|
| 47 | + @BeforeEach |
| 48 | + void setUp() { |
| 49 | + URI url = URI.create(baseUrl); |
| 50 | + this.graphQlTester = WebSocketGraphQlTester.builder(url, new ReactorNettyWebSocketClient()).build(); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + void greetingMono() { |
| 55 | + this.graphQlTester.document("{greetingMono}") |
| 56 | + .execute() |
| 57 | + .path("greetingMono") |
| 58 | + .entity(String.class) |
| 59 | + .isEqualTo("Hello!"); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + void greetingsFlux() { |
| 64 | + this.graphQlTester.document("{greetingsFlux}") |
| 65 | + .execute() |
| 66 | + .path("greetingsFlux") |
| 67 | + .entityList(String.class) |
| 68 | + .containsExactly("Hi!", "Bonjour!", "Hola!", "Ciao!", "Zdravo!"); |
| 69 | + } |
| 70 | + |
38 | 71 | @Test
|
39 | 72 | void subscriptionWithEntityPath() {
|
40 | 73 | Flux<String> result = this.graphQlTester.document("subscription { greetings }")
|
|
0 commit comments