33import static org .junit .Assert .assertEquals ;
44import static org .junit .Assert .assertNotNull ;
55
6+ import com .fasterxml .jackson .databind .ObjectMapper ;
7+ import graphql .kickstart .spring .webclient .testapp .Simple ;
8+ import java .util .HashMap ;
9+ import java .util .Map ;
610import org .junit .jupiter .api .BeforeEach ;
11+ import org .junit .jupiter .api .DisplayName ;
712import org .junit .jupiter .api .Test ;
813import org .springframework .boot .test .context .SpringBootTest ;
914import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
@@ -24,14 +29,37 @@ void beforeEach() {
2429 WebClient webClient = WebClient .builder ()
2530 .baseUrl ("http://localhost:" + randomServerPort )
2631 .build ();
27- graphqlClient = new GraphQLWebClientImpl (webClient );
32+ graphqlClient = new GraphQLWebClientImpl (webClient , new ObjectMapper () );
2833 }
2934
3035 @ Test
36+ @ DisplayName ("Query test without variables and returning String" )
3137 void queryWithoutVariablesSucceeds () {
3238 Mono <String > response = graphqlClient .query ("query-test.graphql" , null , String .class );
3339 assertNotNull ("response should not be null" , response );
3440 assertEquals ("response should equal 'test'" , "test" , response .block ());
3541 }
3642
43+ @ Test
44+ @ DisplayName ("Query echo with String variable and returning String" )
45+ void echoStringSucceeds () {
46+ Map <String , Object > variables = new HashMap <>();
47+ variables .put ("value" , "echo echo echo" );
48+ Mono <String > response = graphqlClient .query ("query-echo.graphql" , variables , String .class );
49+ assertNotNull ("response should not be null" , response );
50+ assertEquals ("response should equal 'echo echo echo'" , "echo echo echo" , response .block ());
51+ }
52+
53+ @ Test
54+ @ DisplayName ("Query simple return type" )
55+ void simpleTypeSucceeds () {
56+ Map <String , Object > variables = new HashMap <>();
57+ variables .put ("id" , "my-id" );
58+ Mono <Simple > response = graphqlClient .query ("query-simple.graphql" , variables , Simple .class );
59+ assertNotNull ("response should not be null" , response );
60+ Simple object = response .block ();
61+ assertNotNull (object );
62+ assertEquals ("response id should equal 'my-id'" , "my-id" , object .getId ());
63+ }
64+
3765}
0 commit comments