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

Commit 866da86

Browse files
committed
webflux testing
1 parent df3ba09 commit 866da86

File tree

9 files changed

+74
-55
lines changed

9 files changed

+74
-55
lines changed

graphql-java-spring-boot-starter-webflux/src/main/java/graphql/spring/web/reactive/GraphQLEndpointConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package graphql.spring.web.reactive;
22

3-
import graphql.spring.web.reactive.controller.GraphQLController;
3+
import graphql.spring.web.reactive.components.GraphQLController;
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
66
import org.springframework.context.ApplicationContext;

graphql-java-spring-webflux/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ dependencies {
1010

1111
testCompile group: 'junit', name: 'junit', version: '4.12'
1212
testCompile "org.springframework:spring-test:$springVersion"
13+
testCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
14+
testCompile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.4.0'
1315
testCompile "org.mockito:mockito-core:2.+"
1416
}

graphql-java-spring-webflux/src/main/java/graphql/spring/web/reactive/DefaultExecutionResultHandler.java renamed to graphql-java-spring-webflux/src/main/java/graphql/spring/web/reactive/components/DefaultExecutionResultHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package graphql.spring.web.reactive;
1+
package graphql.spring.web.reactive.components;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import graphql.ExecutionResult;
5+
import graphql.spring.web.reactive.ExecutionResultHandler;
56
import org.springframework.beans.factory.annotation.Autowired;
67
import org.springframework.http.server.reactive.ServerHttpResponse;
78
import org.springframework.stereotype.Component;

graphql-java-spring-webflux/src/main/java/graphql/spring/web/reactive/DefaultGraphQLInvocation.java renamed to graphql-java-spring-webflux/src/main/java/graphql/spring/web/reactive/components/DefaultGraphQLInvocation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
package graphql.spring.web.reactive;
1+
package graphql.spring.web.reactive.components;
22

33
import graphql.ExecutionInput;
44
import graphql.ExecutionResult;
55
import graphql.GraphQL;
66
import graphql.Internal;
7+
import graphql.spring.web.reactive.GraphQLInvocation;
8+
import graphql.spring.web.reactive.GraphQLInvocationData;
79
import org.springframework.beans.factory.annotation.Autowired;
810
import org.springframework.stereotype.Component;
911
import org.springframework.web.context.request.WebRequest;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package graphql.spring.web.reactive.controller;
1+
package graphql.spring.web.reactive.components;
22

33

44
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -39,13 +39,12 @@ public class GraphQLController {
3939
consumes = MediaType.APPLICATION_JSON_VALUE,
4040
produces = MediaType.APPLICATION_JSON_VALUE)
4141
public Object graphqlPOST(@RequestBody GraphQLRequestBody body,
42-
WebRequest webRequest,
4342
ServerHttpResponse serverHttpResponse) {
4443
String query = body.getQuery();
4544
if (query == null) {
4645
query = "";
4746
}
48-
Mono<ExecutionResult> executionResult = graphQLInvocation.invoke(new GraphQLInvocationData(query, body.getOperationName(), body.getVariables()), webRequest);
47+
Mono<ExecutionResult> executionResult = graphQLInvocation.invoke(new GraphQLInvocationData(query, body.getOperationName(), body.getVariables()), null);
4948
return executionResultHandler.handleExecutionResult(executionResult, serverHttpResponse);
5049
}
5150

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package graphql.spring.web.reactive.controller;
1+
package graphql.spring.web.reactive.components;
22

33
import graphql.Internal;
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package graphql.spring.web.reactive.components;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.context.ApplicationContext;
8+
import org.springframework.http.MediaType;
9+
import org.springframework.test.context.ContextConfiguration;
10+
import org.springframework.test.context.junit4.SpringRunner;
11+
import org.springframework.test.context.web.WebAppConfiguration;
12+
import org.springframework.test.web.reactive.server.WebTestClient;
13+
import reactor.core.publisher.Mono;
14+
15+
import java.util.LinkedHashMap;
16+
import java.util.Map;
17+
18+
import static org.hamcrest.CoreMatchers.is;
19+
20+
@RunWith(SpringRunner.class)
21+
@ContextConfiguration(classes = {TestAppConfig.class})
22+
@WebAppConfiguration
23+
public class GraphQLControllerTest {
24+
25+
@Autowired
26+
private ApplicationContext applicationContext;
27+
28+
private WebTestClient client;
29+
30+
@Before
31+
public void setup() {
32+
client = WebTestClient.bindToApplicationContext(applicationContext).build();
33+
}
34+
35+
36+
@Test
37+
public void testVariableJson() throws Exception {
38+
Map<String, Object> request = new LinkedHashMap<>();
39+
client.post().uri("/graphql")
40+
.body(Mono.just(request), Map.class)
41+
.accept(MediaType.APPLICATION_JSON_UTF8)
42+
.exchange()
43+
.expectStatus().isOk()
44+
.expectBody()
45+
.jsonPath("data", is("foo"));
46+
// String query = "{foo}";
47+
// String variablesJson = "{\"key\":\"value\"}";
48+
// MvcResult mvcResult = this.mockMvc.perform(get("/graphql")
49+
// .param("query", query)
50+
// .param("variables", variablesJson))
51+
// .andDo(print()).andExpect(status().isOk())
52+
// .andReturn();
53+
54+
}
55+
56+
}

graphql-java-spring-webflux/src/test/java/graphql/spring/web/reactive/controller/TestAppConfig.java renamed to graphql-java-spring-webflux/src/test/java/graphql/spring/web/reactive/components/TestAppConfig.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package graphql.spring.web.reactive.controller;
1+
package graphql.spring.web.reactive.components;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import graphql.ExecutionInput;
@@ -9,6 +9,7 @@
99
import org.springframework.context.annotation.Bean;
1010
import org.springframework.context.annotation.ComponentScan;
1111
import org.springframework.context.annotation.Configuration;
12+
import org.springframework.web.context.request.WebRequest;
1213
import org.springframework.web.reactive.config.EnableWebFlux;
1314

1415
import java.util.concurrent.CompletableFuture;
@@ -35,4 +36,9 @@ public ObjectMapper objectMapper() {
3536
return new ObjectMapper();
3637
}
3738

39+
@Bean
40+
public WebRequest webRequest() {
41+
return Mockito.mock(WebRequest.class);
42+
}
43+
3844
}

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

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)