Fix WebGraphQlTester auto-registration for SpringBootTest

Prior to this commit, the `GraphQlTesterContextCustomizer` would
register a `WebGraphQlTester` instance as a `GraphQlTester` bean., only
exposing the `GraphQlTester` type. This is not in line with the
documentation and also does not register the bean definition with the
most specific type.
With this issue, a `@SpringBootTest` integration test will not be
injected with a `WebGraphQlTester` if it asks one.

This commit ensures that the `WebGraphQlTester` is registered as such
and that all related classes are renamed as a result.

Fixes gh-29250
This commit is contained in:
Brian Clozel
2022-01-03 16:00:04 +01:00
parent c3abf96d1f
commit 0d616b8924
6 changed files with 33 additions and 34 deletions

View File

@@ -28,7 +28,7 @@ import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFacto
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ContextPathCompositeHandler;
@@ -38,17 +38,17 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.test.annotation.DirtiesContext;
/**
* Integration test for {@link GraphQlTesterContextCustomizer}.
* Integration test for {@link WebGraphQlTesterContextCustomizer}.
*
* @author Brian Clozel
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = "spring.main.web-application-type=reactive")
@DirtiesContext
class GraphQlTesterContextCustomizerIntegrationTests {
class WebGraphQlTesterContextCustomizerIntegrationTests {
@Autowired
GraphQlTester graphQlTester;
WebGraphQlTester graphQlTester;
@Test
void shouldHandleGraphQlRequests() {

View File

@@ -28,7 +28,7 @@ import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFacto
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ContextPathCompositeHandler;
@@ -38,17 +38,17 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.test.context.TestPropertySource;
/**
* Tests for {@link GraphQlTesterContextCustomizer} with a custom context path for a
* Tests for {@link WebGraphQlTesterContextCustomizer} with a custom context path for a
* Reactive web application.
*
* @author Brian Clozel
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = { "spring.main.web-application-type=reactive", "spring.webflux.base-path=/test" })
class GraphQlTesterContextCustomizerWithCustomBasePathTests {
class WebGraphQlTesterContextCustomizerWithCustomBasePathTests {
@Autowired
GraphQlTester graphQlTester;
WebGraphQlTester graphQlTester;
@Test
void shouldHandleGraphQlRequests() {

View File

@@ -24,7 +24,7 @@ import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactor
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;
import org.springframework.http.MediaType;
import org.springframework.test.context.TestPropertySource;
import org.springframework.web.bind.annotation.PostMapping;
@@ -32,17 +32,17 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.DispatcherServlet;
/**
* Tests for {@link GraphQlTesterContextCustomizer} with a custom context path for a
* Tests for {@link WebGraphQlTesterContextCustomizer} with a custom context path for a
* Servlet web application.
*
* @author Brian Clozel
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = "server.servlet.context-path=/test")
class GraphQlTesterContextCustomizerWithCustomContextPathTests {
class WebGraphQlTesterContextCustomizerWithCustomContextPathTests {
@Autowired
GraphQlTester graphQlTester;
WebGraphQlTester graphQlTester;
@Test
void shouldHandleGraphQlRequests() {