|
| 1 | +package graphql.kickstart.spring.webflux.boot; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import graphql.kickstart.tools.SchemaParserOptions.GenericWrapper; |
| 6 | +import java.io.IOException; |
| 7 | +import lombok.RequiredArgsConstructor; |
| 8 | +import lombok.val; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; |
| 12 | +import org.springframework.boot.test.context.SpringBootTest; |
| 13 | +import org.springframework.boot.test.context.TestConfiguration; |
| 14 | +import org.springframework.context.annotation.Bean; |
| 15 | +import org.springframework.http.MediaType; |
| 16 | +import org.springframework.test.context.junit.jupiter.SpringExtension; |
| 17 | +import org.springframework.test.web.reactive.server.WebTestClient; |
| 18 | +import reactor.core.publisher.Mono; |
| 19 | + |
| 20 | +@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") |
| 21 | +@RequiredArgsConstructor |
| 22 | +@ExtendWith(SpringExtension.class) |
| 23 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
| 24 | +class MonoGenericWrapperAlreadyDefinedTest { |
| 25 | + |
| 26 | + @Autowired |
| 27 | + private WebTestClient webTestClient; |
| 28 | + |
| 29 | + @Test |
| 30 | + void monoWrapper() throws IOException { |
| 31 | + val result = webTestClient.post() |
| 32 | + .uri("/graphql") |
| 33 | + .contentType(MediaType.APPLICATION_JSON) |
| 34 | + .bodyValue("{ \"query\": \"query { hello } \"}") |
| 35 | + .exchange() |
| 36 | + .returnResult(String.class); |
| 37 | + val response = result.getResponseBody().blockFirst(); |
| 38 | + assertThat(response).isEqualTo("{\"data\":{\"hello\":\"Hello world\"}}"); |
| 39 | + } |
| 40 | + |
| 41 | + @TestConfiguration |
| 42 | + static class MonoConfiguration { |
| 43 | + @Bean |
| 44 | + GenericWrapper genericWrapper() { |
| 45 | + return GenericWrapper.withTransformer( |
| 46 | + Mono.class, |
| 47 | + 0, |
| 48 | + Mono::toFuture, |
| 49 | + t -> t |
| 50 | + ); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments