16
16
17
17
package org .springframework .graphql .data .query ;
18
18
19
+ import java .nio .charset .StandardCharsets ;
19
20
import java .util .List ;
20
21
import java .util .concurrent .atomic .AtomicReference ;
22
+ import java .util .stream .Stream ;
21
23
22
24
import graphql .schema .DataFetcher ;
23
25
import graphql .schema .DataFetchingFieldSelectionSet ;
24
- import org .junit .jupiter .api .Test ;
26
+ import org .junit .jupiter .params .ParameterizedTest ;
27
+ import org .junit .jupiter .params .provider .Arguments ;
28
+ import org .junit .jupiter .params .provider .MethodSource ;
25
29
30
+ import org .springframework .core .io .ByteArrayResource ;
31
+ import org .springframework .core .io .Resource ;
26
32
import org .springframework .data .util .TypeInformation ;
27
33
import org .springframework .graphql .BookSource ;
28
34
import org .springframework .graphql .GraphQlSetup ;
34
40
* Unit test for {@link PropertySelection}.
35
41
*
36
42
* @author Rossen Stoyanchev
43
+ * @author Brian Clozel
37
44
*/
38
45
class PropertySelectionTests {
39
46
40
- @ Test
41
- void propertySelectionWithConnection () {
47
+ @ ParameterizedTest
48
+ @ MethodSource ("schemaResource" )
49
+ void propertySelectionWithConnection (Resource schemaResource ) {
42
50
43
51
AtomicReference <DataFetchingFieldSelectionSet > ref = new AtomicReference <>();
44
52
DataFetcher <?> dataFetcher = environment -> {
45
53
ref .set (environment .getSelectionSet ());
46
54
return null ;
47
55
};
48
56
49
- GraphQlSetup .schemaResource (BookSource . paginationSchema )
57
+ GraphQlSetup .schemaResource (schemaResource )
50
58
.typeDefinitionConfigurer (new ConnectionTypeDefinitionConfigurer ())
51
59
.dataFetcher ("Query" , "books" , dataFetcher )
52
60
.toGraphQlService ()
@@ -59,4 +67,20 @@ void propertySelectionWithConnection() {
59
67
assertThat (list ).containsExactly ("id" , "name" );
60
68
}
61
69
70
+ static Stream <Arguments > schemaResource () {
71
+ return Stream .of (
72
+ Arguments .of (BookSource .paginationSchema ),
73
+ Arguments .of (new ByteArrayResource ("""
74
+ type Query {
75
+ books(first:Int, after:String): BookConnection!
76
+ }
77
+
78
+ type Book {
79
+ id: ID
80
+ name: String
81
+ }
82
+ """ .getBytes (StandardCharsets .UTF_8 )))
83
+ );
84
+ }
85
+
62
86
}
0 commit comments