|
1 | 1 | package com._4point.aem.fluentforms.sampleapp.resources; |
2 | 2 |
|
3 | | -import static com._4point.aem.fluentforms.sampleapp.resources.ResponseEntityMatchers.hasStringEntityMatching; |
4 | | -import static com._4point.aem.fluentforms.sampleapp.resources.ResponseEntityMatchers.isMediaType; |
5 | | -import static com._4point.aem.fluentforms.sampleapp.resources.ResponseEntityMatchers.isStatus; |
6 | | -import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; |
7 | | -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; |
8 | | -import static com.github.tomakehurst.wiremock.client.WireMock.verify; |
| 3 | +import static com._4point.aem.fluentforms.sampleapp.resources.ResponseEntityMatchers.*; |
9 | 4 | import static org.hamcrest.MatcherAssert.assertThat; |
10 | | -import static org.hamcrest.Matchers.allOf; |
11 | | -import static org.hamcrest.Matchers.anyOf; |
12 | | -import static org.hamcrest.Matchers.matchesRegex; |
| 5 | +import static org.hamcrest.Matchers.*; |
13 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; |
14 | 7 |
|
15 | 8 | import java.net.URI; |
16 | 9 | import java.nio.file.Path; |
17 | | -import java.util.List; |
18 | 10 | import java.util.concurrent.TimeUnit; |
19 | 11 |
|
20 | 12 | import org.htmlunit.WebClient; |
|
28 | 20 | import org.springframework.web.client.RestClient; |
29 | 21 |
|
30 | 22 | abstract class AbstractAemProxyEndpointTest { |
31 | | - private static final Path RESOURCES_DIR = Path.of("src", "test", "resources"); |
32 | | - private static final Path SAMPLE_FILES_DIR = RESOURCES_DIR.resolve("SampleFiles"); |
| 23 | + protected static final Path SAMPLE_XDP_FILENAME_PATH = Path.of("SampleForm.xdp"); |
33 | 24 |
|
34 | 25 | @LocalServerPort |
35 | 26 | private int port; |
| 27 | + private final String sampleFileLocation; |
| 28 | + |
| 29 | + protected AbstractAemProxyEndpointTest(String sampleFileLocation) { |
| 30 | + this.sampleFileLocation = sampleFileLocation; |
| 31 | + } |
36 | 32 |
|
37 | 33 | @Timeout(value = 30, unit = TimeUnit.SECONDS) |
38 | 34 | @Test |
@@ -66,27 +62,21 @@ void testProxyCsrfToken() throws Exception { |
66 | 62 | @Test |
67 | 63 | void proxyTest() throws Exception { |
68 | 64 | try (final WebClient webClient = new WebClient()) { |
69 | | - String baseUri = getBaseUriString(port) + "/FluentForms/Html5FormsServiceRenderHtml5Form" + "?form=" + SAMPLE_FILES_DIR.resolve("SampleForm.xdp").toAbsolutePath(); |
| 65 | + String baseUri = getBaseUriString(port) + "/FluentForms/Html5FormsServiceRenderHtml5Form" + "?form=" + sampleFileLocation; |
70 | 66 | final HtmlPage page = webClient.getPage(baseUri); |
71 | 67 | assertEquals("LC Forms", page.getTitleText()); |
72 | 68 | } |
73 | | - List.of( |
74 | | - /* "/content/xfaforms/profiles/default.html", */ // This fails for some reason however it's not essential to the test because if this were truly not working, none of the other calls would be made. |
75 | | - /* "/libs/granite/csrf/token.json", */ // This is not tested because it doesn't always happen (depending on the timings). |
76 | | - "/etc.clientlibs/fd/xfaforms/clientlibs/I18N/en.js", |
77 | | - "/etc.clientlibs/fd/xfaforms/clientlibs/profile.css", |
78 | | - "/etc.clientlibs/fd/xfaforms/clientlibs/profile.js", |
79 | | - "/etc.clientlibs/clientlibs/granite/jquery/granite/csrf.js", |
80 | | - "/etc.clientlibs/toggles.json" |
81 | | - ) |
82 | | - .forEach(url->verify(getRequestedFor(urlPathEqualTo(url)))); |
| 69 | + verifyProxyTest(); |
83 | 70 | } |
84 | 71 |
|
| 72 | + protected abstract void verifyProxyTest(); |
| 73 | + |
85 | 74 | protected static String getBaseUriString(int port) { |
86 | 75 | return getBaseUri(port).toString(); |
87 | 76 | } |
88 | 77 |
|
89 | 78 | private static URI getBaseUri(int port) { |
90 | 79 | return URI.create("http://localhost:" + port); |
91 | 80 | } |
| 81 | + |
92 | 82 | } |
0 commit comments