Upgrade to Spring GraphQL 1.0.0-SNAPSHOT
This commit switches to 1.0.0-SNAPSHOT for Spring GraphQL, before its upcoming 1.0.0-M6 version. This commit adapts to the changes introduced in spring-projects/spring-graphql#317 : now that `GraphQlClient` has been introduced, `GraphQlTester` has been aligned with the new infrastructure. The `@GraphQlTest` and `@SpringBootTest` testing support is now using different variants for each. All samples have been updated to use the proper GraphQL terminology, see and spring-projects/spring-graphql#310 . See gh-29637
This commit is contained in:
@@ -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.</li>
|
||||
* <li>Registers a {@link org.springframework.boot.test.web.client.TestRestTemplate
|
||||
* TestRestTemplate} and/or
|
||||
* {@link org.springframework.test.web.reactive.server.WebTestClient WebTestClient} bean
|
||||
* for use in web tests that are using a fully running web server.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Can register the following beans for web tests that are using a fully running web
|
||||
* server:
|
||||
* <ul>
|
||||
* <li>{@link org.springframework.boot.test.web.client.TestRestTemplate
|
||||
* TestRestTemplate}</li>
|
||||
* <li>{@link org.springframework.test.web.reactive.server.WebTestClient
|
||||
* WebTestClient}</li>
|
||||
* <li>{@link org.springframework.graphql.test.tester.HttpGraphQlTester
|
||||
* HttpGraphQlTester}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Phillip Webb
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.graphql.test.tester.WebGraphQlTester;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
import org.springframework.test.context.ContextCustomizer;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
import org.springframework.test.context.TestContextAnnotationUtils;
|
||||
@@ -45,32 +45,32 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
/**
|
||||
* {@link ContextCustomizer} for {@link WebGraphQlTester}.
|
||||
* {@link ContextCustomizer} for {@link HttpGraphQlTester}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
class WebGraphQlTesterContextCustomizer implements ContextCustomizer {
|
||||
class HttpGraphQlTesterContextCustomizer implements ContextCustomizer {
|
||||
|
||||
@Override
|
||||
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
|
||||
SpringBootTest springBootTest = TestContextAnnotationUtils.findMergedAnnotation(mergedConfig.getTestClass(),
|
||||
SpringBootTest.class);
|
||||
if (springBootTest.webEnvironment().isEmbedded()) {
|
||||
registerWebGraphQlTester(context);
|
||||
registerHttpGraphQlTester(context);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerWebGraphQlTester(ConfigurableApplicationContext context) {
|
||||
private void registerHttpGraphQlTester(ConfigurableApplicationContext context) {
|
||||
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
|
||||
if (beanFactory instanceof BeanDefinitionRegistry) {
|
||||
registerWebGraphQlTester((BeanDefinitionRegistry) beanFactory);
|
||||
registerHttpGraphQlTester((BeanDefinitionRegistry) beanFactory);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerWebGraphQlTester(BeanDefinitionRegistry registry) {
|
||||
RootBeanDefinition definition = new RootBeanDefinition(WebGraphQlTesterRegistrar.class);
|
||||
private void registerHttpGraphQlTester(BeanDefinitionRegistry registry) {
|
||||
RootBeanDefinition definition = new RootBeanDefinition(HttpGraphQlTesterRegistrar.class);
|
||||
definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
registry.registerBeanDefinition(WebGraphQlTesterRegistrar.class.getName(), definition);
|
||||
registry.registerBeanDefinition(HttpGraphQlTesterRegistrar.class.getName(), definition);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +83,7 @@ class WebGraphQlTesterContextCustomizer implements ContextCustomizer {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
|
||||
private static class WebGraphQlTesterRegistrar
|
||||
private static class HttpGraphQlTesterRegistrar
|
||||
implements BeanDefinitionRegistryPostProcessor, Ordered, BeanFactoryAware {
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
@@ -96,9 +96,9 @@ class WebGraphQlTesterContextCustomizer implements ContextCustomizer {
|
||||
@Override
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
|
||||
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) this.beanFactory,
|
||||
WebGraphQlTester.class, false, false).length == 0) {
|
||||
registry.registerBeanDefinition(WebGraphQlTester.class.getName(),
|
||||
new RootBeanDefinition(WebGraphQlTesterFactory.class));
|
||||
HttpGraphQlTester.class, false, false).length == 0) {
|
||||
registry.registerBeanDefinition(HttpGraphQlTester.class.getName(),
|
||||
new RootBeanDefinition(HttpGraphQlTesterFactory.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class WebGraphQlTesterContextCustomizer implements ContextCustomizer {
|
||||
|
||||
}
|
||||
|
||||
public static class WebGraphQlTesterFactory implements FactoryBean<WebGraphQlTester>, ApplicationContextAware {
|
||||
public static class HttpGraphQlTesterFactory implements FactoryBean<HttpGraphQlTester>, ApplicationContextAware {
|
||||
|
||||
private static final String SERVLET_APPLICATION_CONTEXT_CLASS = "org.springframework.web.context.WebApplicationContext";
|
||||
|
||||
@@ -122,7 +122,7 @@ class WebGraphQlTesterContextCustomizer implements ContextCustomizer {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private WebGraphQlTester object;
|
||||
private HttpGraphQlTester object;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
@@ -136,23 +136,23 @@ class WebGraphQlTesterContextCustomizer implements ContextCustomizer {
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return WebGraphQlTester.class;
|
||||
return HttpGraphQlTester.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebGraphQlTester getObject() throws Exception {
|
||||
public HttpGraphQlTester getObject() throws Exception {
|
||||
if (this.object == null) {
|
||||
this.object = createGraphQlTester();
|
||||
}
|
||||
return this.object;
|
||||
}
|
||||
|
||||
private WebGraphQlTester createGraphQlTester() {
|
||||
private HttpGraphQlTester 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 WebGraphQlTester.create(mutatedWebClient);
|
||||
return HttpGraphQlTester.create(mutatedWebClient);
|
||||
}
|
||||
|
||||
private String getBaseUrl(boolean sslEnabled, String port) {
|
||||
@@ -19,7 +19,7 @@ package org.springframework.boot.test.graphql.tester;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.graphql.test.tester.GraphQlTester;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
import org.springframework.test.context.ContextConfigurationAttributes;
|
||||
import org.springframework.test.context.ContextCustomizer;
|
||||
import org.springframework.test.context.ContextCustomizerFactory;
|
||||
@@ -27,14 +27,14 @@ import org.springframework.test.context.TestContextAnnotationUtils;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* {@link ContextCustomizerFactory} for {@link GraphQlTester}.
|
||||
* {@link ContextCustomizerFactory} for {@link HttpGraphQlTester}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @see WebGraphQlTesterContextCustomizer
|
||||
* @see HttpGraphQlTesterContextCustomizer
|
||||
*/
|
||||
class WebGraphQlTesterContextCustomizerFactory implements ContextCustomizerFactory {
|
||||
class HttpGraphQlTesterContextCustomizerFactory implements ContextCustomizerFactory {
|
||||
|
||||
private static final String WEBGRAPHQLTESTER_CLASS = "org.springframework.graphql.test.tester.WebGraphQlTester";
|
||||
private static final String HTTPGRAPHQLTESTER_CLASS = "org.springframework.graphql.test.tester.HttpGraphQlTester";
|
||||
|
||||
private static final String WEBTESTCLIENT_CLASS = "org.springframework.test.web.reactive.server.WebTestClient";
|
||||
|
||||
@@ -43,12 +43,12 @@ class WebGraphQlTesterContextCustomizerFactory implements ContextCustomizerFacto
|
||||
List<ContextConfigurationAttributes> configAttributes) {
|
||||
SpringBootTest springBootTest = TestContextAnnotationUtils.findMergedAnnotation(testClass,
|
||||
SpringBootTest.class);
|
||||
return (springBootTest != null && isGraphQlTesterPresent()) ? new WebGraphQlTesterContextCustomizer() : null;
|
||||
return (springBootTest != null && isGraphQlTesterPresent()) ? new HttpGraphQlTesterContextCustomizer() : null;
|
||||
}
|
||||
|
||||
private boolean isGraphQlTesterPresent() {
|
||||
return ClassUtils.isPresent(WEBTESTCLIENT_CLASS, getClass().getClassLoader())
|
||||
&& ClassUtils.isPresent(WEBGRAPHQLTESTER_CLASS, getClass().getClassLoader());
|
||||
&& ClassUtils.isPresent(HTTPGRAPHQLTESTER_CLASS, getClass().getClassLoader());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
org.springframework.test.context.ContextCustomizerFactory=\
|
||||
org.springframework.boot.test.context.ImportsContextCustomizerFactory,\
|
||||
org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizerFactory,\
|
||||
org.springframework.boot.test.graphql.tester.WebGraphQlTesterContextCustomizerFactory,\
|
||||
org.springframework.boot.test.graphql.tester.HttpGraphQlTesterContextCustomizerFactory,\
|
||||
org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory,\
|
||||
org.springframework.boot.test.mock.mockito.MockitoContextCustomizerFactory,\
|
||||
org.springframework.boot.test.web.client.TestRestTemplateContextCustomizerFactory,\
|
||||
|
||||
@@ -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.WebGraphQlTester;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.reactive.ContextPathCompositeHandler;
|
||||
@@ -38,21 +38,21 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
/**
|
||||
* Integration test for {@link WebGraphQlTesterContextCustomizer}.
|
||||
* Integration test for {@link HttpGraphQlTesterContextCustomizer}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = "spring.main.web-application-type=reactive")
|
||||
@DirtiesContext
|
||||
class WebGraphQlTesterContextCustomizerIntegrationTests {
|
||||
class HttpGraphQlTesterContextCustomizerIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
WebGraphQlTester graphQlTester;
|
||||
HttpGraphQlTester graphQlTester;
|
||||
|
||||
@Test
|
||||
void shouldHandleGraphQlRequests() {
|
||||
this.graphQlTester.query("{}").executeAndVerify();
|
||||
this.graphQlTester.document("{}").executeAndVerify();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@@ -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.WebGraphQlTester;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.reactive.ContextPathCompositeHandler;
|
||||
@@ -38,21 +38,21 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebGraphQlTesterContextCustomizer} with a custom context path for a
|
||||
* Tests for {@link HttpGraphQlTesterContextCustomizer} 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 WebGraphQlTesterContextCustomizerWithCustomBasePathTests {
|
||||
class HttpGraphQlTesterContextCustomizerWithCustomBasePathTests {
|
||||
|
||||
@Autowired
|
||||
WebGraphQlTester graphQlTester;
|
||||
HttpGraphQlTester graphQlTester;
|
||||
|
||||
@Test
|
||||
void shouldHandleGraphQlRequests() {
|
||||
this.graphQlTester.query("{}").executeAndVerify();
|
||||
this.graphQlTester.document("{}").executeAndVerify();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@@ -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.WebGraphQlTester;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -32,21 +32,21 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebGraphQlTesterContextCustomizer} with a custom context path for a
|
||||
* Tests for {@link HttpGraphQlTesterContextCustomizer} 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 WebGraphQlTesterContextCustomizerWithCustomContextPathTests {
|
||||
class HttpGraphQlTesterContextCustomizerWithCustomContextPathTests {
|
||||
|
||||
@Autowired
|
||||
WebGraphQlTester graphQlTester;
|
||||
HttpGraphQlTester graphQlTester;
|
||||
|
||||
@Test
|
||||
void shouldHandleGraphQlRequests() {
|
||||
this.graphQlTester.query("{}").executeAndVerify();
|
||||
this.graphQlTester.document("{}").executeAndVerify();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
Reference in New Issue
Block a user