|
25 | 25 | import java.util.Set;
|
26 | 26 | import java.util.function.Function;
|
27 | 27 | import java.util.stream.Collectors;
|
| 28 | +import java.util.stream.Stream; |
28 | 29 |
|
29 | 30 | import graphql.ExecutionResult;
|
30 | 31 | import org.junit.jupiter.params.ParameterizedTest;
|
| 32 | +import org.junit.jupiter.params.provider.Arguments; |
31 | 33 | import org.junit.jupiter.params.provider.MethodSource;
|
32 | 34 | import reactor.core.publisher.Flux;
|
33 | 35 | import reactor.core.publisher.Mono;
|
|
47 | 49 | import org.springframework.stereotype.Controller;
|
48 | 50 |
|
49 | 51 | import static org.assertj.core.api.Assertions.assertThat;
|
| 52 | +import static org.junit.jupiter.api.Named.named; |
| 53 | +import static org.junit.jupiter.params.provider.Arguments.arguments; |
50 | 54 |
|
51 | 55 | /**
|
52 | 56 | * Test GraphQL requests handled through {@code @BatchMapping} methods.
|
@@ -91,13 +95,13 @@ public class BatchMappingInvocationTests {
|
91 | 95 | "}";
|
92 | 96 |
|
93 | 97 |
|
94 |
| - private static Class<?>[] controllerClasses() { |
95 |
| - return new Class[] { |
96 |
| - BatchFluxController.class, |
97 |
| - BatchListController.class, |
98 |
| - BatchMonoMapController.class, |
99 |
| - BatchMapController.class |
100 |
| - }; |
| 98 | + private static Stream<Arguments> controllerClasses() { |
| 99 | + return Stream.of( |
| 100 | + arguments(named("Returning Mono<Map<K,V>>", BatchMonoMapController.class)), |
| 101 | + arguments(named("Returning Map<K,V>", BatchMapController.class)), |
| 102 | + arguments(named("Returning Flux<V>", BatchFluxController.class)), |
| 103 | + arguments(named("Returning List<V>", BatchListController.class)) |
| 104 | + ); |
101 | 105 | }
|
102 | 106 |
|
103 | 107 | @ParameterizedTest
|
@@ -199,60 +203,60 @@ public Collection<Course> courses() {
|
199 | 203 | }
|
200 | 204 |
|
201 | 205 | @Controller
|
202 |
| - private static class BatchFluxController extends CourseController { |
| 206 | + private static class BatchMonoMapController extends CourseController { |
203 | 207 |
|
204 | 208 | @BatchMapping
|
205 |
| - public Flux<Person> instructor(List<Course> courses) { |
206 |
| - return Flux.fromIterable(courses).map(Course::instructor); |
| 209 | + public Mono<Map<Course, Person>> instructor(List<Course> courses) { |
| 210 | + return Flux.fromIterable(Course.allCourses()) |
| 211 | + .collect(Collectors.toMap(Function.identity(), Course::instructor)); |
207 | 212 | }
|
208 | 213 |
|
209 | 214 | @BatchMapping
|
210 |
| - public Flux<List<Person>> students(List<Course> courses) { |
211 |
| - return Flux.fromIterable(courses).map(Course::students); |
| 215 | + public Mono<Map<Course, List<Person>>> students(Set<Course> courses) { |
| 216 | + return Flux.fromIterable(courses).collect(Collectors.toMap(Function.identity(), Course::students)); |
212 | 217 | }
|
213 | 218 | }
|
214 | 219 |
|
215 | 220 | @Controller
|
216 |
| - private static class BatchListController extends CourseController { |
| 221 | + private static class BatchMapController extends CourseController { |
217 | 222 |
|
218 | 223 | @BatchMapping
|
219 |
| - public List<Person> instructor(List<Course> courses) { |
220 |
| - return courses.stream().map(Course::instructor).collect(Collectors.toList()); |
| 224 | + public Map<Course, Person> instructor(List<Course> courses) { |
| 225 | + return Course.allCourses().stream().collect( |
| 226 | + Collectors.toMap(Function.identity(), Course::instructor)); |
221 | 227 | }
|
222 | 228 |
|
223 | 229 | @BatchMapping
|
224 |
| - public List<List<Person>> students(List<Course> courses) { |
225 |
| - return courses.stream().map(Course::students).collect(Collectors.toList()); |
| 230 | + public Map<Course, List<Person>> students(List<Course> courses) { |
| 231 | + return courses.stream().collect(Collectors.toMap(Function.identity(), Course::students)); |
226 | 232 | }
|
227 | 233 | }
|
228 | 234 |
|
229 | 235 | @Controller
|
230 |
| - private static class BatchMonoMapController extends CourseController { |
| 236 | + private static class BatchFluxController extends CourseController { |
231 | 237 |
|
232 | 238 | @BatchMapping
|
233 |
| - public Mono<Map<Course, Person>> instructor(List<Course> courses) { |
234 |
| - return Flux.fromIterable(Course.allCourses()) |
235 |
| - .collect(Collectors.toMap(Function.identity(), Course::instructor)); |
| 239 | + public Flux<Person> instructor(List<Course> courses) { |
| 240 | + return Flux.fromIterable(courses).map(Course::instructor); |
236 | 241 | }
|
237 | 242 |
|
238 | 243 | @BatchMapping
|
239 |
| - public Mono<Map<Course, List<Person>>> students(Set<Course> courses) { |
240 |
| - return Flux.fromIterable(courses).collect(Collectors.toMap(Function.identity(), Course::students)); |
| 244 | + public Flux<List<Person>> students(List<Course> courses) { |
| 245 | + return Flux.fromIterable(courses).map(Course::students); |
241 | 246 | }
|
242 | 247 | }
|
243 | 248 |
|
244 | 249 | @Controller
|
245 |
| - private static class BatchMapController extends CourseController { |
| 250 | + private static class BatchListController extends CourseController { |
246 | 251 |
|
247 | 252 | @BatchMapping
|
248 |
| - public Map<Course, Person> instructor(List<Course> courses) { |
249 |
| - return Course.allCourses().stream().collect( |
250 |
| - Collectors.toMap(Function.identity(), Course::instructor)); |
| 253 | + public List<Person> instructor(List<Course> courses) { |
| 254 | + return courses.stream().map(Course::instructor).collect(Collectors.toList()); |
251 | 255 | }
|
252 | 256 |
|
253 | 257 | @BatchMapping
|
254 |
| - public Map<Course, List<Person>> students(List<Course> courses) { |
255 |
| - return courses.stream().collect(Collectors.toMap(Function.identity(), Course::students)); |
| 258 | + public List<List<Person>> students(List<Course> courses) { |
| 259 | + return courses.stream().map(Course::students).collect(Collectors.toList()); |
256 | 260 | }
|
257 | 261 | }
|
258 | 262 |
|
|
0 commit comments