5
5
import com .graphql .spring .boot .test .GraphQLResponse ;
6
6
import com .graphql .spring .boot .test .GraphQLTestTemplate ;
7
7
import io .micrometer .core .instrument .util .IOUtils ;
8
- import org .json .JSONException ;
9
- import org .skyscreamer .jsonassert .JSONAssert ;
10
- import org .springframework .beans .factory .annotation .Autowired ;
11
- import org .springframework .core .io .ClassPathResource ;
12
-
13
8
import java .io .IOException ;
14
9
import java .nio .charset .StandardCharsets ;
15
10
import java .util .Calendar ;
16
11
import java .util .Date ;
12
+ import org .json .JSONException ;
13
+ import org .skyscreamer .jsonassert .JSONAssert ;
14
+ import org .springframework .core .io .ClassPathResource ;
17
15
18
16
import static java .lang .String .format ;
19
17
import static org .assertj .core .api .Assertions .assertThat ;
20
18
19
+ /**
20
+ * Utility class that provides utility methods for the test classes.
21
+ *
22
+ * @author Lukas Zetto
23
+ * @version 1.0
24
+ */
21
25
public class UtilTests {
22
26
23
27
static final String GRAPHQL_QUERY_REQUEST_PATH = "graphql/resolver/query/request/%s.graphql" ;
@@ -32,11 +36,30 @@ private static String read(String location) throws IOException {
32
36
StandardCharsets .UTF_8 );
33
37
}
34
38
35
- public static void validate (GraphQLTestTemplate graphQLTestTemplate , String testname ) throws IOException , JSONException {
39
+ /**
40
+ * Validates a GraphQL query.
41
+ *
42
+ * @param graphQLTestTemplate The GraphQL test template.
43
+ * @param testname The name of the GraphQL query.
44
+ * @throws IOException When the validation of the GraphQL query fails.
45
+ * @throws JSONException When the validation of the GraphQL query fails.
46
+ */
47
+ public static void validate (GraphQLTestTemplate graphQLTestTemplate , String testname )
48
+ throws IOException , JSONException {
36
49
compare (graphQLTestTemplate , testname );
37
50
}
38
51
39
- public static void validate (GraphQLTestTemplate graphQLTestTemplate , String testname , String user ) throws IOException , JSONException {
52
+ /**
53
+ * Validates a GraphQL query.
54
+ *
55
+ * @param graphQLTestTemplate The GraphQL test template.
56
+ * @param testname The name of the GraphQL query.
57
+ * @param user The name of the user.
58
+ * @throws IOException When the validation of the GraphQL query fails.
59
+ * @throws JSONException When the validation of the GraphQL query fails.
60
+ */
61
+ public static void validate (GraphQLTestTemplate graphQLTestTemplate , String testname , String user )
62
+ throws IOException , JSONException {
40
63
String token = JWT
41
64
.create ()
42
65
.withIssuer ("my-graphql-api" )
@@ -48,10 +71,10 @@ public static void validate(GraphQLTestTemplate graphQLTestTemplate, String test
48
71
compare (graphQLTestTemplate , testname );
49
72
}
50
73
51
- private static void compare (GraphQLTestTemplate graphQLTestTemplate , String testname ) throws IOException , JSONException {
74
+ private static void compare (GraphQLTestTemplate graphQLTestTemplate , String testname )
75
+ throws IOException , JSONException {
52
76
String expectedResultBody = read (format (GRAPHQL_QUERY_RESPONSE_PATH , testname ));
53
77
GraphQLResponse response = graphQLTestTemplate .postForResource (format (GRAPHQL_QUERY_REQUEST_PATH , testname ));
54
- String test = response .getRawResponse ().getBody ();
55
78
assertThat (response .isOk ()).isTrue ();
56
79
JSONAssert .assertEquals (expectedResultBody , response .getRawResponse ().getBody (), true );
57
80
}
0 commit comments