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

Commit 25e9b42

Browse files
committed
chore(sonar): add graphiql tests
1 parent dabef1c commit 25e9b42

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package graphql.kickstart.autoconfigure.editor.graphiql;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.hamcrest.Matchers.emptyString;
5+
import static org.hamcrest.Matchers.is;
6+
import static org.hamcrest.Matchers.not;
7+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
8+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
9+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
10+
11+
import org.junit.jupiter.api.Test;
12+
import org.junit.jupiter.api.extension.ExtendWith;
13+
import org.springframework.beans.factory.annotation.Autowired;
14+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
15+
import org.springframework.boot.test.context.SpringBootTest;
16+
import org.springframework.context.ApplicationContext;
17+
import org.springframework.http.MediaType;
18+
import org.springframework.test.context.TestPropertySource;
19+
import org.springframework.test.context.junit.jupiter.SpringExtension;
20+
import org.springframework.test.web.servlet.MockMvc;
21+
22+
@ExtendWith(SpringExtension.class)
23+
@SpringBootTest(classes = {GraphiQLAutoConfiguration.class})
24+
@AutoConfigureMockMvc
25+
@TestPropertySource("classpath:enabled-config.properties")
26+
class GraphiQLEnabledTest {
27+
28+
@Autowired private ApplicationContext applicationContext;
29+
@Autowired private MockMvc mockMvc;
30+
31+
@Test
32+
void graphiqlLoads() {
33+
assertThat(applicationContext.getBean(GraphiQLController.class)).isNotNull();
34+
}
35+
36+
@Test
37+
void graphiqlShouldBeAvailableAtDefaultEndpoint() throws Exception {
38+
mockMvc
39+
.perform(get("/graphiql"))
40+
.andExpect(status().isOk())
41+
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
42+
.andExpect(content().string(not(is(emptyString()))))
43+
.andReturn();
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package graphql.kickstart.autoconfigure.editor.graphiql;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.jsoup.Jsoup;
7+
import org.jsoup.nodes.Document;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.extension.ExtendWith;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration;
12+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
13+
import org.springframework.boot.test.context.SpringBootTest;
14+
import org.springframework.context.ApplicationContext;
15+
import org.springframework.test.context.TestPropertySource;
16+
import org.springframework.test.context.junit.jupiter.SpringExtension;
17+
import org.springframework.test.web.reactive.server.WebTestClient;
18+
19+
@Slf4j
20+
@AutoConfigureWebTestClient
21+
@ExtendWith(SpringExtension.class)
22+
@SpringBootTest(
23+
classes = {GraphiQLAutoConfiguration.class, WebFluxAutoConfiguration.class},
24+
properties = {"spring.main.web-application-type=reactive"})
25+
@TestPropertySource("classpath:enabled-config.properties")
26+
class ReactiveGraphiQLEnabledTest {
27+
28+
@Autowired private ApplicationContext applicationContext;
29+
@Autowired private WebTestClient webTestClient;
30+
31+
@Test
32+
void graphiqlLoads() {
33+
assertThat(applicationContext.getBean(ReactiveGraphiQLController.class)).isNotNull();
34+
}
35+
36+
@Test
37+
void graphiqlShouldBeAvailableAtDefaultEndpoint() throws Exception {
38+
final String responseBody =
39+
webTestClient
40+
.get()
41+
.uri("/graphiql")
42+
.exchange()
43+
.expectStatus()
44+
.isOk()
45+
.expectBody(String.class)
46+
.returnResult()
47+
.getResponseBody();
48+
assertThat(responseBody).isNotNull();
49+
final Document document = Jsoup.parse(responseBody);
50+
log.info("{}", responseBody);
51+
assertThat(document.select("head title").text()).isEqualTo("GraphiQL");
52+
}
53+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
graphql.voyager.enabled=true
22
graphql.altair.enabled=true
3+
graphql.graphiql.enabled=true

0 commit comments

Comments
 (0)