Skip to content

Commit b3b06d9

Browse files
committed
✅ AemProxyEndpoint tests now work in all scenarios
1 parent b6e4ea8 commit b3b06d9

3 files changed

Lines changed: 46 additions & 23 deletions

File tree

spring/fluentforms-sample-webmvc-app/src/test/java/com/_4point/aem/fluentforms/sampleapp/resources/AbstractAemProxyEndpointTest.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
package com._4point.aem.fluentforms.sampleapp.resources;
22

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.*;
94
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.*;
136
import static org.junit.jupiter.api.Assertions.assertEquals;
147

158
import java.net.URI;
169
import java.nio.file.Path;
17-
import java.util.List;
1810
import java.util.concurrent.TimeUnit;
1911

2012
import org.htmlunit.WebClient;
@@ -28,11 +20,15 @@
2820
import org.springframework.web.client.RestClient;
2921

3022
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");
3324

3425
@LocalServerPort
3526
private int port;
27+
private final String sampleFileLocation;
28+
29+
protected AbstractAemProxyEndpointTest(String sampleFileLocation) {
30+
this.sampleFileLocation = sampleFileLocation;
31+
}
3632

3733
@Timeout(value = 30, unit = TimeUnit.SECONDS)
3834
@Test
@@ -66,27 +62,21 @@ void testProxyCsrfToken() throws Exception {
6662
@Test
6763
void proxyTest() throws Exception {
6864
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;
7066
final HtmlPage page = webClient.getPage(baseUri);
7167
assertEquals("LC Forms", page.getTitleText());
7268
}
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();
8370
}
8471

72+
protected abstract void verifyProxyTest();
73+
8574
protected static String getBaseUriString(int port) {
8675
return getBaseUri(port).toString();
8776
}
8877

8978
private static URI getBaseUri(int port) {
9079
return URI.create("http://localhost:" + port);
9180
}
81+
9282
}

spring/fluentforms-sample-webmvc-app/src/test/java/com/_4point/aem/fluentforms/sampleapp/resources/AemInstanceAemProxyEndpointTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@
1414
)
1515
@ContextConfiguration(initializers = AemInstance.AemInstanceContextInitializer.class)
1616
public class AemInstanceAemProxyEndpointTest extends AbstractAemProxyEndpointTest {
17+
private static final String CRX_CONTENT_ROOT = "crx:/content/dam/formsanddocuments/sample-forms/";
18+
19+
protected AemInstanceAemProxyEndpointTest() {
20+
super(CRX_CONTENT_ROOT + SAMPLE_XDP_FILENAME_PATH);
21+
}
1722

1823
@BeforeAll
1924
static void setUpAll() throws Exception {
2025
AemInstance.AEM_1.prepareForTests();
2126
}
2227

28+
@Override
29+
protected void verifyProxyTest() {
30+
// Can't really verify that the calls were made to AEM (other than no errors occurred).
31+
}
32+
2333
}

spring/fluentforms-sample-webmvc-app/src/test/java/com/_4point/aem/fluentforms/sampleapp/resources/WireMockAemProxyEndpointTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static com.github.tomakehurst.wiremock.client.WireMock.*;
44
import static org.junit.jupiter.api.Assertions.*;
55

6+
import java.nio.file.Path;
67
import java.util.List;
78

89
import org.htmlunit.DefaultCredentialsProvider;
@@ -38,6 +39,13 @@
3839
class WireMockAemProxyEndpointTest extends AbstractAemProxyEndpointTest {
3940
private static final boolean WIREMOCK_RECORDING = false;
4041

42+
private static final Path RESOURCES_DIR = Path.of("src", "test", "resources");
43+
private static final Path SAMPLE_FILES_DIR = RESOURCES_DIR.resolve("SampleFiles");
44+
45+
public WireMockAemProxyEndpointTest() {
46+
super(SAMPLE_FILES_DIR.resolve(SAMPLE_XDP_FILENAME_PATH).toAbsolutePath().toString());
47+
}
48+
4149
@BeforeEach
4250
void setUp(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
4351
if (WIREMOCK_RECORDING) {
@@ -59,6 +67,21 @@ void tearDown() throws Exception {
5967
}
6068
}
6169
}
70+
71+
@Override
72+
protected void verifyProxyTest() {
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))));
83+
}
84+
6285

6386
// In order to re-record the AEM interactions for Wiremock emulation, you need to:
6487
// 1) run a local AEM server

0 commit comments

Comments
 (0)