This repository was archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathIntegrationTestDifferentUrl.java
More file actions
47 lines (36 loc) · 1.6 KB
/
Copy pathIntegrationTestDifferentUrl.java
File metadata and controls
47 lines (36 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package graphql.spring.web.servlet;
import graphql.ExecutionInput;
import graphql.ExecutionResultImpl;
import graphql.GraphQL;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.concurrent.CompletableFuture;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "graphql.url=otherUrl")
@RunWith(SpringRunner.class)
public class IntegrationTestDifferentUrl {
@Autowired
private TestRestTemplate restTemplate;
@Autowired
GraphQL graphql;
@Test
public void endpointIsAvailableWithDifferentUrl() {
String query = "{foo}";
ExecutionResultImpl executionResult = ExecutionResultImpl.newExecutionResult()
.data("bar")
.build();
CompletableFuture cf = CompletableFuture.completedFuture(executionResult);
ArgumentCaptor<ExecutionInput> captor = ArgumentCaptor.forClass(ExecutionInput.class);
Mockito.when(graphql.executeAsync(captor.capture())).thenReturn(cf);
String body = this.restTemplate.getForObject("/otherUrl/?query={query}", String.class, query);
assertThat(body, is("{\"data\":\"bar\"}"));
assertThat(captor.getValue().getQuery(), is(query));
}
}