configAttributes) {
+ SpringBootTest springBootTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, SpringBootTest.class);
+ return (springBootTest != null && isGraphQlTesterPresent()) ? new GraphQlTesterContextCustomizer() : null;
+ }
+
+ private boolean isGraphQlTesterPresent() {
+ return ClassUtils.isPresent(WEBTESTCLIENT_CLASS, getClass().getClassLoader())
+ && ClassUtils.isPresent(GRAPHQLTESTER_CLASS, getClass().getClassLoader());
+ }
+}
diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/test/tester/WebTestClientMockMvcAutoConfiguration.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/test/tester/WebTestClientMockMvcAutoConfiguration.java
new file mode 100644
index 00000000..5027ad41
--- /dev/null
+++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/test/tester/WebTestClientMockMvcAutoConfiguration.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2020-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.graphql.boot.test.tester;
+
+import java.util.List;
+
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.test.web.reactive.server.WebTestClientBuilderCustomizer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.client.MockMvcWebTestClient;
+import org.springframework.web.reactive.function.client.WebClient;
+
+/**
+ * Auto-configuration for {@link WebTestClient} support with {@link MockMvc}.
+ * Temporary workaround for upcoming enhancement request in Spring Boot 2.6.0.
+ *
+ * @author Brian Clozel
+ * @see Spring Boot 2.6.x issue
+ */
+@Configuration(proxyBeanMethods = false)
+@ConditionalOnClass({ WebClient.class, WebTestClient.class, MockMvcWebTestClient.class})
+@AutoConfigureAfter(name = "org.springframework.boot.test.autoconfigure.web.reactive.WebTestClientAutoConfiguration")
+public class WebTestClientMockMvcAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean
+ @ConditionalOnBean(MockMvc.class)
+ public WebTestClient webTestClient(MockMvc mockMvc, List customizers) {
+ WebTestClient.Builder builder = MockMvcWebTestClient.bindTo(mockMvc);
+ for (WebTestClientBuilderCustomizer customizer : customizers) {
+ customizer.customize(builder);
+ }
+ return builder.build();
+ }
+
+}
diff --git a/graphql-spring-boot-starter/src/main/resources/META-INF/spring.factories b/graphql-spring-boot-starter/src/main/resources/META-INF/spring.factories
index c2134a89..423ff5fa 100644
--- a/graphql-spring-boot-starter/src/main/resources/META-INF/spring.factories
+++ b/graphql-spring-boot-starter/src/main/resources/META-INF/spring.factories
@@ -4,3 +4,10 @@ org.springframework.graphql.boot.GraphQlAutoConfiguration,\
org.springframework.graphql.boot.GraphQlServiceAutoConfiguration,\
org.springframework.graphql.boot.WebFluxGraphQlAutoConfiguration,\
org.springframework.graphql.boot.WebMvcGraphQlAutoConfiguration
+# Spring Test @AutoConfigureGraphQlTester
+org.springframework.graphql.boot.test.tester.AutoConfigureGraphQlTester=\
+org.springframework.graphql.boot.test.tester.WebTestClientMockMvcAutoConfiguration,\
+org.springframework.graphql.boot.test.tester.GraphQlTesterAutoConfiguration
+# Spring Test ContextCustomizerFactories
+org.springframework.test.context.ContextCustomizerFactory=\
+org.springframework.graphql.boot.test.tester.GraphQlTesterContextCustomizerFactory
\ No newline at end of file
diff --git a/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/test/tester/GraphQlTesterAutoConfigurationTests.java b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/test/tester/GraphQlTesterAutoConfigurationTests.java
new file mode 100644
index 00000000..e21bd584
--- /dev/null
+++ b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/test/tester/GraphQlTesterAutoConfigurationTests.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2020-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.graphql.boot.test.tester;
+
+import org.junit.jupiter.api.Test;
+
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.graphql.boot.GraphQlProperties;
+import org.springframework.graphql.test.tester.GraphQlTester;
+import org.springframework.graphql.web.WebGraphQlHandler;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.reactive.function.server.RouterFunction;
+import org.springframework.web.reactive.function.server.RouterFunctions;
+import org.springframework.web.reactive.function.server.ServerResponse;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Tests for {@link GraphQlTesterAutoConfiguration}
+ *
+ * @author Brian Clozel
+ */
+class GraphQlTesterAutoConfigurationTests {
+
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withConfiguration(AutoConfigurations.of(GraphQlTesterAutoConfiguration.class));
+
+ @Test
+ void shouldNotBeConfiguredWithoutGraphQlHandlerNorWebTestClient() {
+ this.contextRunner.run((context) -> {
+ assertThat(context).hasNotFailed();
+ assertThat(context).doesNotHaveBean(GraphQlTester.class);
+ });
+ }
+
+ @Test
+ void shouldBeConfiguredWhenGraphQlHandlerPresent() {
+ this.contextRunner.withUserConfiguration(HandlerConfiguration.class).run((context) -> {
+ assertThat(context).hasNotFailed();
+ assertThat(context).hasSingleBean(GraphQlTester.class);
+ });
+ }
+
+ @Test
+ void shouldBeConfiguredWhenWebTestClientPresent() {
+ this.contextRunner.withUserConfiguration(WebTestClientConfiguration.class).run((context) -> {
+ assertThat(context).hasNotFailed();
+ assertThat(context).hasSingleBean(GraphQlTester.class);
+ });
+ }
+
+ @Configuration(proxyBeanMethods = false)
+ static class HandlerConfiguration {
+
+ @Bean
+ WebGraphQlHandler webGraphQlHandler() {
+ return mock(WebGraphQlHandler.class);
+ }
+
+
+ }
+
+ @Configuration(proxyBeanMethods = false)
+ static class WebTestClientConfiguration {
+
+ @Bean
+ WebTestClient webTestClient() {
+ RouterFunction routerFunction = RouterFunctions.route()
+ .POST("/graphql", request -> ServerResponse.ok().build()).build();
+ return WebTestClient.bindToRouterFunction(routerFunction).build();
+ }
+
+ @Bean
+ GraphQlProperties graphQlProperties() {
+ return new GraphQlProperties();
+ }
+
+ }
+}
diff --git a/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/test/tester/GraphQlTesterContextCustomizerIntegrationTests.java b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/test/tester/GraphQlTesterContextCustomizerIntegrationTests.java
new file mode 100644
index 00000000..b2df7a37
--- /dev/null
+++ b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/test/tester/GraphQlTesterContextCustomizerIntegrationTests.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2020-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.graphql.boot.test.tester;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+import reactor.core.publisher.Mono;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.buffer.DefaultDataBufferFactory;
+import org.springframework.graphql.boot.GraphQlProperties;
+import org.springframework.graphql.test.tester.GraphQlTester;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.server.reactive.ContextPathCompositeHandler;
+import org.springframework.http.server.reactive.HttpHandler;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.http.server.reactive.ServerHttpResponse;
+import org.springframework.test.annotation.DirtiesContext;
+
+/**
+ * Integration test for {@link GraphQlTesterContextCustomizer}
+ *
+ * @author Brian Clozel
+ */
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=reactive")
+@DirtiesContext
+class GraphQlTesterContextCustomizerIntegrationTests {
+
+ @Autowired GraphQlTester graphQlTester;
+
+ @Test
+ void test() {
+ this.graphQlTester.query("{}").executeAndVerify();
+ }
+
+ @Configuration(proxyBeanMethods = false)
+ static class TestConfig {
+
+ @Bean
+ TomcatReactiveWebServerFactory webServerFactory() {
+ return new TomcatReactiveWebServerFactory(0);
+ }
+
+ @Bean
+ HttpHandler httpHandler() {
+ TestHandler httpHandler = new TestHandler();
+ GraphQlProperties properties = new GraphQlProperties();
+ Map handlersMap = Collections.singletonMap(properties.getPath(), httpHandler);
+ return new ContextPathCompositeHandler(handlersMap);
+ }
+ }
+
+ static class TestHandler implements HttpHandler {
+
+ private static final DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
+
+ @Override
+ public Mono handle(ServerHttpRequest request, ServerHttpResponse response) {
+ response.setStatusCode(HttpStatus.OK);
+ response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
+ return response.writeWith(Mono.just(factory.wrap("{\"data\":{}}".getBytes())));
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/samples/webmvc-http/src/test/java/io/spring/sample/graphql/project/MockMvcGraphQlTests.java b/samples/webmvc-http/src/test/java/io/spring/sample/graphql/project/MockMvcGraphQlTests.java
index 8893d6a4..f2a5cf1e 100644
--- a/samples/webmvc-http/src/test/java/io/spring/sample/graphql/project/MockMvcGraphQlTests.java
+++ b/samples/webmvc-http/src/test/java/io/spring/sample/graphql/project/MockMvcGraphQlTests.java
@@ -15,36 +15,28 @@
*/
package io.spring.sample.graphql.project;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.graphql.boot.test.tester.AutoConfigureGraphQlTester;
import org.springframework.graphql.test.tester.GraphQlTester;
-import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.test.web.servlet.MockMvc;
-import org.springframework.test.web.servlet.client.MockMvcWebTestClient;
import static org.assertj.core.api.Assertions.assertThat;
/**
- * GraphQL requests via {@link WebTestClient} connecting to {@link MockMvc}.
+ * GraphQL requests via {@link GraphQlTester} connecting to {@link MockMvc}.
*/
@SpringBootTest
@AutoConfigureMockMvc
+@AutoConfigureGraphQlTester
public class MockMvcGraphQlTests {
+ @Autowired
private GraphQlTester graphQlTester;
-
- @BeforeEach
- public void setUp(@Autowired MockMvc mockMvc) {
- WebTestClient client = MockMvcWebTestClient.bindTo(mockMvc).baseUrl("/graphql").build();
- this.graphQlTester = GraphQlTester.create(client);
- }
-
-
@Test
void jsonPath() {
String query = "{" +