-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathGreetingApplicationTests.java
57 lines (44 loc) · 1.58 KB
/
GreetingApplicationTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.example.greeting;
import java.net.URI;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.graphql.test.tester.WebSocketGraphQlTester;
import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class GreetingApplicationTests {
@LocalServerPort
private int port;
@Value("http://localhost:${local.server.port}${spring.graphql.websocket.path}")
private String baseUrl;
private GraphQlTester graphQlTester;
@BeforeEach
void setUp() {
URI url = URI.create(baseUrl);
this.graphQlTester = WebSocketGraphQlTester.builder(url, new ReactorNettyWebSocketClient())
.interceptor(JwtGraphQlClientInterceptor.create())
.build();
}
@Test
void greeting() {
this.graphQlTester.document("{greeting}")
.execute()
.path("greeting")
.entity(String.class).isEqualTo("Hello Markey!");
}
@Test
void greetings() {
Flux<String> flux = this.graphQlTester.document("subscription {greetings}")
.executeSubscription()
.toFlux("greetings", String.class);
StepVerifier.create(flux)
.expectNext("Hello Markey0!", "Hello Markey1!", "Hello Markey2!", "Hello Markey3!")
.thenCancel()
.verify();
}
}