Skip to content

Commit 095d720

Browse files
committed
Simplify request execution in tests
1 parent 7aaf4b9 commit 095d720

14 files changed

+105
-71
lines changed

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingInvocationTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@
3131

3232
import org.springframework.graphql.ExecutionGraphQlResponse;
3333
import org.springframework.graphql.ResponseHelper;
34-
import org.springframework.graphql.TestExecutionRequest;
3534
import org.springframework.graphql.data.method.annotation.BatchMapping;
3635
import org.springframework.stereotype.Controller;
3736

@@ -72,8 +71,7 @@ void oneToOne(CourseController controller) {
7271
" }" +
7372
"}";
7473

75-
Mono<ExecutionGraphQlResponse> responseMono = createGraphQlService(controller)
76-
.execute(TestExecutionRequest.forDocument(query));
74+
Mono<ExecutionGraphQlResponse> responseMono = createGraphQlService(controller).execute(query);
7775

7876
List<Course> actualCourses = ResponseHelper.forResponse(responseMono).toList("courses", Course.class);
7977
List<Course> courses = Course.allCourses();
@@ -105,8 +103,7 @@ void oneToMany(CourseController controller) {
105103
" }" +
106104
"}";
107105

108-
Mono<ExecutionGraphQlResponse> responseMono = createGraphQlService(controller)
109-
.execute(TestExecutionRequest.forDocument(document));
106+
Mono<ExecutionGraphQlResponse> responseMono = createGraphQlService(controller).execute(document);
110107

111108
List<Course> actualCourses = ResponseHelper.forResponse(responseMono).toList("courses", Course.class);
112109
List<Course> courses = Course.allCourses();

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingPrincipalMethodArgumentResolverTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -94,7 +94,7 @@ private void testBatchLoading(PrincipalCourseController controller, Function<Con
9494
Mono<ExecutionGraphQlResponse> responseMono = Mono.delay(Duration.ofMillis(10))
9595
.flatMap(aLong -> {
9696
String document = "{ courses { id instructor { id } } }";
97-
return createGraphQlService(controller).execute(TestExecutionRequest.forDocument(document));
97+
return createGraphQlService(controller).execute(document);
9898
})
9999
.contextWrite(contextWriter);
100100

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingTestSupport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,8 +29,8 @@
2929

3030
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3131
import org.springframework.core.task.SimpleAsyncTaskExecutor;
32-
import org.springframework.graphql.ExecutionGraphQlService;
3332
import org.springframework.graphql.GraphQlSetup;
33+
import org.springframework.graphql.TestExecutionGraphQlService;
3434
import org.springframework.graphql.data.method.annotation.QueryMapping;
3535
import org.springframework.graphql.execution.BatchLoaderRegistry;
3636
import org.springframework.graphql.execution.DefaultBatchLoaderRegistry;
@@ -80,7 +80,7 @@ public class BatchMappingTestSupport {
8080
"}";
8181

8282

83-
protected ExecutionGraphQlService createGraphQlService(CourseController controller) {
83+
protected TestExecutionGraphQlService createGraphQlService(CourseController controller) {
8484
BatchLoaderRegistry registry = new DefaultBatchLoaderRegistry();
8585

8686
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingInvocationTests.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
import org.springframework.graphql.BookSource;
4141
import org.springframework.graphql.ExecutionGraphQlRequest;
4242
import org.springframework.graphql.ExecutionGraphQlResponse;
43-
import org.springframework.graphql.ExecutionGraphQlService;
4443
import org.springframework.graphql.GraphQlSetup;
4544
import org.springframework.graphql.ResponseHelper;
45+
import org.springframework.graphql.TestExecutionGraphQlService;
4646
import org.springframework.graphql.TestExecutionRequest;
4747
import org.springframework.graphql.data.method.annotation.Argument;
4848
import org.springframework.graphql.data.method.annotation.GraphQlExceptionHandler;
@@ -80,7 +80,7 @@ void queryWithScalarArgument() {
8080
" }" +
8181
"}";
8282

83-
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
83+
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
8484

8585
Book book = ResponseHelper.forResponse(responseMono).toEntity("bookById", Book.class);
8686
assertThat(book.getId()).isEqualTo(1);
@@ -100,7 +100,7 @@ void queryWithObjectArgument() {
100100
" }" +
101101
"}";
102102

103-
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
103+
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
104104

105105
List<Book> bookList = ResponseHelper.forResponse(responseMono).toList("booksByCriteria", Book.class);
106106
assertThat(bookList).hasSize(2);
@@ -117,7 +117,7 @@ void queryWithProjectionOnArgumentsMap() {
117117
" }" +
118118
"}";
119119

120-
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
120+
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
121121

122122
List<Book> bookList = ResponseHelper.forResponse(responseMono).toList("booksByProjectedArguments", Book.class);
123123
assertThat(bookList).hasSize(2);
@@ -134,7 +134,7 @@ void queryWithProjectionOnNamedArgument() {
134134
" }" +
135135
"}";
136136

137-
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
137+
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
138138

139139
List<Book> bookList = ResponseHelper.forResponse(responseMono).toList("booksByProjectedCriteria", Book.class);
140140
assertThat(bookList).hasSize(2);
@@ -179,7 +179,7 @@ void mutation() {
179179
" }" +
180180
"}";
181181

182-
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
182+
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
183183

184184
Author author = ResponseHelper.forResponse(responseMono).toEntity("addAuthor", Author.class);
185185
assertThat(author.getId()).isEqualTo(99);
@@ -196,7 +196,7 @@ void subscription() {
196196
" }" +
197197
"}";
198198

199-
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
199+
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
200200

201201
Flux<Book> bookFlux = ResponseHelper.forSubscription(responseMono)
202202
.map(response -> response.toEntity("bookSearch", Book.class));
@@ -222,8 +222,7 @@ void handleExceptionFromQuery() {
222222
" }" +
223223
"}";
224224

225-
Mono<ExecutionGraphQlResponse> responseMono =
226-
graphQlService().execute(TestExecutionRequest.forDocument(document));
225+
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
227226

228227
ResponseHelper responseHelper = ResponseHelper.forResponse(responseMono);
229228
assertThat(responseHelper.errorCount()).isEqualTo(1);
@@ -246,12 +245,12 @@ void handleExceptionWithResolverWhenNoAnnotatedExceptionHandlerMatches() {
246245
.message("Rejected: " + ex.getMessage())
247246
.build()));
248247

249-
ExecutionGraphQlService service = graphQlService((configurer, setup) -> {
248+
TestExecutionGraphQlService service = graphQlService((configurer, setup) -> {
250249
setup.exceptionResolver(configurer.getExceptionResolver()); // First @ControllerAdvice (no match)
251250
setup.exceptionResolver(resolver); // Then resolver
252251
});
253252

254-
Mono<ExecutionGraphQlResponse> responseMono = service.execute(TestExecutionRequest.forDocument(document));
253+
Mono<ExecutionGraphQlResponse> responseMono = service.execute(document);
255254

256255
ResponseHelper responseHelper = ResponseHelper.forResponse(responseMono);
257256
assertThat(responseHelper.errorCount()).isEqualTo(1);
@@ -268,8 +267,7 @@ void handleExceptionFromSubscription() {
268267
" }" +
269268
"}";
270269

271-
Mono<ExecutionGraphQlResponse> responseMono =
272-
graphQlService().execute(TestExecutionRequest.forDocument(document));
270+
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
273271

274272
Flux<Book> bookFlux = ResponseHelper.forSubscription(responseMono)
275273
.map(response -> response.toEntity("bookSearch", Book.class));
@@ -286,11 +284,11 @@ void handleExceptionFromSubscription() {
286284
}
287285

288286

289-
private ExecutionGraphQlService graphQlService() {
287+
private TestExecutionGraphQlService graphQlService() {
290288
return graphQlService((configurer, setup) -> {});
291289
}
292290

293-
private ExecutionGraphQlService graphQlService(BiConsumer<AnnotatedControllerConfigurer, GraphQlSetup> consumer) {
291+
private TestExecutionGraphQlService graphQlService(BiConsumer<AnnotatedControllerConfigurer, GraphQlSetup> consumer) {
294292
BatchLoaderRegistry registry = new DefaultBatchLoaderRegistry();
295293

296294
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPaginationTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
import org.springframework.graphql.Book;
2828
import org.springframework.graphql.BookSource;
2929
import org.springframework.graphql.ExecutionGraphQlResponse;
30-
import org.springframework.graphql.ExecutionGraphQlService;
3130
import org.springframework.graphql.GraphQlSetup;
3231
import org.springframework.graphql.ResponseHelper;
33-
import org.springframework.graphql.TestExecutionRequest;
32+
import org.springframework.graphql.TestExecutionGraphQlService;
3433
import org.springframework.graphql.data.method.annotation.QueryMapping;
3534
import org.springframework.graphql.data.pagination.CursorStrategy;
3635
import org.springframework.graphql.data.query.ScrollPositionCursorStrategy;
@@ -50,9 +49,8 @@ public class SchemaMappingPaginationTests {
5049
@Test
5150
void forwardPagination() {
5251

53-
String query = BookSource.booksConnectionQuery("first:2, after:\"O_3\"");
54-
55-
Mono<ExecutionGraphQlResponse> response = graphQlService().execute(TestExecutionRequest.forDocument(query));
52+
String document = BookSource.booksConnectionQuery("first:2, after:\"O_3\"");
53+
Mono<ExecutionGraphQlResponse> response = graphQlService().execute(document);
5654

5755
ResponseHelper.forResponse(response).assertData(
5856
"{\"books\":{" +
@@ -68,7 +66,7 @@ void forwardPagination() {
6866
"}}}");
6967
}
7068

71-
private ExecutionGraphQlService graphQlService() {
69+
private TestExecutionGraphQlService graphQlService() {
7270

7371
ScrollPositionCursorStrategy cursorStrategy = new ScrollPositionCursorStrategy();
7472

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPrincipalMethodArgumentResolverTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,10 +33,9 @@
3333
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3434
import org.springframework.core.MethodParameter;
3535
import org.springframework.graphql.ExecutionGraphQlResponse;
36-
import org.springframework.graphql.ExecutionGraphQlService;
3736
import org.springframework.graphql.GraphQlSetup;
3837
import org.springframework.graphql.ResponseHelper;
39-
import org.springframework.graphql.TestExecutionRequest;
38+
import org.springframework.graphql.TestExecutionGraphQlService;
4039
import org.springframework.graphql.data.method.annotation.QueryMapping;
4140
import org.springframework.graphql.data.method.annotation.SubscriptionMapping;
4241
import org.springframework.lang.Nullable;
@@ -156,12 +155,12 @@ private Mono<ExecutionGraphQlResponse> executeAsync(
156155
context.registerBean(GreetingController.class, () -> greetingController);
157156
context.refresh();
158157

159-
ExecutionGraphQlService graphQlService = GraphQlSetup.schemaContent(schema)
158+
TestExecutionGraphQlService graphQlService = GraphQlSetup.schemaContent(schema)
160159
.runtimeWiringForAnnotatedControllers(context)
161160
.toGraphQlService();
162161

163162
return Mono.delay(Duration.ofMillis(10))
164-
.flatMap(aLong -> graphQlService.execute(TestExecutionRequest.forDocument(document)))
163+
.flatMap(aLong -> graphQlService.execute(document))
165164
.contextWrite(contextWriter);
166165
}
167166

spring-graphql/src/test/java/org/springframework/graphql/data/pagination/ConnectionFieldTypeVisitorTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import org.springframework.graphql.ExecutionGraphQlResponse;
2828
import org.springframework.graphql.GraphQlSetup;
2929
import org.springframework.graphql.ResponseHelper;
30-
import org.springframework.graphql.TestExecutionRequest;
31-
import org.springframework.graphql.execution.ConnectionTypeDefinitionConfigurer;
3230

3331
/**
3432
* Unit tests for {@link ConnectionFieldTypeVisitor}.
@@ -49,7 +47,7 @@ void paginationDataFetcher() {
4947
.dataFetcher("Query", "books", env -> BookSource.books())
5048
.connectionSupport(adapter)
5149
.toGraphQlService()
52-
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery(null)));
50+
.execute(BookSource.booksConnectionQuery(null));
5351

5452
ResponseHelper.forResponse(response).assertData(
5553
"{\"books\":{" +
@@ -78,7 +76,7 @@ void trivialDataFetcherIsSkipped() {
7876
.dataFetcher("Query", "books", new PropertyDataFetcher<>("books"))
7977
.connectionSupport(new ListConnectionAdapter())
8078
.toGraphQlService()
81-
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery(null)));
79+
.execute(BookSource.booksConnectionQuery(null));
8280

8381
ResponseHelper.forResponse(response).assertData("{\"books\":null}");
8482
}
@@ -90,7 +88,7 @@ void nullValueTreatedAsEmptyConnection() {
9088
.dataFetcher("Query", "books", environment -> null)
9189
.connectionSupport(new ListConnectionAdapter())
9290
.toGraphQlService()
93-
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery(null)));
91+
.execute(BookSource.booksConnectionQuery(null));
9492

9593
ResponseHelper.forResponse(response).assertData(
9694
"{\"books\":{" +

spring-graphql/src/test/java/org/springframework/graphql/execution/BatchLoadingTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,10 +28,10 @@
2828
import org.springframework.graphql.Book;
2929
import org.springframework.graphql.BookSource;
3030
import org.springframework.graphql.ExecutionGraphQlResponse;
31-
import org.springframework.graphql.ResponseHelper;
3231
import org.springframework.graphql.ExecutionGraphQlService;
3332
import org.springframework.graphql.GraphQlSetup;
34-
import org.springframework.graphql.TestExecutionRequest;
33+
import org.springframework.graphql.ResponseHelper;
34+
import org.springframework.graphql.TestExecutionGraphQlService;
3535

3636
import static org.assertj.core.api.Assertions.assertThat;
3737

@@ -60,7 +60,7 @@ void batchLoader() {
6060
this.registry.forTypePair(Long.class, Author.class)
6161
.registerBatchLoader((ids, env) -> Flux.fromIterable(ids).map(BookSource::getAuthor));
6262

63-
ExecutionGraphQlService service = GraphQlSetup.schemaResource(BookSource.schema)
63+
TestExecutionGraphQlService service = GraphQlSetup.schemaResource(BookSource.schema)
6464
.queryFetcher("booksByCriteria", env -> {
6565
Map<String, Object> criteria = env.getArgument("criteria");
6666
String authorName = (String) criteria.get("author");
@@ -76,7 +76,7 @@ void batchLoader() {
7676
.dataLoaders(this.registry)
7777
.toGraphQlService();
7878

79-
Mono<ExecutionGraphQlResponse> responseMono = service.execute(TestExecutionRequest.forDocument(document));
79+
Mono<ExecutionGraphQlResponse> responseMono = service.execute(document);
8080

8181
List<Book> books = ResponseHelper.forResponse(responseMono).toList("booksByCriteria", Book.class);
8282
assertThat(books).hasSize(2);

spring-graphql/src/test/java/org/springframework/graphql/execution/ClassNameTypeResolverTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,9 +23,8 @@
2323
import reactor.core.publisher.Mono;
2424

2525
import org.springframework.graphql.ExecutionGraphQlResponse;
26-
import org.springframework.graphql.ResponseHelper;
2726
import org.springframework.graphql.GraphQlSetup;
28-
import org.springframework.graphql.TestExecutionRequest;
27+
import org.springframework.graphql.ResponseHelper;
2928

3029
import static org.assertj.core.api.Assertions.assertThat;
3130

@@ -85,7 +84,7 @@ void typeResolutionViaSuperHierarchy() {
8584

8685
Mono<ExecutionGraphQlResponse> responseMono = graphQlSetup.queryFetcher("animals", env -> animalList)
8786
.toGraphQlService()
88-
.execute(TestExecutionRequest.forDocument(document));
87+
.execute(document);
8988

9089
ResponseHelper response = ResponseHelper.forResponse(responseMono);
9190
for (int i = 0; i < animalList.size(); i++) {
@@ -128,7 +127,7 @@ void typeResolutionViaMapping() {
128127
Mono<ExecutionGraphQlResponse> responseMono = graphQlSetup.queryFetcher("sightings", env -> animalAndPlantList)
129128
.typeResolver(typeResolver)
130129
.toGraphQlService()
131-
.execute(TestExecutionRequest.forDocument(document));
130+
.execute(document);
132131

133132
ResponseHelper response = ResponseHelper.forResponse(responseMono);
134133
for (int i = 0; i < animalAndPlantList.size(); i++) {

spring-graphql/src/test/java/org/springframework/graphql/execution/ConnectionTypeDefinitionConfigurerTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.graphql.ExecutionGraphQlResponse;
3535
import org.springframework.graphql.GraphQlSetup;
3636
import org.springframework.graphql.ResponseHelper;
37-
import org.springframework.graphql.TestExecutionRequest;
3837

3938
/**
4039
* Unit tests for {@link ConnectionTypeDefinitionConfigurer}.
@@ -57,7 +56,7 @@ void connectionTypeGeneration() {
5756
Mono<ExecutionGraphQlResponse> response = initGraphQlSetup()
5857
.dataFetcher("Query", "books", dataFetcher)
5958
.toGraphQlService()
60-
.execute(TestExecutionRequest.forDocument(document));
59+
.execute(document);
6160

6261
ResponseHelper.forResponse(response).assertData(
6362
"{\"books\":{" +

0 commit comments

Comments
 (0)