mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Adapt @AutoConfigureHttpGraphQlTester to new testing infrastructure
This commit adapts @AutoConfigureHttpGraphQlTester to rely on the auto-configured WebTestClient and stop triggering the configuration of MockMvc. Closes gh-47660
This commit is contained in:
+5
-2
@@ -451,11 +451,14 @@ Often, javadoc:org.springframework.boot.graphql.test.autoconfigure.GraphQlTest[f
|
||||
include-code::GreetingControllerTests[]
|
||||
|
||||
javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] tests are full integration tests and involve the entire application.
|
||||
When using a random or defined port, a live server is configured and an javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean is contributed automatically so you can use it to test your server.
|
||||
When a MOCK environment is configured, you can also request an javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean by annotating your test class with javadoc:org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester[format=annotation] from the `spring-boot-graphql-test` module:
|
||||
A javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean can be added by annotating your test class with javadoc:org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester[format=annotation] from the `spring-boot-graphql-test` module:
|
||||
|
||||
include-code::GraphQlIntegrationTests[]
|
||||
|
||||
The javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean uses the relevant transport of the integration test.
|
||||
When using a random or defined port, the tester is configured against the live server.
|
||||
To bind the tester to `MockMvc`, make sure to annotate your test class with javadoc:org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc[format=annotation].
|
||||
|
||||
|
||||
|
||||
[[testing.spring-boot-applications.autoconfigured-spring-data-cassandra]]
|
||||
|
||||
+2
-1
@@ -21,10 +21,11 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureHttpGraphQlTester
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
|
||||
class GraphQlIntegrationTests {
|
||||
|
||||
@Test
|
||||
|
||||
+2
-1
@@ -20,12 +20,13 @@ import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester
|
||||
import org.springframework.http.HttpHeaders
|
||||
import org.springframework.test.web.reactive.server.WebTestClient
|
||||
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureHttpGraphQlTester
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
|
||||
class GraphQlIntegrationTests {
|
||||
|
||||
@Test
|
||||
|
||||
-2
@@ -24,7 +24,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.webtestclient.AutoConfigureWebTestClient;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
|
||||
@@ -39,7 +38,6 @@ import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@AutoConfigureMockMvc
|
||||
@AutoConfigureWebTestClient
|
||||
@ImportAutoConfiguration
|
||||
public @interface AutoConfigureHttpGraphQlTester {
|
||||
|
||||
+2
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
|
||||
import org.springframework.graphql.execution.ErrorType;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
|
||||
@@ -28,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureHttpGraphQlTester
|
||||
@AutoConfigureMockMvc
|
||||
class GreetingControllerTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user