Skip to content
This repository was archived by the owner on Oct 25, 2021. It is now read-only.

Commit ec56d6f

Browse files
committed
more tests
1 parent 10c44fe commit ec56d6f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

graphql-java-spring-webflux/src/test/java/graphql/spring/web/reactive/components/GraphQLControllerTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,33 @@ public void testPostRequest() throws Exception {
7777
assertThat(captor.getValue().getOperationName(), is(operationName));
7878
}
7979

80+
@Test
81+
public void testSimplePostRequest() throws Exception {
82+
Map<String, Object> request = new LinkedHashMap<>();
83+
String query = "{foo}";
84+
request.put("query", query);
85+
86+
ExecutionResultImpl executionResult = ExecutionResultImpl.newExecutionResult()
87+
.data("bar")
88+
.build();
89+
CompletableFuture cf = CompletableFuture.completedFuture(executionResult);
90+
ArgumentCaptor<ExecutionInput> captor = ArgumentCaptor.forClass(ExecutionInput.class);
91+
Mockito.when(graphql.executeAsync(captor.capture())).thenReturn(cf);
92+
93+
client.post().uri("/graphql")
94+
.body(Mono.just(request), Map.class)
95+
.accept(MediaType.APPLICATION_JSON_UTF8)
96+
.exchange()
97+
.expectStatus().isOk()
98+
.expectBody()
99+
.jsonPath("data").isEqualTo("bar");
100+
101+
assertThat(captor.getAllValues().size(), is(1));
102+
103+
assertThat(captor.getValue().getQuery(), is(query));
104+
}
105+
106+
80107
@Test
81108
public void testGetRequest() throws Exception {
82109
String variablesJson = "{\"variable\":\"variableValue\"}";

graphql-java-spring-webmvc/src/test/java/graphql/spring/web/servlet/components/GraphQLControllerTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,39 @@ public void testPostRequest() throws Exception {
104104

105105
}
106106

107+
@Test
108+
public void testSimplePostRequest() throws Exception {
109+
Map<String, Object> request = new LinkedHashMap<>();
110+
String query = "{foo}";
111+
request.put("query", query);
112+
113+
ExecutionResultImpl executionResult = ExecutionResultImpl.newExecutionResult()
114+
.data("bar")
115+
.build();
116+
CompletableFuture cf = CompletableFuture.completedFuture(executionResult);
117+
ArgumentCaptor<ExecutionInput> captor = ArgumentCaptor.forClass(ExecutionInput.class);
118+
Mockito.when(graphql.executeAsync(captor.capture())).thenReturn(cf);
119+
120+
121+
MvcResult mvcResult = this.mockMvc.perform(post("/graphql")
122+
.content(toJson(request))
123+
.contentType(MediaType.APPLICATION_JSON_UTF8))
124+
.andExpect(status().isOk())
125+
.andExpect(request().asyncStarted())
126+
.andReturn();
127+
128+
this.mockMvc.perform(asyncDispatch(mvcResult))
129+
.andDo(print()).andExpect(status().isOk())
130+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
131+
.andExpect(jsonPath("data", is("bar")))
132+
.andReturn();
133+
134+
assertThat(captor.getAllValues().size(), is(1));
135+
136+
assertThat(captor.getValue().getQuery(), is(query));
137+
138+
}
139+
107140
@Test
108141
public void testGetRequest() throws Exception {
109142
String variablesJson = "{\"variable\":\"variableValue\"}";

0 commit comments

Comments
 (0)