Skip to content

Commit aa51b3e

Browse files
committed
✅ Got the AemInstanceFluentFormsResources tests working.
1 parent b3b06d9 commit aa51b3e

6 files changed

Lines changed: 41 additions & 10 deletions

File tree

spring/fluentforms-sample-webmvc-app/src/main/java/com/_4point/aem/fluentforms/sampleapp/resources/FluentFormsResources.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public class FluentFormsResources {
5555
protected static final String RESOURCE_PATH = "/FluentForms";
5656

5757
// TODO: Move this to configuration value
58-
String contentRoot = "crx:/content/dam/formsanddocuments";
58+
// String contentRoot = "crx:/content/dam/formsanddocuments";
59+
String contentRoot = "";
5960

6061
@Autowired
6162
DocumentFactory documentFactory;

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,26 @@
2020
public abstract class AbstractFluentFormsResourcesTest {
2121
private static final String APPLICATION_PDF = "application/pdf";
2222
private static final MediaType APPLICATION_PDF_TYPE = MediaType.valueOf(APPLICATION_PDF);
23-
23+
2424
private static final Path RESOURCES_DIR = Path.of("src", "test", "resources");
2525
private static final Path SAMPLE_FILES_DIR = RESOURCES_DIR.resolve("SampleFiles");
26+
protected static final Path SAMPLE_XDP_FILENAME_PATH = Path.of("SampleForm.xdp");
2627

2728
private static final RestClient REST_CLIENT = RestClient.create();
2829

2930
@LocalServerPort
3031
private int port;
32+
private final String sampleFormLocation;
33+
34+
protected AbstractFluentFormsResourcesTest(String sampleFormLocation) {
35+
this.sampleFormLocation = sampleFormLocation;
36+
}
37+
3138
@Test
3239
void testOutputServiceGeneratePdf_NoData() {
3340
URI uri = UriComponentsBuilder.fromUri(getBaseUri(port))
3441
.path("/FluentForms/OutputServiceGeneratePdf")
35-
.queryParam("form", "sample_template.xdp")
42+
.queryParam("form", sampleFormLocation)
3643
.build()
3744
.toUri();
3845

@@ -63,7 +70,7 @@ void testOutputServiceGeneratePdf_WithData() {
6370

6471
URI uri = UriComponentsBuilder.fromUri(getBaseUri(port))
6572
.path("/FluentForms/OutputServiceGeneratePdf")
66-
.queryParam("form", "sample_template.xdp")
73+
.queryParam("form", sampleFormLocation)
6774
.queryParam("dataKey", dataKeyValue)
6875
.build()
6976
.toUri();
@@ -80,7 +87,7 @@ void testOutputServiceGeneratePdf_WithData() {
8087
void testOutputServiceGeneratePdf_WithPostedXmlData() {
8188
URI uri = UriComponentsBuilder.fromUri(getBaseUri(port))
8289
.path("/FluentForms/OutputServiceGeneratePdf")
83-
.queryParam("form", "sample_template.xdp")
90+
.queryParam("form", sampleFormLocation)
8491
.build()
8592
.toUri();
8693

@@ -97,7 +104,7 @@ void testOutputServiceGeneratePdf_WithPostedXmlData() {
97104
void testOutputServiceGeneratePdf_WithPostedJsonData() {
98105
URI uri = UriComponentsBuilder.fromUri(getBaseUri(port))
99106
.path("/FluentForms/OutputServiceGeneratePdf")
100-
.queryParam("form", "sample_template.xdp")
107+
.queryParam("form", sampleFormLocation)
101108
.build()
102109
.toUri();
103110

@@ -162,7 +169,7 @@ void testAdaptiveFormsServiceRenderAdaptiveForm_WithData() {
162169
void testHtml5FormsServiceRenderHtml5Form_NoData() {
163170
URI uri = UriComponentsBuilder.fromUri(getBaseUri(port))
164171
.path("/FluentForms/Html5FormsServiceRenderHtml5Form")
165-
.queryParam("form", SAMPLE_FILES_DIR.resolve("SampleForm.xdp").toAbsolutePath())
172+
.queryParam("form", sampleFormLocation)
166173
.build()
167174
.toUri();
168175

@@ -193,7 +200,7 @@ void testHtml5FormsServiceRenderHtmlForm_WithData() {
193200

194201
URI uri = UriComponentsBuilder.fromUri(getBaseUri(port))
195202
.path("/FluentForms/Html5FormsServiceRenderHtml5Form")
196-
.queryParam("form", SAMPLE_FILES_DIR.resolve("SampleForm.xdp").toAbsolutePath())
203+
.queryParam("form", sampleFormLocation)
197204
.queryParam("dataKey", dataKeyValue)
198205
.build()
199206
.toUri();

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ public boolean isLocal() {
138138
return aemContainer == null && aemHost().equalsIgnoreCase(LOCALHOST);
139139
}
140140

141+
public Path samplesPath(String filename) {
142+
return targetType.samplesPath(filename);
143+
}
144+
145+
public Path samplesPath(Path filename) {
146+
return samplesPath(filename.toString());
147+
}
148+
141149
private static boolean aemIsUp(HttpClient restClient, HttpRequest request) {
142150
try {
143151
HttpResponse<Void> result = restClient.send(request, BodyHandlers.discarding());
@@ -165,7 +173,7 @@ private static String encodeBasic(String username, String password) {
165173
* the tests.
166174
*/
167175
public enum AemTargetType {
168-
LOCAL(Path.of("..", "test_containers", "ff_it_files").toAbsolutePath()), // Running on local machine (assumes that the port is TEST_MACHINE_PORT)
176+
LOCAL(Path.of("src", "test", "resources", "SampleFiles").toAbsolutePath()), // Running on local machine (assumes that the port is TEST_MACHINE_PORT)
169177
REMOTE_WINDOWS(Path.of("/Adobe", "ff_it_files")), // Running on remote Windows machine (assumes that machine name is TEST_MACHINE_NAME and port is TEST_MACHINE_PORT)
170178
REMOTE_LINUX(Path.of("/opt", "adobe", "ff_it_files")), // Running on remote Linux machine (assumes that machine name is TEST_MACHINE_NAME and port is TEST_MACHINE_PORT)
171179
TESTCONTAINERS(Path.of("/opt", "adobe", "ff_it_files")); // Running on local testcontainers image (gets port from TestContainers)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@
88

99
import com._4point.aem.fluentforms.sampleapp.FluentFormsSpringApplication;
1010

11+
/**
12+
* These AEM Instance tests run against a running AEM instance that have sample forms deployed to the same locations
13+
* as the rest-serivices it.tests tests. In practice, this means that (for example) the test containers docker image
14+
* should be the it.tests docker image.
15+
*/
1116
@EnabledIf("com._4point.aem.fluentforms.sampleapp.resources.TestConstants#runAemInstanceTests")
1217
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
1318
classes = FluentFormsSpringApplication.class
1419
)
1520
@ContextConfiguration(initializers = AemInstance.AemInstanceContextInitializer.class)
1621
public class AemInstanceFluentFormsResourcesTest extends AbstractFluentFormsResourcesTest {
1722

23+
protected AemInstanceFluentFormsResourcesTest() {
24+
super(AemInstance.AEM_1.samplesPath(SAMPLE_XDP_FILENAME_PATH).toString());
25+
}
26+
1827
@BeforeAll
1928
static void setUpAll() throws Exception {
2029
AemInstance.AEM_1.prepareForTests();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com._4point.aem.fluentforms.sampleapp.resources;
22

3+
import java.nio.file.Path;
34
import java.util.List;
45

56
import org.junit.jupiter.api.AfterEach;
@@ -30,7 +31,12 @@
3031
class WireMockFluentFormsResourcesTest extends AbstractFluentFormsResourcesTest {
3132
private static final boolean WIREMOCK_RECORDING = false;
3233

34+
private static final Path RESOURCES_DIR = Path.of("src", "test", "resources");
35+
private static final Path SAMPLE_FILES_DIR = RESOURCES_DIR.resolve("SampleFiles");
3336

37+
private WireMockFluentFormsResourcesTest() {
38+
super(SAMPLE_FILES_DIR.resolve(SAMPLE_XDP_FILENAME_PATH).toAbsolutePath().toString());
39+
}
3440

3541
@BeforeEach
3642
void setUp(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {

spring/fluentforms-sample-webmvc-app/src/test/resources/mappings/FluentFormsResourcesTest_testOutputServiceGeneratePdf_Success.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url" : "/services/OutputService/GeneratePdfOutput",
66
"method" : "POST",
77
"bodyPatterns" : [ {
8-
"contains" : "sample_template"
8+
"contains" : "SampleForm.xdp"
99
} ]
1010
},
1111
"response" : {

0 commit comments

Comments
 (0)