15
15
*/
16
16
package com .introproventures .graphql .jpa .query .test .web ;
17
17
18
+ import static java .util .Collections .emptyMap ;
19
+ import static java .util .Collections .singletonMap ;
18
20
import static org .mockito .Mockito .never ;
19
21
import static org .mockito .Mockito .verify ;
20
22
import static org .mockito .Mockito .when ;
@@ -77,9 +79,11 @@ public void setUp() {
77
79
when (executor .execute (Mockito .anyString ()))
78
80
.thenReturn (new ExecutionResultImpl (new HashMap <>(), new ArrayList <>()));
79
81
80
- when (executor .execute (Mockito .anyString (),Mockito .any ( )))
82
+ when (executor .execute (Mockito .anyString (),Mockito .nullable ( Map . class )))
81
83
.thenReturn (new ExecutionResultImpl (new HashMap <>(), new ArrayList <>()));
82
84
85
+ when (executor .execute (Mockito .anyString (),Mockito .nullable (String .class ),Mockito .nullable (Map .class )))
86
+ .thenReturn (new ExecutionResultImpl (new HashMap <>(), new ArrayList <>()));
83
87
}
84
88
85
89
private void ok (final GraphQLQueryRequest query ) throws Exception , JsonProcessingException {
@@ -206,7 +210,7 @@ public void testGraphqlQuery() throws Exception {
206
210
ok (new GraphQLQueryRequest ("{Tasks(where: {name: {EQ: \" name\" }}){select{id}}}" ));
207
211
208
212
verify (executor )
209
- .execute ("{Tasks(where: {name: {EQ: \" name\" }}){select{id}}}" , null );
213
+ .execute ("{Tasks(where: {name: {EQ: \" name\" }}){select{id}}}" , null , null );
210
214
}
211
215
212
216
@ Test
@@ -215,7 +219,6 @@ public void testGraphqlQueryNull() throws Exception {
215
219
.andExpect (status ().isBadRequest ());
216
220
}
217
221
218
- @ SuppressWarnings ("serial" )
219
222
@ Test
220
223
public void testGraphqlArguments () throws Exception {
221
224
GraphQLQueryRequest query = new GraphQLQueryRequest ("query TasksQuery($title: String!){Tasks(where:{name: {EQ: $title}}){select{id name}}}" );
@@ -227,35 +230,50 @@ public void testGraphqlArguments() throws Exception {
227
230
ok (query );
228
231
229
232
verify (executor )
230
- .execute (query .getQuery (), variables );
233
+ .execute (query .getQuery (), null , variables );
231
234
}
232
235
236
+ @ Test
237
+ public void testGraphqlOperationName () throws Exception {
238
+ String operationName = "TasksQuery" ;
239
+ GraphQLQueryRequest query = new GraphQLQueryRequest ("query TasksQuery($title: String!){Tasks(where:{name: {EQ: $title}}){select{id name}}}" );
240
+
241
+ Map <String , Object > variables = new HashMap <>();
242
+ variables .put ("title" , "value" );
243
+ query .setVariables (variables );
244
+ query .setOperationName (operationName );
245
+
246
+ ok (query );
247
+
248
+ verify (executor )
249
+ .execute (query .getQuery (), operationName , variables );
250
+ }
233
251
// Json directly
234
252
@ Test
235
253
public void testGraphqlArgumentsJson () throws Exception {
236
- String json = "{\" query\" : \" {Tasks(where:{name:{EQ: \\ \" title\\ \" }}){select{ title genre }}\" , \" arguments \" : {\" title \" : \" title \" }}" ;
254
+ String json = "{\" query\" : \" {Tasks(where:{name:{EQ: \\ \" title\\ \" }}){select{ title genre }}\" , \" variables \" : {\" key \" : \" value \" }}" ;
237
255
238
256
ok (json );
239
257
240
- verify (executor ).execute ("{Tasks(where:{name:{EQ: \" title\" }}){select{ title genre }}" , null );
258
+ verify (executor ).execute ("{Tasks(where:{name:{EQ: \" title\" }}){select{ title genre }}" , null , singletonMap ( "key" , "value" ) );
241
259
}
242
260
243
261
@ Test
244
262
public void testGraphqlArgumentsEmptyString () throws Exception {
245
- String json = "{\" query\" : \" {Tasks(where:{name:{EQ: \\ \" title\\ \" }}){select{id name}}\" , \" arguments \" : \" \" }" ;
263
+ String json = "{\" query\" : \" {Tasks(where:{name:{EQ: \\ \" title\\ \" }}){select{id name}}\" , \" variables \" : {} }" ;
246
264
247
265
ok (json );
248
266
249
- verify (executor ).execute ("{Tasks(where:{name:{EQ: \" title\" }}){select{id name}}" , null );
267
+ verify (executor ).execute ("{Tasks(where:{name:{EQ: \" title\" }}){select{id name}}" , null , emptyMap () );
250
268
}
251
269
252
270
@ Test
253
271
public void testGraphqlArgumentsNull () throws Exception {
254
- String json = "{\" query\" : \" {Tasks(where:{name:{EQ: \\ \" title\\ \" }}){select{id name}}\" , \" arguments \" : null}" ;
272
+ String json = "{\" query\" : \" {Tasks(where:{name:{EQ: \\ \" title\\ \" }}){select{id name}}\" , \" variables \" : null}" ;
255
273
256
274
ok (json );
257
275
258
- verify (executor ).execute ("{Tasks(where:{name:{EQ: \" title\" }}){select{id name}}" , null );
276
+ verify (executor ).execute ("{Tasks(where:{name:{EQ: \" title\" }}){select{id name}}" , null , null );
259
277
}
260
278
261
279
@ Test
@@ -264,7 +282,7 @@ public void testGraphqlNoArguments() throws Exception {
264
282
265
283
ok (json );
266
284
267
- verify (executor ).execute ("{Tasks(where:{name:{EQ: \" title\" }}){select{id name}}" , null );
285
+ verify (executor ).execute ("{Tasks(where:{name:{EQ: \" title\" }}){select{id name}}" , null , null );
268
286
}
269
287
270
288
// Form submitted data
@@ -308,4 +326,5 @@ public void testGraphqlArgumentsParamsVariablesEmpty() throws Exception {
308
326
309
327
verify (executor ).execute (query , null );
310
328
}
329
+
311
330
}
0 commit comments