18
18
class JakartaValidationDirectiveTest {
19
19
@ Test
20
20
void testJakartaSizeAnnotationAddedAsDirective () {
21
- GraphQL schema = GraphQL .newGraphQL (SchemaBuilder .build ("com.fleetpin .graphql.builder.type.directive" )).build ();
21
+ GraphQL schema = GraphQL .newGraphQL (SchemaBuilder .build ("com.phocassoftware .graphql.builder.type.directive" )).build ();
22
22
var name = schema .getGraphQLSchema ().getFieldDefinition (FieldCoordinates .coordinates (schema .getGraphQLSchema ().getMutationType (), "setName" ));
23
23
var directive = name .getArgument ("name" ).getAppliedDirective ("Size" );
24
24
var argument = directive .getArgument ("min" );
@@ -28,7 +28,7 @@ void testJakartaSizeAnnotationAddedAsDirective() {
28
28
29
29
@ Test
30
30
void testJakartaSizeDirectiveArgumentDefinition () {
31
- Map <String , Object > response = execute ("query IntrospectionQuery { __schema { directives { name locations args { name } } } }" ).getData ();
31
+ Map <String , Object > response = execute ("query IntrospectionQuery { __schema { directives { name locations args { name } } } }" , null ).getData ();
32
32
List <LinkedHashMap <String , Object >> dir = (List <LinkedHashMap <String , Object >>) ((Map <String , Object >) response .get ("__schema" )).get ("directives" );
33
33
LinkedHashMap <String , Object > constraint = dir .stream ().filter (map -> map .get ("name" ).equals ("Size" )).collect (Collectors .toList ()).get (0 );
34
34
@@ -43,12 +43,24 @@ void testJakartaSizeDirectiveArgumentDefinition() {
43
43
assertEquals ("{name=groups}" , ((List <Object >) constraint .get ("args" )).get (4 ).toString ());
44
44
}
45
45
46
- private ExecutionResult execute (String query ) {
47
- GraphQLSchema preSchema = SchemaBuilder .builder ().classpath ("com.fleetpin.graphql.builder.type.directive" ).build ().build ();
46
+ @ Test
47
+ void testJakartaValidationIsApplied () {
48
+ var name = "Roger" ;
49
+ Map <String , String > response = execute ("mutation setName($name: String!){setName(name: $name)} " , Map .of ("name" , name )).getData ();
50
+ var result = response .get ("setName" );
51
+
52
+ assertEquals (name , result );
53
+ }
54
+
55
+ private ExecutionResult execute (String query , Map <String , Object > variables ) {
56
+ GraphQLSchema preSchema = SchemaBuilder .builder ().classpath ("com.phocassoftware.graphql.builder.type.directive" ).build ().build ();
48
57
GraphQL schema = GraphQL .newGraphQL (new IntrospectionWithDirectivesSupport ().apply (preSchema )).build ();
49
58
50
59
var input = ExecutionInput .newExecutionInput ();
51
60
input .query (query );
61
+ if (variables != null ) {
62
+ input .variables (variables );
63
+ }
52
64
return schema .execute (input );
53
65
}
54
66
}
0 commit comments