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

Commit 1b93759

Browse files
fix(#487): additional Playground WebFlux tests
1 parent 957ddc0 commit 1b93759

13 files changed

+287
-56
lines changed

playground-spring-boot-autoconfigure/src/test/java/graphql/kickstart/playground/boot/PlaygroundCdnCustomVersionTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
@SpringBootTest(classes = PlaygroundTestConfig.class)
1212
@AutoConfigureMockMvc
1313
@TestPropertySource("classpath:application-playground-cdn-custom-version-test.properties")
14-
class PlaygroundCdnCustomVersionTest extends PlaygroundResourcesTestBase {
14+
public class PlaygroundCdnCustomVersionTest extends PlaygroundResourcesTestBase {
1515

16-
@Test
17-
void shouldLoadSpecifiedVersionFromCdn() throws Exception {
18-
String LOGO_CDN_PATH = "https://cdn.jsdelivr.net/npm/graphql-playground-react@1.7.10/build/logo.png";
19-
String FAVICON_CDN_PATH = "https://cdn.jsdelivr.net/npm/graphql-playground-react@1.7.10/build/favicon.png";
20-
String SCRIPT_CDN_PATH = "https://cdn.jsdelivr.net/npm/graphql-playground-react@1.7.10/build/static/js/middleware.js";
21-
String CSS_CDN_PATH = "https://cdn.jsdelivr.net/npm/graphql-playground-react@1.7.10/build/static/css/index.css";
22-
testPlaygroundResources(CSS_CDN_PATH, SCRIPT_CDN_PATH, FAVICON_CDN_PATH, LOGO_CDN_PATH);
23-
}
16+
@Test
17+
public void shouldLoadSpecifiedVersionFromCdn() throws Exception {
18+
testPlaygroundResources(
19+
PlaygroundTestHelper.CUSTOM_VERSION_CSS_CDN_PATH,
20+
PlaygroundTestHelper.CUSTOM_VERSION_SCRIPT_CDN_PATH,
21+
PlaygroundTestHelper.CUSTOM_VERSION_FAVICON_CDN_PATH,
22+
PlaygroundTestHelper.CUSTOM_VERSION_LOGO_CDN_PATH
23+
);
24+
}
2425
}

playground-spring-boot-autoconfigure/src/test/java/graphql/kickstart/playground/boot/PlaygroundCdnTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
@SpringBootTest(classes = PlaygroundTestConfig.class)
1212
@AutoConfigureMockMvc
1313
@TestPropertySource("classpath:application-playground-cdn-test.properties")
14-
class PlaygroundCdnTest extends PlaygroundResourcesTestBase {
14+
public class PlaygroundCdnTest extends PlaygroundResourcesTestBase {
1515

16-
@Test
17-
void shouldLoadLatestVersionFromCdn() throws Exception {
18-
String LOGO_CDN_PATH = "https://cdn.jsdelivr.net/npm/graphql-playground-react@latest/build/logo.png";
19-
String FAVICON_CDN_PATH = "https://cdn.jsdelivr.net/npm/graphql-playground-react@latest/build/favicon.png";
20-
String SCRIPT_CDN_PATH = "https://cdn.jsdelivr.net/npm/graphql-playground-react@latest/build/static/js/middleware.js";
21-
String CSS_CDN_PATH = "https://cdn.jsdelivr.net/npm/graphql-playground-react@latest/build/static/css/index.css";
22-
testPlaygroundResources(CSS_CDN_PATH, SCRIPT_CDN_PATH, FAVICON_CDN_PATH, LOGO_CDN_PATH);
23-
}
16+
@Test
17+
public void shouldLoadLatestVersionFromCdn() throws Exception {
18+
testPlaygroundResources(
19+
PlaygroundTestHelper.DEFAULT_CSS_CDN_PATH,
20+
PlaygroundTestHelper.DEFAULT_SCRIPT_CDN_PATH,
21+
PlaygroundTestHelper.DEFAULT_FAVICON_CDN_PATH,
22+
PlaygroundTestHelper.DEFAULT_LOGO_CDN_PATH
23+
);
24+
}
2425
}

playground-spring-boot-autoconfigure/src/test/java/graphql/kickstart/playground/boot/PlaygroundCustomMappingTest.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@
2121
@SpringBootTest(classes = PlaygroundTestConfig.class)
2222
@AutoConfigureMockMvc
2323
@TestPropertySource("classpath:application-playground-mapping-test.properties")
24-
class PlaygroundCustomMappingTest {
24+
public class PlaygroundCustomMappingTest {
2525

26-
private static final String CONFIGURED_MAPPING = "/test-mapping";
26+
@Autowired
27+
private MockMvc mockMvc;
2728

28-
@Autowired
29-
private MockMvc mockMvc;
30-
31-
@Test
32-
void shouldUseTheConfiguredRequestMapping() throws Exception {
33-
mockMvc.perform(get(CONFIGURED_MAPPING))
34-
.andExpect(status().isOk())
35-
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
36-
.andExpect(content().encoding(StandardCharsets.UTF_8.name()))
37-
.andExpect(content().string(not(isEmptyString())));
38-
}
29+
@Test
30+
public void shouldUseTheConfiguredRequestMapping() throws Exception {
31+
mockMvc.perform(get(PlaygroundTestHelper.CUSTOM_MAPPING))
32+
.andExpect(status().isOk())
33+
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
34+
.andExpect(content().encoding(StandardCharsets.UTF_8.name()))
35+
.andExpect(content().string(not(isEmptyString())));
36+
}
3937
}

playground-spring-boot-autoconfigure/src/test/java/graphql/kickstart/playground/boot/PlaygroundCustomStaticPathTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
@SpringBootTest(classes = PlaygroundTestConfig.class)
1212
@AutoConfigureMockMvc
1313
@TestPropertySource("classpath:application-playground-custom-static-path.properties")
14-
class PlaygroundCustomStaticPathTest extends PlaygroundResourcesTestBase {
14+
public class PlaygroundCustomStaticPathTest extends PlaygroundResourcesTestBase {
1515

16-
private static final String CUSTOM_CSS_URL = "/custom-static-path/static/css/index.css";
17-
private static final String CUSTOM_SCRIPT_URL = "/custom-static-path/static/js/middleware.js";
18-
private static final String CUSTOM_FAVICON_URL = "/custom-static-path/favicon.png";
19-
private static final String CUSTOM_LOGO_URL = "/custom-static-path/logo.png";
20-
21-
@Test
22-
void shouldLoadStaticResourcesFromCustomPath() throws Exception {
23-
testPlaygroundResources(CUSTOM_CSS_URL, CUSTOM_SCRIPT_URL, CUSTOM_FAVICON_URL, CUSTOM_LOGO_URL);
24-
}
16+
@Test
17+
public void shouldLoadStaticResourcesFromCustomPath() throws Exception {
18+
testPlaygroundResources(
19+
PlaygroundTestHelper.CUSTOM_LOCAL_CSS_URL,
20+
PlaygroundTestHelper.CUSTOM_LOCAL_SCRIPT_URL,
21+
PlaygroundTestHelper.CUSTOM_LOCAL_FAVICON_URL,
22+
PlaygroundTestHelper.CUSTOM_LOCAL_LOGO_URL
23+
);
24+
}
2525
}

playground-spring-boot-autoconfigure/src/test/java/graphql/kickstart/playground/boot/PlaygroundCustomTitleTest.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,19 @@
2020
@SpringBootTest(classes = PlaygroundTestConfig.class)
2121
@AutoConfigureMockMvc
2222
@TestPropertySource("classpath:application-playground-custom-title.properties")
23-
class PlaygroundCustomTitleTest {
23+
public class PlaygroundCustomTitleTest {
2424

25-
private static final String CUSTOM_TITLE = "My CustomTest Title";
25+
@Autowired
26+
private MockMvc mockMvc;
2627

27-
@Autowired
28-
private MockMvc mockMvc;
28+
@Test
29+
public void shouldUseTheCustomPageTitle() throws Exception {
30+
final MvcResult mvcResult = mockMvc.perform(get(PlaygroundTestHelper.DEFAULT_PLAYGROUND_ENDPOINT))
31+
.andExpect(status().isOk())
32+
.andExpect(model().attribute(PlaygroundTestHelper.PAGE_TITLE_FIELD_NAME, PlaygroundTestHelper.CUSTOM_TITLE))
33+
.andReturn();
2934

30-
@Test
31-
void shouldUseTheCustomPageTitle() throws Exception {
32-
final MvcResult mvcResult = mockMvc
33-
.perform(get(PlaygroundTestHelper.DEFAULT_PLAYGROUND_ENDPOINT))
34-
.andExpect(status().isOk())
35-
.andExpect(model().attribute(PlaygroundTestHelper.PAGE_TITLE_FIELD_NAME, CUSTOM_TITLE))
36-
.andReturn();
37-
38-
final Document document = Jsoup.parse(mvcResult.getResponse().getContentAsString());
39-
PlaygroundTestHelper.assertTitle(document, CUSTOM_TITLE);
40-
}
35+
final Document document = Jsoup.parse(mvcResult.getResponse().getContentAsString());
36+
PlaygroundTestHelper.assertTitle(document, PlaygroundTestHelper.CUSTOM_TITLE);
37+
}
4138
}

playground-spring-boot-autoconfigure/src/test/java/graphql/kickstart/playground/boot/PlaygroundTestHelper.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@
66
import static org.assertj.core.api.Assertions.assertThat;
77

88
public final class PlaygroundTestHelper {
9+
10+
public static final String CUSTOM_LOCAL_CSS_URL = "/custom-static-path/static/css/index.css";
11+
public static final String CUSTOM_LOCAL_SCRIPT_URL = "/custom-static-path/static/js/middleware.js";
12+
public static final String CUSTOM_LOCAL_FAVICON_URL = "/custom-static-path/favicon.png";
13+
public static final String CUSTOM_LOCAL_LOGO_URL = "/custom-static-path/logo.png";
14+
15+
public static final String DEFAULT_CSS_CDN_PATH
16+
= "https://cdn.jsdelivr.net/npm/graphql-playground-react@latest/build/static/css/index.css";
17+
public static final String DEFAULT_SCRIPT_CDN_PATH
18+
= "https://cdn.jsdelivr.net/npm/graphql-playground-react@latest/build/static/js/middleware.js";
19+
public static final String DEFAULT_FAVICON_CDN_PATH
20+
= "https://cdn.jsdelivr.net/npm/graphql-playground-react@latest/build/favicon.png";
21+
public static final String DEFAULT_LOGO_CDN_PATH
22+
= "https://cdn.jsdelivr.net/npm/graphql-playground-react@latest/build/logo.png";
23+
24+
public static final String CUSTOM_VERSION_CSS_CDN_PATH
25+
= "https://cdn.jsdelivr.net/npm/graphql-playground-react@1.7.10/build/static/css/index.css";
26+
public static final String CUSTOM_VERSION_SCRIPT_CDN_PATH
27+
= "https://cdn.jsdelivr.net/npm/graphql-playground-react@1.7.10/build/static/js/middleware.js";
28+
public static final String CUSTOM_VERSION_FAVICON_CDN_PATH
29+
= "https://cdn.jsdelivr.net/npm/graphql-playground-react@1.7.10/build/favicon.png";
30+
public static final String CUSTOM_VERSION_LOGO_CDN_PATH
31+
= "https://cdn.jsdelivr.net/npm/graphql-playground-react@1.7.10/build/logo.png";
32+
33+
public static final String CUSTOM_MAPPING = "/test-mapping";
34+
public static final String CUSTOM_TITLE = "My CustomTest Title";
935
public static final String DEFAULT_PLAYGROUND_ENDPOINT = "/playground";
1036
public static final String CSS_URL_FIELD_NAME = "cssUrl";
1137
public static final String SCRIPT_URL_FIELD_NAME = "scriptUrl";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package graphql.kickstart.playground.boot.webflux;
2+
3+
import graphql.kickstart.playground.boot.PlaygroundTestHelper;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.test.context.TestPropertySource;
8+
9+
@SpringBootTest(classes = PlaygroundWebFluxTestConfig.class)
10+
@AutoConfigureWebTestClient
11+
@TestPropertySource("classpath:application-playground-cdn-test.properties")
12+
public class PlaygroundWebFluxCdnTest extends PlaygroundWebFluxResourcesTestBase {
13+
14+
@Test
15+
public void shouldLoadLatestVersionFromCdn() {
16+
testPlaygroundResources(
17+
PlaygroundTestHelper.DEFAULT_CSS_CDN_PATH,
18+
PlaygroundTestHelper.DEFAULT_SCRIPT_CDN_PATH,
19+
PlaygroundTestHelper.DEFAULT_FAVICON_CDN_PATH,
20+
PlaygroundTestHelper.DEFAULT_LOGO_CDN_PATH
21+
);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package graphql.kickstart.playground.boot.webflux;
2+
3+
import graphql.kickstart.playground.boot.PlaygroundTestHelper;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.test.context.TestPropertySource;
8+
9+
@SpringBootTest(classes = PlaygroundWebFluxTestConfig.class)
10+
@AutoConfigureWebTestClient
11+
@TestPropertySource("classpath:application-playground-cdn-custom-version-test.properties")
12+
public class PlaygroundWebFluxCustomCdnVersionTest extends PlaygroundWebFluxResourcesTestBase {
13+
14+
@Test
15+
public void shouldLoadSpecifiedVersionFromCdn() {
16+
testPlaygroundResources(
17+
PlaygroundTestHelper.CUSTOM_VERSION_CSS_CDN_PATH,
18+
PlaygroundTestHelper.CUSTOM_VERSION_SCRIPT_CDN_PATH,
19+
PlaygroundTestHelper.CUSTOM_VERSION_FAVICON_CDN_PATH,
20+
PlaygroundTestHelper.CUSTOM_VERSION_LOGO_CDN_PATH
21+
);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package graphql.kickstart.playground.boot.webflux;
2+
3+
import graphql.kickstart.playground.boot.PlaygroundTestHelper;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
7+
import org.springframework.boot.test.context.SpringBootTest;
8+
import org.springframework.http.MediaType;
9+
import org.springframework.test.context.TestPropertySource;
10+
import org.springframework.test.web.reactive.server.WebTestClient;
11+
12+
@SpringBootTest(classes = PlaygroundWebFluxTestConfig.class)
13+
@AutoConfigureWebTestClient
14+
@TestPropertySource("classpath:application-playground-mapping-test.properties")
15+
public class PlaygroundWebFluxCustomMappingTest {
16+
17+
@Autowired
18+
private WebTestClient webTestClient;
19+
20+
@Test
21+
public void shouldUseTheConfiguredRequestMapping() {
22+
webTestClient.get().uri(PlaygroundTestHelper.CUSTOM_MAPPING)
23+
.exchange()
24+
.expectStatus().isOk()
25+
.expectHeader().contentTypeCompatibleWith(MediaType.TEXT_HTML);
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package graphql.kickstart.playground.boot.webflux;
2+
3+
import graphql.kickstart.playground.boot.PlaygroundTestHelper;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.test.context.TestPropertySource;
8+
9+
@SpringBootTest(classes = PlaygroundWebFluxTestConfig.class)
10+
@AutoConfigureWebTestClient
11+
@TestPropertySource("classpath:application-playground-custom-static-path.properties")
12+
public class PlaygroundWebFluxCustomStaticPathTest extends PlaygroundWebFluxResourcesTestBase {
13+
14+
@Test
15+
public void shouldLoadStaticResourcesFromCustomPath() {
16+
testPlaygroundResources(
17+
PlaygroundTestHelper.CUSTOM_LOCAL_CSS_URL,
18+
PlaygroundTestHelper.CUSTOM_LOCAL_SCRIPT_URL,
19+
PlaygroundTestHelper.CUSTOM_LOCAL_FAVICON_URL,
20+
PlaygroundTestHelper.CUSTOM_LOCAL_LOGO_URL
21+
);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package graphql.kickstart.playground.boot.webflux;
2+
3+
import graphql.kickstart.playground.boot.PlaygroundTestHelper;
4+
import org.jsoup.Jsoup;
5+
import org.jsoup.nodes.Document;
6+
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.test.context.TestPropertySource;
11+
import org.springframework.test.web.reactive.server.EntityExchangeResult;
12+
import org.springframework.test.web.reactive.server.WebTestClient;
13+
import org.springframework.test.web.servlet.MvcResult;
14+
15+
import java.nio.charset.StandardCharsets;
16+
17+
import static graphql.kickstart.playground.boot.PlaygroundTestHelper.CUSTOM_TITLE;
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
@SpringBootTest(classes = PlaygroundWebFluxTestConfig.class)
21+
@AutoConfigureWebTestClient
22+
@TestPropertySource("classpath:application-playground-custom-title.properties")
23+
public class PlaygroundWebFluxCustomTitleTest {
24+
25+
@Autowired
26+
private WebTestClient webTestClient;
27+
28+
@Test
29+
public void shouldUseTheCustomPageTitle() {
30+
// WHEN
31+
final byte[] actual = webTestClient.get().uri(PlaygroundTestHelper.DEFAULT_PLAYGROUND_ENDPOINT)
32+
.exchange()
33+
.expectStatus().isOk()
34+
.expectBody().returnResult().getResponseBody();
35+
// THEN
36+
assertThat(actual).isNotNull();
37+
final Document document = Jsoup.parse(new String(actual, StandardCharsets.UTF_8));
38+
PlaygroundTestHelper.assertTitle(document, CUSTOM_TITLE);
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package graphql.kickstart.playground.boot.webflux;
2+
3+
import graphql.kickstart.playground.boot.PlaygroundController;
4+
import graphql.kickstart.playground.boot.PlaygroundTestHelper;
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.context.ApplicationContext;
11+
import org.springframework.test.web.reactive.server.WebTestClient;
12+
13+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
14+
15+
@SpringBootTest(classes = PlaygroundWebFluxTestConfig.class, properties = "graphql.playground.enabled=false")
16+
@AutoConfigureWebTestClient
17+
public class PlaygroundWebFluxDisabledTest {
18+
19+
@Autowired
20+
private ApplicationContext applicationContext;
21+
22+
@Autowired
23+
private WebTestClient webTestClient;
24+
25+
@Test
26+
public void playgroundShouldNotLoadIfDisabled() {
27+
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
28+
.isThrownBy(() -> applicationContext.getBean(PlaygroundController.class));
29+
}
30+
31+
@Test
32+
public void playgroundEndpointShouldNotExist() {
33+
webTestClient.get().uri(PlaygroundTestHelper.DEFAULT_PLAYGROUND_ENDPOINT)
34+
.exchange()
35+
.expectStatus().isNotFound();
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package graphql.kickstart.playground.boot.webflux;
2+
3+
import graphql.kickstart.playground.boot.PlaygroundTestHelper;
4+
import org.jsoup.Jsoup;
5+
import org.jsoup.nodes.Document;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.test.web.reactive.server.WebTestClient;
8+
9+
import java.nio.charset.StandardCharsets;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
13+
public class PlaygroundWebFluxResourcesTestBase {
14+
15+
@Autowired
16+
private WebTestClient webTestClient;
17+
18+
void testPlaygroundResources(
19+
final String cssUrl,
20+
final String scriptUrl,
21+
final String faviconUrl,
22+
final String logoUrl
23+
) {
24+
// WHEN
25+
final byte[] actual = webTestClient.get().uri(PlaygroundTestHelper.DEFAULT_PLAYGROUND_ENDPOINT)
26+
.exchange()
27+
.expectStatus().isOk()
28+
.expectBody().returnResult().getResponseBody();
29+
30+
// THEN
31+
assertThat(actual).isNotNull();
32+
final Document document = Jsoup.parse(new String(actual, StandardCharsets.UTF_8));
33+
PlaygroundTestHelper.assertStaticResources(document, cssUrl, scriptUrl, faviconUrl, logoUrl);
34+
}
35+
}

0 commit comments

Comments
 (0)