19
19
import java .util .Optional ;
20
20
21
21
import org .junit .jupiter .api .BeforeEach ;
22
- import org .junit .jupiter .api .Disabled ;
23
22
import org .junit .jupiter .api .Test ;
24
23
25
24
import org .springframework .context .support .StaticApplicationContext ;
26
25
import org .springframework .core .MethodParameter ;
27
26
import org .springframework .data .web .ProjectedPayload ;
28
27
import org .springframework .graphql .Book ;
28
+ import org .springframework .graphql .data .ArgumentValue ;
29
29
import org .springframework .graphql .data .method .annotation .Argument ;
30
30
import org .springframework .graphql .data .method .annotation .QueryMapping ;
31
31
import org .springframework .stereotype .Controller ;
@@ -50,11 +50,15 @@ void setUp() {
50
50
51
51
@ Test
52
52
void supports () {
53
- MethodParameter param = methodParam (BookController .class , "optionalProjection" , Optional .class );
54
- assertThat (this .resolver .supportsParameter (param )).isTrue ();
53
+ testSupports ("projection" , BookProjection .class , true );
54
+ testSupports ("optionalProjection" , Optional .class , true );
55
+ testSupports ("optionalString" , Optional .class , false );
56
+ testSupports ("argumentValueProjection" , ArgumentValue .class , true );
57
+ }
55
58
56
- param = methodParam (BookController .class , "optionalString" , Optional .class );
57
- assertThat (this .resolver .supportsParameter (param )).isFalse ();
59
+ void testSupports (String methodName , Class <?> methodParamType , boolean supported ) {
60
+ MethodParameter param = methodParam (BookController .class , methodName , methodParamType );
61
+ assertThat (this .resolver .supportsParameter (param )).isEqualTo (supported );
58
62
}
59
63
60
64
@ Test
@@ -81,7 +85,44 @@ void optionalNotPresent() throws Exception {
81
85
}
82
86
83
87
@ Test
84
- @ Disabled // pending decision under gh-550
88
+ void argumentValuePresent () throws Exception {
89
+
90
+ Object result = this .resolver .resolveArgument (
91
+ methodParam (BookController .class , "argumentValueProjection" , ArgumentValue .class ),
92
+ environment ("{ \" where\" : { \" author\" : \" Orwell\" }}" ));
93
+
94
+ assertThat (result ).isNotNull ().isInstanceOf (ArgumentValue .class );
95
+ BookProjection book = ((ArgumentValue <BookProjection >) result ).value ();
96
+ assertThat (book .getAuthor ()).isEqualTo ("Orwell" );
97
+ }
98
+
99
+ @ Test
100
+ void argumentValueSetToNull () throws Exception {
101
+
102
+ Object result = this .resolver .resolveArgument (
103
+ methodParam (BookController .class , "argumentValueProjection" , ArgumentValue .class ),
104
+ environment ("{ \" where\" : null}" ));
105
+
106
+ assertThat (result ).isNotNull ().isInstanceOf (ArgumentValue .class );
107
+ ArgumentValue <BookProjection > value = ((ArgumentValue <BookProjection >) result );
108
+ assertThat (value .isPresent ()).isFalse ();
109
+ assertThat (value .isOmitted ()).isFalse ();
110
+ }
111
+
112
+ @ Test
113
+ void argumentValueIsOmitted () throws Exception {
114
+
115
+ Object result = this .resolver .resolveArgument (
116
+ methodParam (BookController .class , "argumentValueProjection" , ArgumentValue .class ),
117
+ environment ("{}" ));
118
+
119
+ assertThat (result ).isNotNull ().isInstanceOf (ArgumentValue .class );
120
+ ArgumentValue <BookProjection > value = ((ArgumentValue <BookProjection >) result );
121
+ assertThat (value .isPresent ()).isFalse ();
122
+ assertThat (value .isOmitted ()).isTrue ();
123
+ }
124
+
125
+ @ Test // gh-550
85
126
void nullValue () throws Exception {
86
127
87
128
Object result = this .resolver .resolveArgument (
@@ -110,6 +151,11 @@ public List<Book> optionalProjection(@Argument(name = "where") Optional<BookProj
110
151
public void optionalString (@ Argument Optional <String > projection ) {
111
152
}
112
153
154
+ @ QueryMapping
155
+ public List <Book > argumentValueProjection (@ Argument (name = "where" ) ArgumentValue <BookProjection > projection ) {
156
+ return null ;
157
+ }
158
+
113
159
}
114
160
115
161
0 commit comments