Update docs and samples on "slice" tests

See gh-75
This commit is contained in:
Rossen Stoyanchev
2021-10-28 12:29:16 +01:00
parent 59d5458333
commit 6dabd7c212
5 changed files with 86 additions and 45 deletions

View File

@@ -20,8 +20,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.graphql.GraphQlService;
import org.springframework.graphql.boot.test.GraphQlTest;
import org.springframework.graphql.test.tester.GraphQlTester;
@@ -29,10 +28,8 @@ import org.springframework.graphql.test.tester.GraphQlTester;
/**
* GraphQL query tests directly via {@link GraphQL}.
*/
@GraphQlTest(controllers = SampleController.class,
includeFilters = @ComponentScan.Filter(
type = FilterType.ASSIGNABLE_TYPE,
classes = {ContextWebFilter.class, DataRepository.class}))
@GraphQlTest(SampleController.class)
@Import(TestConfig.class)
public class QueryTests {
private GraphQlTester graphQlTester;

View File

@@ -22,8 +22,7 @@ import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.graphql.GraphQlService;
import org.springframework.graphql.boot.test.GraphQlTest;
import org.springframework.graphql.test.tester.GraphQlTester;
@@ -31,10 +30,8 @@ import org.springframework.graphql.test.tester.GraphQlTester;
/**
* GraphQL subscription tests directly via {@link GraphQL}.
*/
@GraphQlTest(controllers = SampleController.class,
includeFilters = @ComponentScan.Filter(
type = FilterType.ASSIGNABLE_TYPE,
classes = {ContextWebFilter.class, DataRepository.class}))
@GraphQlTest(SampleController.class)
@Import(TestConfig.class)
public class SubscriptionTests {
private GraphQlTester graphQlTester;

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2002-2021 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 io.spring.sample.graphql;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Collaborator and additional components for {@link SampleController} slice tests.
*/
@Configuration
class TestConfig {
@Bean
public ContextWebFilter contextWebFilter() {
return new ContextWebFilter();
}
@Bean
public DataRepository dataRepository() {
return new DataRepository();
}
}