32
32
import com .fasterxml .jackson .databind .JsonNode ;
33
33
import com .fasterxml .jackson .databind .ObjectMapper ;
34
34
import com .introproventures .graphql .jpa .query .converter .model .JsonEntity ;
35
+ import com .introproventures .graphql .jpa .query .converter .model .TaskVariableEntity ;
35
36
import com .introproventures .graphql .jpa .query .converter .model .VariableValue ;
36
37
import com .introproventures .graphql .jpa .query .schema .GraphQLExecutor ;
37
38
import com .introproventures .graphql .jpa .query .schema .GraphQLSchemaBuilder ;
38
- import com .introproventures .graphql .jpa .query .schema .JavaScalars ;
39
- import com .introproventures .graphql .jpa .query .schema .JavaScalars .GraphQLObjectCoercing ;
40
39
import com .introproventures .graphql .jpa .query .schema .impl .GraphQLJpaExecutor ;
41
40
import com .introproventures .graphql .jpa .query .schema .impl .GraphQLJpaSchemaBuilder ;
42
- import graphql .schema .GraphQLScalarType ;
43
41
import org .junit .Test ;
44
42
import org .junit .runner .RunWith ;
45
43
import org .springframework .beans .factory .annotation .Autowired ;
@@ -66,13 +64,9 @@ public GraphQLExecutor graphQLExecutor(final GraphQLSchemaBuilder graphQLSchemaB
66
64
67
65
@ Bean
68
66
public GraphQLSchemaBuilder graphQLSchemaBuilder (final EntityManager entityManager ) {
69
-
70
- JavaScalars .register (JsonNode .class , new GraphQLScalarType ("Json" , "Json type" , new GraphQLObjectCoercing ()));
71
- JavaScalars .register (VariableValue .class , new GraphQLScalarType ("VariableValue" , "VariableValue Type" , new GraphQLObjectCoercing ()));
72
-
73
67
return new GraphQLJpaSchemaBuilder (entityManager )
74
- .name ("HashMapSchema " )
75
- .description ("Json Entity test schema " );
68
+ .name ("CustomAttributeConverterSchema " )
69
+ .description ("Custom Attribute Converter Schema " );
76
70
}
77
71
78
72
}
@@ -121,6 +115,27 @@ public void criteriaTester() {
121
115
assertThat (result ).isNotEmpty ();
122
116
assertThat (result ).hasSize (1 );
123
117
}
118
+
119
+ @ Test
120
+ @ Transactional
121
+ public void criteriaTester2 () {
122
+ CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
123
+ CriteriaQuery <TaskVariableEntity > criteria = builder .createQuery (TaskVariableEntity .class );
124
+ Root <TaskVariableEntity > taskVariable = criteria .from (TaskVariableEntity .class );
125
+
126
+ Boolean object = new Boolean (true );
127
+
128
+ VariableValue <Boolean > variableValue = new VariableValue <>(object );
129
+ criteria .select (taskVariable )
130
+ .where (builder .equal (taskVariable .get ("value" ), variableValue ));
131
+
132
+ // when:
133
+ List <?> result = entityManager .createQuery (criteria ).getResultList ();
134
+
135
+ // then:
136
+ assertThat (result ).isNotEmpty ();
137
+ assertThat (result ).hasSize (1 );
138
+ }
124
139
125
140
@ Test // Problem with generating cast() in the where expression
126
141
@ Transactional
@@ -312,5 +327,126 @@ public void queryProcessVariablesWhereSearchCriteria() {
312
327
// then
313
328
assertThat (result .toString ()).isEqualTo (expected );
314
329
}
330
+
331
+ @ Test
332
+ public void queryProcessVariablesWhereWithEQStringSearchCriteria () {
333
+ //given
334
+ String query = "query {" +
335
+ " TaskVariables(where: {"
336
+ + "name: {EQ: \" variable1\" }"
337
+ + "value: {EQ: \" data\" }"
338
+ + "}) {" +
339
+ " select {" +
340
+ " name" +
341
+ " value" +
342
+ " }" +
343
+ " }" +
344
+ "}" ;
345
+
346
+ String expected = "{TaskVariables={select=[{name=variable1, value=data}]}}" ;
347
+
348
+ //when
349
+ Object result = executor .execute (query ).getData ();
350
+
351
+ // then
352
+ assertThat (result .toString ()).isEqualTo (expected );
353
+ }
354
+
355
+ @ Test
356
+ public void queryProcessVariablesWhereWithEQBooleanSearchCriteria () {
357
+ //given
358
+ String query = "query {" +
359
+ " TaskVariables(where: {"
360
+ + "name: {EQ: \" variable2\" }"
361
+ + "value: {EQ: true}"
362
+ + "}) {" +
363
+ " select {" +
364
+ " name" +
365
+ " value" +
366
+ " }" +
367
+ " }" +
368
+ "}" ;
369
+
370
+ String expected = "{TaskVariables={select=[{name=variable2, value=true}]}}" ;
371
+
372
+ //when
373
+ Object result = executor .execute (query ).getData ();
374
+
375
+ // then
376
+ assertThat (result .toString ()).isEqualTo (expected );
377
+ }
378
+
379
+ @ Test
380
+ public void queryProcessVariablesWhereWithEQNullSearchCriteria () {
381
+ //given
382
+ String query = "query {" +
383
+ " TaskVariables(where: {"
384
+ + "name: {EQ: \" variable3\" }"
385
+ + "value: {EQ: null}"
386
+ + "}) {" +
387
+ " select {" +
388
+ " name" +
389
+ " value" +
390
+ " }" +
391
+ " }" +
392
+ "}" ;
393
+
394
+ String expected = "{TaskVariables={select=[{name=variable3, value=null}]}}" ;
395
+
396
+ //when
397
+ Object result = executor .execute (query ).getData ();
398
+
399
+ // then
400
+ assertThat (result .toString ()).isEqualTo (expected );
401
+ }
402
+
403
+ @ Test
404
+ public void queryProcessVariablesWhereWithEQIntSearchCriteria () {
405
+ //given
406
+ String query = "query {" +
407
+ " TaskVariables(where: {"
408
+ + "name: {EQ: \" variable6\" }"
409
+ + "value: {EQ: 12345}"
410
+ + "}) {" +
411
+ " select {" +
412
+ " name" +
413
+ " value" +
414
+ " }" +
415
+ " }" +
416
+ "}" ;
417
+
418
+ String expected = "{TaskVariables={select=[{name=variable6, value=12345}]}}" ;
419
+
420
+ //when
421
+ Object result = executor .execute (query ).getData ();
422
+
423
+ // then
424
+ assertThat (result .toString ()).isEqualTo (expected );
425
+ }
426
+
427
+ @ Test
428
+ public void queryProcessVariablesWhereWithEQDoubleSearchCriteria () {
429
+ //given
430
+ String query = "query {" +
431
+ " TaskVariables(where: {"
432
+ + "name: {EQ: \" variable5\" }"
433
+ + "value: {EQ: 1.2345}"
434
+ + "}) {" +
435
+ " select {" +
436
+ " name" +
437
+ " value" +
438
+ " }" +
439
+ " }" +
440
+ "}" ;
441
+
442
+ String expected = "{TaskVariables={select=[{name=variable5, value=1.2345}]}}" ;
443
+
444
+ //when
445
+ Object result = executor .execute (query ).getData ();
446
+
447
+ // then
448
+ assertThat (result .toString ()).isEqualTo (expected );
449
+ }
450
+
315
451
316
452
}
0 commit comments