1
+ /*
2
+ * Copyright 2020-2022 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package org .springframework .graphql .data .method .annotation .support ;
18
+
19
+
20
+ import java .util .Collections ;
21
+ import java .util .Map ;
22
+
23
+ import org .junit .jupiter .api .Test ;
24
+
25
+ import org .springframework .core .MethodParameter ;
26
+ import org .springframework .graphql .Book ;
27
+ import org .springframework .graphql .data .method .HandlerMethodArgumentResolver ;
28
+ import org .springframework .graphql .data .method .annotation .Argument ;
29
+ import org .springframework .graphql .data .method .annotation .Arguments ;
30
+ import org .springframework .graphql .data .method .annotation .QueryMapping ;
31
+ import org .springframework .stereotype .Controller ;
32
+
33
+ import static org .assertj .core .api .Assertions .assertThat ;
34
+
35
+ /**
36
+ * Unit tests for {@link ArgumentMethodArgumentResolver}.
37
+ * @author Rossen Stoyanchev
38
+ */
39
+ class ArgumentMapMethodArgumentResolverTests extends ArgumentResolverTestSupport {
40
+
41
+ private final HandlerMethodArgumentResolver resolver = new ArgumentMapMethodArgumentResolver ();
42
+
43
+
44
+ @ Test
45
+ void shouldSupportAnnotatedParameters () {
46
+ MethodParameter param = methodParam (BookController .class , "argumentMap" , Map .class );
47
+ assertThat (this .resolver .supportsParameter (param )).isTrue ();
48
+
49
+ param = methodParam (BookController .class , "argumentsMap" , Map .class );
50
+ assertThat (this .resolver .supportsParameter (param )).isTrue ();
51
+
52
+ param = methodParam (BookController .class , "argument" , Long .class );
53
+ assertThat (this .resolver .supportsParameter (param )).isFalse ();
54
+
55
+ param = methodParam (BookController .class , "namedArgumentMap" , Map .class );
56
+ assertThat (this .resolver .supportsParameter (param )).isFalse ();
57
+
58
+ param = methodParam (BookController .class , "notAnnotated" , String .class );
59
+ assertThat (this .resolver .supportsParameter (param )).isFalse ();
60
+ }
61
+
62
+ @ Test
63
+ void shouldResolveRawArgumentsMap () throws Exception {
64
+ Object result = this .resolver .resolveArgument (
65
+ methodParam (BookController .class , "argumentMap" , Map .class ),
66
+ environment ("{\" id\" : 42 }" ));
67
+
68
+ assertThat (result ).isNotNull ().isInstanceOf (Map .class ).isEqualTo (Collections .singletonMap ("id" , 42 ));
69
+ }
70
+
71
+
72
+ @ SuppressWarnings ({"ConstantConditions" , "unused" })
73
+ @ Controller
74
+ static class BookController {
75
+
76
+ @ QueryMapping
77
+ public Book argumentMap (@ Argument Map <?, ?> args ) {
78
+ return null ;
79
+ }
80
+
81
+ @ QueryMapping
82
+ public Book argumentsMap (@ Arguments Map <?, ?> args ) {
83
+ return null ;
84
+ }
85
+
86
+ @ QueryMapping
87
+ public Book argument (@ Argument Long id ) {
88
+ return null ;
89
+ }
90
+
91
+ @ QueryMapping
92
+ public Book namedArgumentMap (@ Argument (name = "book" ) Map <?, ?> book ) {
93
+ return null ;
94
+ }
95
+
96
+ public void notAnnotated (String param ) {
97
+ }
98
+
99
+ }
100
+
101
+ }
0 commit comments