Decouple GraphQlTester from Web details

Closes gh-65
This commit is contained in:
Rossen Stoyanchev
2021-06-14 14:21:02 +01:00
parent 17bf9ee287
commit de234c94c4
10 changed files with 589 additions and 383 deletions

View File

@@ -24,6 +24,7 @@ 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.test.tester.WebGraphQlTester;
import org.springframework.graphql.web.WebGraphQlHandler;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.client.WebClient;
@@ -45,9 +46,9 @@ public class GraphQlTesterAutoConfiguration {
public static class WebTestClientGraphQlTesterConfiguration {
@Bean
public GraphQlTester clientGraphQlTester(WebTestClient webTestClient, GraphQlProperties properties) {
public WebGraphQlTester clientGraphQlTester(WebTestClient webTestClient, GraphQlProperties properties) {
WebTestClient mutatedWebTestClient = webTestClient.mutate().baseUrl(properties.getPath()).build();
return GraphQlTester.create(mutatedWebTestClient);
return WebGraphQlTester.create(mutatedWebTestClient);
}
}
@@ -58,8 +59,8 @@ public class GraphQlTesterAutoConfiguration {
public static class WebGraphQlHandlerGraphQlTesterConfiguration {
@Bean
public GraphQlTester handlerGraphQlTester(WebGraphQlHandler handler) {
return GraphQlTester.create(handler);
public WebGraphQlTester handlerGraphQlTester(WebGraphQlHandler handler) {
return WebGraphQlTester.create(handler);
}
}

View File

@@ -35,6 +35,7 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;
import org.springframework.test.context.ContextCustomizer;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.TestContextAnnotationUtils;
@@ -142,12 +143,12 @@ class GraphQlTesterContextCustomizer implements ContextCustomizer {
return this.object;
}
private GraphQlTester createGraphQlTester() {
private WebGraphQlTester createGraphQlTester() {
WebTestClient webTestClient = this.applicationContext.getBean(WebTestClient.class);
boolean sslEnabled = isSslEnabled(this.applicationContext);
String port = this.applicationContext.getEnvironment().getProperty("local.server.port", "8080");
WebTestClient mutatedWebClient = webTestClient.mutate().baseUrl(getBaseUrl(sslEnabled, port)).build();
return GraphQlTester.create(mutatedWebClient);
return WebGraphQlTester.create(mutatedWebClient);
}
private String getBaseUrl(boolean sslEnabled, String port) {