diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfiguration.java index 1d0ce465d1..4bc6b567a1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfiguration.java @@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.graphql.reactive.GraphQlWebFluxAutoConfiguration; import org.springframework.context.annotation.Bean; -import org.springframework.graphql.security.ReactiveSecurityDataFetcherExceptionResolver; +import org.springframework.graphql.execution.ReactiveSecurityDataFetcherExceptionResolver; import org.springframework.graphql.web.webflux.GraphQlHttpHandler; import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfiguration.java index 90f283710c..5a3ae3cd43 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfiguration.java @@ -26,8 +26,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.graphql.servlet.GraphQlWebMvcAutoConfiguration; import org.springframework.context.annotation.Bean; -import org.springframework.graphql.security.SecurityContextThreadLocalAccessor; -import org.springframework.graphql.security.SecurityDataFetcherExceptionResolver; +import org.springframework.graphql.execution.SecurityContextThreadLocalAccessor; +import org.springframework.graphql.execution.SecurityDataFetcherExceptionResolver; import org.springframework.graphql.web.webmvc.GraphQlHttpHandler; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQueryByExampleAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQueryByExampleAutoConfigurationTests.java index be28b3e908..c2dafc6ed9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQueryByExampleAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQueryByExampleAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. @@ -30,7 +30,7 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.QueryByExampleExecutor; import org.springframework.graphql.GraphQlService; import org.springframework.graphql.data.GraphQlRepository; -import org.springframework.graphql.test.tester.GraphQlTester; +import org.springframework.graphql.test.tester.GraphQlServiceTester; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; @@ -55,8 +55,8 @@ class GraphQlQueryByExampleAutoConfigurationTests { void shouldRegisterDataFetcherForQueryByExampleRepositories() { this.contextRunner.run((context) -> { GraphQlService graphQlService = context.getBean(GraphQlService.class); - GraphQlTester graphQlTester = GraphQlTester.create(graphQlService); - graphQlTester.query("{ bookById(id: 1) {name}}").execute().path("bookById.name").entity(String.class) + GraphQlServiceTester graphQlTester = GraphQlServiceTester.create(graphQlService); + graphQlTester.document("{ bookById(id: 1) {name}}").execute().path("bookById.name").entity(String.class) .isEqualTo("Test title"); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQuerydslAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQuerydslAutoConfigurationTests.java index c687d0834e..9e7e34663d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQuerydslAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQuerydslAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. @@ -30,6 +30,7 @@ import org.springframework.data.querydsl.QuerydslPredicateExecutor; import org.springframework.data.repository.CrudRepository; import org.springframework.graphql.GraphQlService; import org.springframework.graphql.data.GraphQlRepository; +import org.springframework.graphql.test.tester.GraphQlServiceTester; import org.springframework.graphql.test.tester.GraphQlTester; import static org.mockito.ArgumentMatchers.any; @@ -55,8 +56,8 @@ class GraphQlQuerydslAutoConfigurationTests { void shouldRegisterDataFetcherForQueryDslRepositories() { this.contextRunner.run((context) -> { GraphQlService graphQlService = context.getBean(GraphQlService.class); - GraphQlTester graphQlTester = GraphQlTester.create(graphQlService); - graphQlTester.query("{ bookById(id: 1) {name}}").execute().path("bookById.name").entity(String.class) + GraphQlTester graphQlTester = GraphQlServiceTester.create(graphQlService); + graphQlTester.document("{ bookById(id: 1) {name}}").execute().path("bookById.name").entity(String.class) .isEqualTo("Test title"); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQueryByExampleAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQueryByExampleAutoConfigurationTests.java index 20eb88e797..ed87b22be0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQueryByExampleAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQueryByExampleAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. @@ -29,6 +29,7 @@ import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor; import org.springframework.data.repository.reactive.ReactiveCrudRepository; import org.springframework.graphql.GraphQlService; import org.springframework.graphql.data.GraphQlRepository; +import org.springframework.graphql.test.tester.GraphQlServiceTester; import org.springframework.graphql.test.tester.GraphQlTester; import static org.mockito.ArgumentMatchers.any; @@ -54,8 +55,8 @@ class GraphQlReactiveQueryByExampleAutoConfigurationTests { void shouldRegisterDataFetcherForQueryByExampleRepositories() { this.contextRunner.run((context) -> { GraphQlService graphQlService = context.getBean(GraphQlService.class); - GraphQlTester graphQlTester = GraphQlTester.create(graphQlService); - graphQlTester.query("{ bookById(id: 1) {name}}").execute().path("bookById.name").entity(String.class) + GraphQlTester graphQlTester = GraphQlServiceTester.create(graphQlService); + graphQlTester.document("{ bookById(id: 1) {name}}").execute().path("bookById.name").entity(String.class) .isEqualTo("Test title"); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQuerydslAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQuerydslAutoConfigurationTests.java index 4d5d461462..dcefb935ee 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQuerydslAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQuerydslAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. @@ -29,6 +29,7 @@ import org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor; import org.springframework.data.repository.reactive.ReactiveCrudRepository; import org.springframework.graphql.GraphQlService; import org.springframework.graphql.data.GraphQlRepository; +import org.springframework.graphql.test.tester.GraphQlServiceTester; import org.springframework.graphql.test.tester.GraphQlTester; import static org.mockito.ArgumentMatchers.any; @@ -54,8 +55,8 @@ class GraphQlReactiveQuerydslAutoConfigurationTests { void shouldRegisterDataFetcherForQueryDslRepositories() { this.contextRunner.run((context) -> { GraphQlService graphQlService = context.getBean(GraphQlService.class); - GraphQlTester graphQlTester = GraphQlTester.create(graphQlService); - graphQlTester.query("{ bookById(id: 1) {name}}").execute().path("bookById.name").entity(String.class) + GraphQlTester graphQlTester = GraphQlServiceTester.create(graphQlService); + graphQlTester.document("{ bookById(id: 1) {name}}").execute().path("bookById.name").entity(String.class) .isEqualTo("Test title"); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfigurationTests.java index 9b6f1db534..dbe21765c4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfigurationTests.java @@ -37,8 +37,8 @@ import org.springframework.boot.test.context.runner.ReactiveWebApplicationContex import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.graphql.execution.ErrorType; +import org.springframework.graphql.execution.ReactiveSecurityDataFetcherExceptionResolver; import org.springframework.graphql.execution.RuntimeWiringConfigurer; -import org.springframework.graphql.security.ReactiveSecurityDataFetcherExceptionResolver; import org.springframework.http.MediaType; import org.springframework.lang.Nullable; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfigurationTests.java index fc030d9d45..fa33b55439 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfigurationTests.java @@ -34,8 +34,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.graphql.execution.ErrorType; import org.springframework.graphql.execution.RuntimeWiringConfigurer; -import org.springframework.graphql.security.SecurityContextThreadLocalAccessor; -import org.springframework.graphql.security.SecurityDataFetcherExceptionResolver; +import org.springframework.graphql.execution.SecurityContextThreadLocalAccessor; +import org.springframework.graphql.execution.SecurityDataFetcherExceptionResolver; import org.springframework.http.MediaType; import org.springframework.lang.Nullable; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index b2d678f5bc..29e1b354c1 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1682,7 +1682,7 @@ bom { ] } } - library("Spring GraphQL", "1.0.0-M5") { + library("Spring GraphQL", "1.0.0-SNAPSHOT") { group("org.springframework.graphql") { modules = [ "spring-graphql", diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc index b19a813ae0..b160e51cfc 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc @@ -435,8 +435,12 @@ Spring GraphQL offers a dedicated testing support module; you'll need to add it } ---- -This testing module ships the {spring-graphql-docs}/testing.html#testing-webgraphqltester[WebGraphQlTester]. +This testing module ships the {spring-graphql-docs}/#testing-graphqltester[GraphQlTester]. The tester is heavily used in test, so be sure to become familiar with using it. +There are `GraphQlTester` variants and Spring Boot will auto-configure them depending on the type of tests: + +* the `GraphQlServiceTester` performs tests on the server side, without a client nor a transport +* the `HttpGraphQlTester` performs tests with a client that connects to a server, with or without a live server Spring Boot helps you to test your {spring-graphql-docs}#controllers[Spring GraphQL Controllers] with the `@GraphQlTest` annotation. `@GraphQlTest` auto-configures the Spring GraphQL infrastructure, without any transport nor server being involved. @@ -452,8 +456,11 @@ Often, `@GraphQlTest` is limited to a set of controllers and used in combination include::code:GreetingControllerTests[] -TIP: You can also auto-configure `WebGraphQlTester` in a non-`@GraphQlTest` (such as `@SpringBootTest`) by annotating it with `@AutoConfigureWebGraphQlTester`. +`@SpringBootTest` tests are full integration tests and involve the entire application. +When using a random or defined port, a live server is configured and an `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 `HttpGraphQlTester` bean by annotating your test class with `@AutoConfigureHttpGraphQlTester`: +include::code:GraphQlIntegrationTests[] [[features.testing.spring-boot-applications.autoconfigured-spring-data-cassandra]] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.java new file mode 100644 index 0000000000..2ff2a08ea6 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2022 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.boot.docs.features.testing.springbootapplications.springgraphqltests; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.graphql.test.tester.HttpGraphQlTester; + +@AutoConfigureHttpGraphQlTester +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) +class GraphQlIntegrationTests { + + @Test + void shouldGreetWithSpecificName(@Autowired HttpGraphQlTester graphQlTester) { + HttpGraphQlTester authenticatedTester = graphQlTester.mutate() + .webTestClient( + (client) -> client.defaultHeaders((headers) -> headers.setBasicAuth("admin", "ilovespring"))) + .build(); + authenticatedTester.document("{ greeting(name: \"Alice\") } ").execute().path("greeting").entity(String.class) + .isEqualTo("Hello, Alice!"); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GreetingControllerTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GreetingControllerTests.java index 932003390b..951bd126d0 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GreetingControllerTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GreetingControllerTests.java @@ -31,13 +31,13 @@ class GreetingControllerTests { @Test void shouldGreetWithSpecificName() { - this.graphQlTester.query("{ greeting(name: \"Alice\") } ").execute().path("greeting").entity(String.class) + this.graphQlTester.document("{ greeting(name: \"Alice\") } ").execute().path("greeting").entity(String.class) .isEqualTo("Hello, Alice!"); } @Test void shouldGreetWithDefaultName() { - this.graphQlTester.query("{ greeting } ").execute().path("greeting").entity(String.class) + this.graphQlTester.document("{ greeting } ").execute().path("greeting").entity(String.class) .isEqualTo("Hello, Spring!"); } diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.kt new file mode 100644 index 0000000000..f8b0f3ea09 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2012-2022 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.boot.docs.features.testing.springbootapplications.springgraphqltests + +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.graphql.test.tester.HttpGraphQlTester +import org.springframework.http.HttpHeaders +import org.springframework.test.web.reactive.server.WebTestClient + +@AutoConfigureHttpGraphQlTester +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) +class GraphQlIntegrationTests { + + @Test + fun shouldGreetWithSpecificName(@Autowired graphQlTester: HttpGraphQlTester) { + val authenticatedTester = graphQlTester.mutate() + .webTestClient { client: WebTestClient.Builder -> + client.defaultHeaders { headers: HttpHeaders -> + headers.setBasicAuth("admin", "ilovespring") + } + }.build() + authenticatedTester.document("{ greeting(name: \"Alice\") } ").execute() + .path("greeting").entity(String::class.java).isEqualTo("Hello, Alice!") + } +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GreetingControllerTests.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GreetingControllerTests.kt index 5f67866394..902d9cec26 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GreetingControllerTests.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/springgraphqltests/GreetingControllerTests.kt @@ -30,13 +30,13 @@ internal class GreetingControllerTests { @Test fun shouldGreetWithSpecificName() { - graphQlTester.query("{ greeting(name: \"Alice\") } ").execute().path("greeting").entity(String::class.java) + graphQlTester.document("{ greeting(name: \"Alice\") } ").execute().path("greeting").entity(String::class.java) .isEqualTo("Hello, Alice!") } @Test fun shouldGreetWithDefaultName() { - graphQlTester.query("{ greeting } ").execute().path("greeting").entity(String::class.java) + graphQlTester.document("{ greeting } ").execute().path("greeting").entity(String::class.java) .isEqualTo("Hello, Spring!") } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/GraphQlTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/GraphQlTest.java index d0cfa2d55e..c096f037ba 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/GraphQlTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/GraphQlTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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. @@ -31,7 +31,7 @@ import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache; import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters; import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureGraphQlTester; -import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureWebGraphQlTester; +import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester; import org.springframework.boot.test.autoconfigure.json.AutoConfigureJson; import org.springframework.context.annotation.ComponentScan; import org.springframework.core.annotation.AliasFor; @@ -67,9 +67,9 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; * and other components required for the tests. *
* To load your full application configuration instead and test via - * {@code WebGraphQlTester}, consider using + * {@code HttpGraphQlTester}, consider using * {@link org.springframework.boot.test.context.SpringBootTest @SpringBootTest} combined - * with {@link AutoConfigureWebGraphQlTester @AutoConfigureWebGraphQlTester}. + * with {@link AutoConfigureHttpGraphQlTester @AutoConfigureHttpGraphQlTester}. * * @author Brian Clozel * @since 2.7.0 diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/AutoConfigureWebGraphQlTester.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/AutoConfigureHttpGraphQlTester.java similarity index 87% rename from spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/AutoConfigureWebGraphQlTester.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/AutoConfigureHttpGraphQlTester.java index 5c5a8e1bd6..133db41f40 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/AutoConfigureWebGraphQlTester.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/AutoConfigureHttpGraphQlTester.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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. @@ -26,10 +26,10 @@ import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.graphql.test.tester.WebGraphQlTester; +import org.springframework.graphql.test.tester.HttpGraphQlTester; /** - * Annotation that can be applied to a test class to enable a {@link WebGraphQlTester}. + * Annotation that can be applied to a test class to enable a {@link HttpGraphQlTester}. * *
* This annotation should be used with @@ -38,7 +38,7 @@ import org.springframework.graphql.test.tester.WebGraphQlTester; * * @author Brian Clozel * @since 2.7.0 - * @see WebGraphQlTesterAutoConfiguration + * @see HttpGraphQlTesterAutoConfiguration */ @Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @@ -47,6 +47,6 @@ import org.springframework.graphql.test.tester.WebGraphQlTester; @AutoConfigureMockMvc @AutoConfigureWebTestClient @ImportAutoConfiguration -public @interface AutoConfigureWebGraphQlTester { +public @interface AutoConfigureHttpGraphQlTester { } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/GraphQlTesterAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/GraphQlTesterAutoConfiguration.java index 76caa61c22..d2e654ee79 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/GraphQlTesterAutoConfiguration.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/GraphQlTesterAutoConfiguration.java @@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.graphql.GraphQlService; +import org.springframework.graphql.test.tester.GraphQlServiceTester; import org.springframework.graphql.test.tester.GraphQlTester; /** @@ -40,8 +41,8 @@ public class GraphQlTesterAutoConfiguration { @Bean @ConditionalOnBean(GraphQlService.class) @ConditionalOnMissingBean - public GraphQlTester graphQlTester(GraphQlService graphQlService) { - return GraphQlTester.create(graphQlService); + public GraphQlServiceTester graphQlTester(GraphQlService graphQlService) { + return GraphQlServiceTester.create(graphQlService); } } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/WebGraphQlTesterAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/HttpGraphQlTesterAutoConfiguration.java similarity index 84% rename from spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/WebGraphQlTesterAutoConfiguration.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/HttpGraphQlTesterAutoConfiguration.java index e3f65198cb..953571a1c9 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/WebGraphQlTesterAutoConfiguration.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/HttpGraphQlTesterAutoConfiguration.java @@ -24,26 +24,27 @@ import org.springframework.boot.autoconfigure.graphql.GraphQlProperties; import org.springframework.boot.test.autoconfigure.web.reactive.WebTestClientAutoConfiguration; import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcAutoConfiguration; import org.springframework.context.annotation.Bean; +import org.springframework.graphql.test.tester.HttpGraphQlTester; import org.springframework.graphql.test.tester.WebGraphQlTester; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.client.WebClient; /** - * Auto-configuration for {@link WebGraphQlTester}. + * Auto-configuration for {@link HttpGraphQlTester}. * * @author Brian Clozel * @since 2.7.0 */ @AutoConfiguration(after = { WebTestClientAutoConfiguration.class, MockMvcAutoConfiguration.class }) @ConditionalOnClass({ WebClient.class, WebTestClient.class, WebGraphQlTester.class }) -public class WebGraphQlTesterAutoConfiguration { +public class HttpGraphQlTesterAutoConfiguration { @Bean @ConditionalOnBean(WebTestClient.class) @ConditionalOnMissingBean - public WebGraphQlTester webTestClientGraphQlTester(WebTestClient webTestClient, GraphQlProperties properties) { + public HttpGraphQlTester webTestClientGraphQlTester(WebTestClient webTestClient, GraphQlProperties properties) { WebTestClient mutatedWebTestClient = webTestClient.mutate().baseUrl(properties.getPath()).build(); - return WebGraphQlTester.create(mutatedWebTestClient); + return HttpGraphQlTester.create(mutatedWebTestClient); } } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester.imports b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester.imports new file mode 100644 index 0000000000..78f1ffda4d --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester.imports @@ -0,0 +1,2 @@ +# AutoConfigureHttpGraphQlTester auto-configuration imports +org.springframework.boot.test.autoconfigure.graphql.tester.HttpGraphQlTesterAutoConfiguration \ No newline at end of file diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureWebGraphQlTester.imports b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureWebGraphQlTester.imports deleted file mode 100644 index 9b6b835e16..0000000000 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureWebGraphQlTester.imports +++ /dev/null @@ -1,2 +0,0 @@ -# AutoConfigureWebGraphQlTester auto-configuration imports -org.springframework.boot.test.autoconfigure.graphql.tester.WebGraphQlTesterAutoConfiguration \ No newline at end of file diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/graphql/GraphQlTestIntegrationTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/graphql/GraphQlTestIntegrationTest.java index 18807b332b..fe0cca64a2 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/graphql/GraphQlTestIntegrationTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/graphql/GraphQlTestIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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. @@ -35,7 +35,7 @@ public class GraphQlTestIntegrationTest { @Test void getBookdByIdShouldReturnTestBook() { String query = "{ bookById(id: \"book-1\"){ id name pageCount author } }"; - this.graphQlTester.query(query).execute().path("data.bookById.id").entity(String.class).isEqualTo("42"); + this.graphQlTester.document(query).execute().path("data.bookById.id").entity(String.class).isEqualTo("42"); } } diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.java index d069745393..c75b1f3eef 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.java @@ -62,10 +62,17 @@ import org.springframework.web.context.WebApplicationContext; * including the ability to start a fully running web server listening on a * {@link WebEnvironment#DEFINED_PORT defined} or {@link WebEnvironment#RANDOM_PORT * random} port. - *
+ * Can register the following beans for web tests that are using a fully running web + * server: + *