Refactoring in testFixtures
This commit is contained in:
@@ -71,7 +71,7 @@ public class BatchMappingInvocationTests extends BatchMappingTestSupport {
|
||||
"}";
|
||||
|
||||
Mono<RequestOutput> resultMono = createGraphQlService(controller)
|
||||
.execute(new TestRequestInput(query));
|
||||
.execute(TestRequestInput.forDocument(query));
|
||||
|
||||
List<Course> actualCourses = GraphQlResponse.from(resultMono).toList("courses", Course.class);
|
||||
List<Course> courses = Course.allCourses();
|
||||
@@ -91,7 +91,7 @@ public class BatchMappingInvocationTests extends BatchMappingTestSupport {
|
||||
@ParameterizedTest
|
||||
@MethodSource("controllers")
|
||||
void oneToMany(CourseController controller) {
|
||||
String query = "{ " +
|
||||
String document = "{ " +
|
||||
" courses { " +
|
||||
" id" +
|
||||
" name" +
|
||||
@@ -104,7 +104,7 @@ public class BatchMappingInvocationTests extends BatchMappingTestSupport {
|
||||
"}";
|
||||
|
||||
Mono<RequestOutput> resultMono = createGraphQlService(controller)
|
||||
.execute(new TestRequestInput(query));
|
||||
.execute(TestRequestInput.forDocument(document));
|
||||
|
||||
List<Course> actualCourses = GraphQlResponse.from(resultMono).toList("courses", Course.class);
|
||||
List<Course> courses = Course.allCourses();
|
||||
|
||||
@@ -94,8 +94,8 @@ public class BatchMappingPrincipalMethodArgumentResolverTests extends BatchMappi
|
||||
private void testBatchLoading(PrincipalCourseController controller, Function<Context, Context> contextWriter) {
|
||||
Mono<RequestOutput> resultMono = Mono.delay(Duration.ofMillis(10))
|
||||
.flatMap(aLong -> {
|
||||
String query = "{ courses { id instructor { id } } }";
|
||||
return createGraphQlService(controller).execute(new TestRequestInput(query));
|
||||
String document = "{ courses { id instructor { id } } }";
|
||||
return createGraphQlService(controller).execute(TestRequestInput.forDocument(document));
|
||||
})
|
||||
.contextWrite(contextWriter);
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(new TestRequestInput(document));
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(TestRequestInput.forDocument(document));
|
||||
|
||||
Book book = GraphQlResponse.from(resultMono).toEntity("bookById", Book.class);
|
||||
assertThat(book.getId()).isEqualTo(1);
|
||||
@@ -91,7 +91,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(new TestRequestInput(document));
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(TestRequestInput.forDocument(document));
|
||||
|
||||
List<Book> bookList = GraphQlResponse.from(resultMono).toList("booksByCriteria", Book.class);
|
||||
assertThat(bookList).hasSize(2);
|
||||
@@ -108,7 +108,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(new TestRequestInput(document));
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(TestRequestInput.forDocument(document));
|
||||
|
||||
List<Book> bookList = GraphQlResponse.from(resultMono).toList("booksByProjectedArguments", Book.class);
|
||||
assertThat(bookList).hasSize(2);
|
||||
@@ -125,7 +125,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(new TestRequestInput(document));
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(TestRequestInput.forDocument(document));
|
||||
|
||||
List<Book> bookList = GraphQlResponse.from(resultMono).toList("booksByProjectedCriteria", Book.class);
|
||||
assertThat(bookList).hasSize(2);
|
||||
@@ -144,7 +144,7 @@ public class SchemaMappingInvocationTests {
|
||||
"}";
|
||||
|
||||
AtomicReference<GraphQLContext> contextRef = new AtomicReference<>();
|
||||
RequestInput requestInput = new TestRequestInput(document);
|
||||
RequestInput requestInput = TestRequestInput.forDocument(document);
|
||||
requestInput.configureExecutionInput((executionInput, builder) -> {
|
||||
contextRef.set(executionInput.getGraphQLContext());
|
||||
return executionInput;
|
||||
@@ -170,7 +170,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(new TestRequestInput(document));
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(TestRequestInput.forDocument(document));
|
||||
|
||||
Author author = GraphQlResponse.from(resultMono).toEntity("addAuthor", Author.class);
|
||||
assertThat(author.getId()).isEqualTo(99);
|
||||
@@ -187,7 +187,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(new TestRequestInput(document));
|
||||
Mono<RequestOutput> resultMono = graphQlService().execute(TestRequestInput.forDocument(document));
|
||||
|
||||
Flux<Book> bookFlux = GraphQlResponse.forSubscription(resultMono)
|
||||
.map(response -> response.toEntity("bookSearch", Book.class));
|
||||
|
||||
@@ -151,7 +151,7 @@ public class SchemaMappingPrincipalMethodArgumentResolverTests {
|
||||
}
|
||||
|
||||
private Mono<RequestOutput> executeAsync(
|
||||
String schema, String op, Function<Context, Context> contextWriter) {
|
||||
String schema, String document, Function<Context, Context> contextWriter) {
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.registerBean(GreetingController.class, () -> greetingController);
|
||||
@@ -162,7 +162,7 @@ public class SchemaMappingPrincipalMethodArgumentResolverTests {
|
||||
.toGraphQlService();
|
||||
|
||||
return Mono.delay(Duration.ofMillis(10))
|
||||
.flatMap(aLong -> graphQlService.execute(new TestRequestInput(op)))
|
||||
.flatMap(aLong -> graphQlService.execute(TestRequestInput.forDocument(document)))
|
||||
.contextWrite(contextWriter);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class BatchLoadingTests {
|
||||
|
||||
@Test
|
||||
void batchLoader() {
|
||||
String query = "{ " +
|
||||
String document = "{ " +
|
||||
" booksByCriteria(criteria: {author:\"Orwell\"}) { " +
|
||||
" author {" +
|
||||
" firstName, " +
|
||||
@@ -76,7 +76,7 @@ public class BatchLoadingTests {
|
||||
.dataLoaders(this.registry)
|
||||
.toGraphQlService();
|
||||
|
||||
Mono<RequestOutput> resultMono = service.execute(new TestRequestInput(query));
|
||||
Mono<RequestOutput> resultMono = service.execute(TestRequestInput.forDocument(document));
|
||||
|
||||
List<Book> books = GraphQlResponse.from(resultMono).toList("booksByCriteria", Book.class);
|
||||
assertThat(books).hasSize(2);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ClassNameTypeResolverTests {
|
||||
|
||||
@Test
|
||||
void typeResolutionViaSuperHierarchy() {
|
||||
String query = "" +
|
||||
String document = "" +
|
||||
"query Animals {" +
|
||||
" animals {" +
|
||||
" __typename" +
|
||||
@@ -85,7 +85,7 @@ public class ClassNameTypeResolverTests {
|
||||
|
||||
Mono<RequestOutput> resultMono = graphQlSetup.queryFetcher("animals", env -> animalList)
|
||||
.toGraphQlService()
|
||||
.execute(new TestRequestInput(query));
|
||||
.execute(TestRequestInput.forDocument(document));
|
||||
|
||||
GraphQlResponse response = GraphQlResponse.from(resultMono);
|
||||
for (int i = 0; i < animalList.size(); i++) {
|
||||
@@ -106,7 +106,7 @@ public class ClassNameTypeResolverTests {
|
||||
|
||||
@Test
|
||||
void typeResolutionViaMapping() {
|
||||
String query = "" +
|
||||
String document = "" +
|
||||
"query Sightings {" +
|
||||
" sightings {" +
|
||||
" __typename" +
|
||||
@@ -128,7 +128,7 @@ public class ClassNameTypeResolverTests {
|
||||
Mono<RequestOutput> result = graphQlSetup.queryFetcher("sightings", env -> animalAndPlantList)
|
||||
.typeResolver(typeResolver)
|
||||
.toGraphQlService()
|
||||
.execute(new TestRequestInput(query));
|
||||
.execute(TestRequestInput.forDocument(document));
|
||||
|
||||
GraphQlResponse response = GraphQlResponse.from(result);
|
||||
for (int i = 0; i < animalAndPlantList.size(); i++) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.graphql;
|
||||
|
||||
import org.springframework.graphql.execution.DataLoaderRegistrar;
|
||||
import org.springframework.graphql.web.WebGraphQlSetup;
|
||||
|
||||
/**
|
||||
* Workflow that results in the creation of a {@link GraphQlService} or a
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
||||
import org.springframework.graphql.execution.ThreadLocalAccessor;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebGraphQlSetup;
|
||||
import org.springframework.graphql.web.WebInterceptor;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.graphql;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
@@ -31,12 +29,13 @@ public class TestRequestInput extends RequestInput {
|
||||
private static final AtomicLong idIndex = new AtomicLong();
|
||||
|
||||
|
||||
public TestRequestInput(String document) {
|
||||
private TestRequestInput(String document) {
|
||||
super(document, null, null, String.valueOf(idIndex.incrementAndGet()), null);
|
||||
}
|
||||
|
||||
public TestRequestInput(String doc, String operationName, Map<String, Object> vars, Locale locale, String id) {
|
||||
super(doc, operationName, vars, id, locale);
|
||||
|
||||
public static RequestInput forDocument(String document) {
|
||||
return new TestRequestInput(document);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,11 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.graphql;
|
||||
package org.springframework.graphql.web;
|
||||
|
||||
import org.springframework.graphql.execution.ThreadLocalAccessor;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInterceptor;
|
||||
|
||||
/**
|
||||
* Workflow that results in the creation of a {@link WebGraphQlHandler} or
|
||||
Reference in New Issue
Block a user