19
19
import graphql .annotations .annotationTypes .GraphQLName ;
20
20
import graphql .annotations .directives .AnnotationsDirectiveWiring ;
21
21
import graphql .annotations .annotationTypes .directives .definition .DirectiveLocations ;
22
- import graphql .annotations .annotationTypes .directives .definition .DirectiveWiring ;
23
22
import graphql .annotations .processor .GraphQLAnnotations ;
23
+ import graphql .annotations .processor .exceptions .GraphQLAnnotationsException ;
24
24
import graphql .introspection .Introspection ;
25
25
import graphql .schema .GraphQLArgument ;
26
26
import graphql .schema .GraphQLDirective ;
27
27
import org .testng .annotations .BeforeMethod ;
28
28
import org .testng .annotations .Test ;
29
29
30
+ import java .lang .annotation .Retention ;
31
+ import java .lang .annotation .RetentionPolicy ;
30
32
import java .util .Set ;
31
33
32
34
import static graphql .Scalars .GraphQLBoolean ;
@@ -54,7 +56,7 @@ public static class GeneralWiring implements AnnotationsDirectiveWiring {
54
56
@ GraphQLName ("upper" )
55
57
@ GraphQLDescription ("makes string upper case" )
56
58
@ DirectiveLocations ({Introspection .DirectiveLocation .FIELD_DEFINITION , Introspection .DirectiveLocation .INTERFACE })
57
- @ DirectiveWiring ( GeneralWiring .class )
59
+ @ GraphQLDirectiveDefinition ( wiring = GeneralWiring .class )
58
60
public static class UpperDirective {
59
61
private boolean isActive = true ;
60
62
@ GraphQLName ("suffixToAdd" )
@@ -121,8 +123,8 @@ public void directive_suppliedDirectiveMethodContainer_returnCorrectDirective()
121
123
// Act
122
124
Set <GraphQLDirective > directive = this .graphQLAnnotations .directives (DirectivesMethodsContainer .class );
123
125
124
- GraphQLDirective upper = (GraphQLDirective ) directive .toArray ()[1 ];
125
- GraphQLDirective suffix = (GraphQLDirective ) directive .toArray ()[0 ];
126
+ GraphQLDirective upper = (GraphQLDirective ) directive .toArray ()[0 ];
127
+ GraphQLDirective suffix = (GraphQLDirective ) directive .toArray ()[1 ];
126
128
127
129
// Assert
128
130
assertEquals (upper .getName (), "upper" );
@@ -151,13 +153,15 @@ public void directive_suppliedDirectiveMethodContainer_returnCorrectDirective()
151
153
@ GraphQLDescription ("the upper" )
152
154
@ GraphQLDirectiveDefinition (wiring = Wiring .class )
153
155
@ DirectiveLocations ({Introspection .DirectiveLocation .FIELD_DEFINITION , Introspection .DirectiveLocation .INTERFACE })
156
+ @ Retention (RetentionPolicy .RUNTIME )
154
157
@interface UpperAnnotation {
155
158
@ GraphQLName ("isActive" )
156
159
@ GraphQLDescription ("is active" )
157
160
boolean isActive () default true ;
158
161
}
159
162
160
163
@ GraphQLName ("bla" )
164
+ @ Retention (RetentionPolicy .RUNTIME )
161
165
@interface NoDirectiveAnnotation {
162
166
boolean isActive () default true ;
163
167
}
@@ -179,21 +183,10 @@ public void directive_suppliedDirectiveAnnotation_returnCorrectDirective() {
179
183
assertEquals (true ,isActive .getDefaultValue ());
180
184
}
181
185
182
- @ Test
183
- public void directive_suppliedNoDirectiveAnnotation_returnNull () {
186
+ @ Test ( expectedExceptions = GraphQLAnnotationsException . class )
187
+ public void directive_suppliedNoDirectiveAnnotation_throwException () {
184
188
// Act
185
189
GraphQLDirective upper = this .graphQLAnnotations .directiveViaAnnotation (NoDirectiveAnnotation .class );
186
-
187
- // Assert
188
- assertEquals (upper .getName (), "upper" );
189
- assertEquals (upper .getDescription (), "the upper" );
190
- assertArrayEquals (upper .validLocations ().toArray (), new Introspection .DirectiveLocation []{Introspection .DirectiveLocation .FIELD_DEFINITION ,
191
- Introspection .DirectiveLocation .INTERFACE });
192
- GraphQLArgument isActive = upper .getArgument ("isActive" );
193
- assertNotNull (isActive );
194
- assertEquals (isActive .getName (), "isActive" );
195
- assertEquals (isActive .getType (), GraphQLBoolean );
196
- assertEquals (true ,isActive .getDefaultValue ());
197
190
}
198
191
199
192
0 commit comments