|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
26 | 26 | import graphql.schema.DataFetchingEnvironmentImpl;
|
27 | 27 | import org.junit.jupiter.api.Test;
|
28 | 28 | import org.mockito.Mockito;
|
| 29 | +import reactor.core.publisher.Mono; |
29 | 30 |
|
30 | 31 | import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
31 | 32 | import org.springframework.graphql.data.GraphQlArgumentBinder;
|
|
35 | 36 | import org.springframework.graphql.data.method.annotation.Argument;
|
36 | 37 | import org.springframework.graphql.data.method.annotation.QueryMapping;
|
37 | 38 | import org.springframework.lang.Nullable;
|
| 39 | +import org.springframework.security.core.annotation.AuthenticationPrincipal; |
| 40 | +import org.springframework.security.core.userdetails.User; |
38 | 41 | import org.springframework.util.ClassUtils;
|
39 |
| -import reactor.core.publisher.Mono; |
40 | 42 |
|
41 | 43 | import static org.assertj.core.api.Assertions.assertThat;
|
42 | 44 |
|
@@ -87,24 +89,20 @@ void callableReturnValue() throws Exception {
|
87 | 89 | }
|
88 | 90 |
|
89 | 91 | @Test
|
90 |
| - void completableFutureReturnValue() throws Exception { |
| 92 | + void completableFutureReturnValue() { |
91 | 93 |
|
92 | 94 | HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
|
| 95 | + resolvers.addResolver(new AuthenticationPrincipalArgumentResolver((beanName, context) -> null)); |
93 | 96 | resolvers.addResolver(new ArgumentMethodArgumentResolver(new GraphQlArgumentBinder()));
|
94 | 97 |
|
95 | 98 | DataFetcherHandlerMethod handlerMethod = new DataFetcherHandlerMethod(
|
96 |
| - handlerMethodFor(new TestController(), "handleAndReturnsCompletableFuture"), resolvers, null, |
97 |
| - new SimpleAsyncTaskExecutor(), false); |
| 99 | + handlerMethodFor(new TestController(), "handleAndReturnFuture"), resolvers, |
| 100 | + null, null, false); |
98 | 101 |
|
99 |
| - DataFetchingEnvironment environment = DataFetchingEnvironmentImpl |
100 |
| - .newDataFetchingEnvironment() |
101 |
| - .build(); |
102 |
| - |
103 |
| - Object result = handlerMethod.invoke(environment); |
| 102 | + Object result = handlerMethod.invoke(DataFetchingEnvironmentImpl.newDataFetchingEnvironment().build()); |
104 | 103 |
|
105 | 104 | assertThat(result).isInstanceOf(Mono.class);
|
106 |
| - Mono<String> mono = (Mono<String>) result; |
107 |
| - assertThat(mono.block()).isEqualTo("B"); |
| 105 | + assertThat(((Mono<String>) result).block()).isEqualTo("B"); |
108 | 106 | }
|
109 | 107 |
|
110 | 108 | private static HandlerMethod handlerMethodFor(Object controller, String methodName) {
|
@@ -133,9 +131,10 @@ public Callable<String> handleAndReturnCallable() {
|
133 | 131 | return () -> "A";
|
134 | 132 | }
|
135 | 133 |
|
136 |
| - public CompletableFuture<String> handleAndReturnsCompletableFuture() { |
| 134 | + public CompletableFuture<String> handleAndReturnFuture(@AuthenticationPrincipal User user) { |
137 | 135 | return CompletableFuture.completedFuture("B");
|
138 | 136 | }
|
| 137 | + |
139 | 138 | }
|
140 | 139 |
|
141 | 140 | }
|
0 commit comments