1+ package graphql .spring .web .servlet ;
2+
3+ import graphql .ExecutionInput ;
4+ import graphql .ExecutionResultImpl ;
5+ import graphql .GraphQL ;
6+ import org .junit .Test ;
7+ import org .junit .runner .RunWith ;
8+ import org .mockito .ArgumentCaptor ;
9+ import org .mockito .Mockito ;
10+ import org .springframework .beans .factory .annotation .Autowired ;
11+ import org .springframework .boot .test .context .SpringBootTest ;
12+ import org .springframework .boot .test .web .client .TestRestTemplate ;
13+ import org .springframework .test .context .junit4 .SpringRunner ;
14+
15+ import java .io .UnsupportedEncodingException ;
16+ import java .util .concurrent .CompletableFuture ;
17+
18+ import static org .hamcrest .CoreMatchers .is ;
19+ import static org .junit .Assert .assertThat ;
20+
21+ @ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT , classes = IntegrationTestConfig .class )
22+ @ RunWith (SpringRunner .class )
23+ public class IntegrationTest {
24+
25+ @ Autowired
26+ private TestRestTemplate restTemplate ;
27+
28+ @ Autowired
29+ GraphQL graphql ;
30+
31+ @ Test
32+ public void endpointIsAvailable () throws UnsupportedEncodingException {
33+ String query = "{foo}" ;
34+
35+ ExecutionResultImpl executionResult = ExecutionResultImpl .newExecutionResult ()
36+ .data ("bar" )
37+ .build ();
38+ CompletableFuture cf = CompletableFuture .completedFuture (executionResult );
39+ ArgumentCaptor <ExecutionInput > captor = ArgumentCaptor .forClass (ExecutionInput .class );
40+ Mockito .when (graphql .executeAsync (captor .capture ())).thenReturn (cf );
41+
42+ String body = this .restTemplate .getForObject ("/graphql?query={query}" , String .class , query );
43+
44+ assertThat (body , is ("{\" data\" :\" bar\" }" ));
45+ assertThat (captor .getValue ().getQuery (), is (query ));
46+ }
47+
48+ }
0 commit comments