Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit cdb27fa

Browse files
author
Ronny Bräunlich
committed
Fix default path in ReactiveGraphiQLController. Add tests for accessing /graphiql based on the servlet and based on the reactive stack. Fix imports.
1 parent d157349 commit cdb27fa

File tree

5 files changed

+74
-16
lines changed

5 files changed

+74
-16
lines changed

graphiql-spring-boot-autoconfigure/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ dependencies{
2727

2828
testCompile "org.springframework.boot:spring-boot-starter-web:$LIB_SPRING_BOOT_VER"
2929
testCompile "org.springframework.boot:spring-boot-starter-test:$LIB_SPRING_BOOT_VER"
30+
31+
testRuntime "org.springframework.boot:spring-boot-starter-webflux:$LIB_SPRING_BOOT_VER"
3032
}
3133

3234
compileJava.dependsOn(processResources)

graphiql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphiql/boot/ReactiveGraphiQLController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void onceConstructed() throws IOException {
3535
super.onceConstructed();
3636
}
3737

38-
@RequestMapping(value = "${graphiql.mapping:/api}")
38+
@RequestMapping(value = "${graphiql.mapping:/graphiql}")
3939
public Mono<Void> graphiql(ServerHttpRequest request, ServerHttpResponse response,
4040
@PathVariable Map<String, String> params) {
4141
response.getHeaders().setContentType(MediaType.TEXT_HTML);

graphiql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphiql/boot/ServletGraphiQLController.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
package com.oembedler.moon.graphiql.boot;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
4-
import com.fasterxml.jackson.databind.ObjectMapper;
53
import lombok.extern.slf4j.Slf4j;
6-
import org.apache.commons.lang3.StringUtils;
7-
import org.apache.commons.lang3.text.StrSubstitutor;
8-
import org.springframework.beans.factory.annotation.Autowired;
9-
import org.springframework.core.env.Environment;
10-
import org.springframework.core.io.ClassPathResource;
11-
import org.springframework.http.MediaType;
12-
import org.springframework.security.web.csrf.CsrfToken;
134
import org.springframework.stereotype.Controller;
14-
import org.springframework.util.StreamUtils;
155
import org.springframework.web.bind.annotation.GetMapping;
166
import org.springframework.web.bind.annotation.PathVariable;
17-
import org.springframework.web.bind.annotation.RequestParam;
187

198
import javax.annotation.PostConstruct;
209
import javax.servlet.http.HttpServletRequest;
2110
import javax.servlet.http.HttpServletResponse;
2211
import java.io.IOException;
23-
import java.io.InputStream;
24-
import java.nio.charset.Charset;
25-
import java.util.HashMap;
2612
import java.util.Map;
27-
import java.util.Properties;
2813

2914
/**
3015
* @author Andrew Potter
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.oembedler.moon.graphiql.boot;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.SpringBootConfiguration;
7+
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
8+
import org.springframework.context.annotation.Import;
9+
import org.springframework.http.MediaType;
10+
import org.springframework.test.context.TestPropertySource;
11+
import org.springframework.test.context.junit4.SpringRunner;
12+
import org.springframework.test.web.reactive.server.WebTestClient;
13+
14+
@RunWith(SpringRunner.class)
15+
@WebFluxTest
16+
public class ReactiveGraphiQLControllerTest {
17+
18+
@Autowired
19+
private WebTestClient webTestClient;
20+
21+
@Test
22+
public void shouldBeAbleToAccessGraphiQL() {
23+
webTestClient.get()
24+
.uri("/graphiql")
25+
.exchange()
26+
.expectStatus().is2xxSuccessful()
27+
.expectHeader().contentType(MediaType.TEXT_HTML);
28+
}
29+
30+
@SpringBootConfiguration
31+
@TestPropertySource(properties = "graphiql.enabled=true")
32+
@Import(GraphiQLAutoConfiguration.class)
33+
public static class ReactiveTestApplication {
34+
}
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.oembedler.moon.graphiql.boot;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.SpringBootConfiguration;
7+
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
8+
import org.springframework.context.annotation.Import;
9+
import org.springframework.test.context.TestPropertySource;
10+
import org.springframework.test.context.junit4.SpringRunner;
11+
import org.springframework.test.web.servlet.MockMvc;
12+
13+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
14+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
15+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
16+
17+
@RunWith(SpringRunner.class)
18+
@WebMvcTest
19+
public class ServletGraphiQLControllerTest {
20+
21+
@Autowired
22+
private MockMvc mockMvc;
23+
24+
@Test
25+
public void shouldBeAbleToAccessGraphiQL() throws Exception {
26+
mockMvc.perform(get("/graphiql"))
27+
.andExpect(status().is2xxSuccessful())
28+
.andExpect(content().contentType("text/html; charset=UTF-8"));
29+
}
30+
31+
@SpringBootConfiguration
32+
@TestPropertySource(properties = "graphiql.enabled=true")
33+
@Import(GraphiQLAutoConfiguration.class)
34+
public static class ServletTestApplication {
35+
}
36+
}

0 commit comments

Comments
 (0)