Skip to content

Commit 2adb213

Browse files
committed
✨ Altered tests to improve tests using TestContainers
This set of changes has the following effects: 1) Makes a distinction between which sample files are local and which ones must be on the remote machine (previously, everything was set up for a local machine). 2) Understands that remote machines may be Windows or Linux 3) Contains files for creating a container containing the required sample files.
1 parent 94a43a2 commit 2adb213

42 files changed

Lines changed: 709 additions & 612 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rest-services/it.tests/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# FluentForms REST Services Integration Test Project
2+
3+
This maven project contains the Integration tests that run against (and require) a real AEM instance.
4+
5+
Some tests are tagged because they require the ream AEM instance to be configured in a specific way. These tags are:
6+
7+
`requiresPdfG` - Requires PDFG to be configured
8+
9+
`requiresRe` - Requires a Reader Extensions credential to be configured.
10+
11+
You can exclude these tags in order for the tests to run successfully when the AEM instance is not configured to meet these requirements.

rest-services/it.tests/src/test/java/com/_4point/aem/docservices/rest_services/it_tests/AemInstance.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import org.testcontainers.containers.GenericContainer;
1616
import org.testcontainers.utility.DockerImageName;
1717

18-
import com._4point.aem.docservices.rest_services.it_tests.TestUtils.AemTargetType;
19-
2018
/**
2119
* This singleton defines the AEM instance that is being used for the integration tests.
2220
*
@@ -30,20 +28,23 @@ public enum AemInstance {
3028
// These tests require an AEM container image with AEM forms installed. Since AEM is proprietary, it is not possible to obtain this
3129
// through public images. By default, this uses a private image hosted in the 4PointSolutions-PS GitHub organization. If you are not
3230
// part of that prg, you will have to supply your own image.
33-
private static final String AEM_IMAGE_NAME = "ghcr.io/4pointsolutions-ps/aem:aem65sp21";
34-
private final TestUtils.AemTargetType targetType;
31+
// private static final String AEM_IMAGE_NAME = "ghcr.io/4pointsolutions-ps/aem:aem65sp21";
32+
// private static final String AEM_IMAGE_NAME = "aem_lts:aem65lts";
33+
private static final String AEM_IMAGE_NAME = "aem_lts_it_tests:aem65lts_it_tests";
34+
35+
private final AemTargetType targetType;
3536
private final GenericContainer<?> aemContainer;
3637
private final AtomicBoolean preparedForTests = new AtomicBoolean(false);
3738

3839
@SuppressWarnings("resource")
39-
private AemInstance(TestUtils.AemTargetType targetType) {
40+
private AemInstance(AemTargetType targetType) {
4041
this(targetType, targetType == AemTargetType.TESTCONTAINERS ? new GenericContainer<>(DockerImageName.parse(AEM_IMAGE_NAME))
4142
.withReuse(true)
4243
.withExposedPorts(4502)
4344
: null);
4445
}
4546

46-
private AemInstance(TestUtils.AemTargetType targetType, GenericContainer<?> aemContainer) {
47+
private AemInstance(AemTargetType targetType, GenericContainer<?> aemContainer) {
4748
this.targetType = targetType;
4849
this.aemContainer = aemContainer;
4950
if (aemContainer != null) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com._4point.aem.docservices.rest_services.it_tests;
2+
3+
import java.nio.file.Path;
4+
5+
/**
6+
* Enum representing the different target types for AEM instances in the
7+
* integration tests. Each enum value corresponds to a specific environment
8+
* where AEM is expected to run, along with the path to the sample files used in
9+
* the tests.
10+
*/
11+
public enum AemTargetType {
12+
LOCAL(Path.of("..", "test_containers", "ff_it_files").toAbsolutePath()), // Running on local machine (assumes that the port is TEST_MACHINE_PORT)
13+
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)
14+
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)
15+
TESTCONTAINERS(Path.of("/opt", "adobe", "ff_it_files")); // Running on local testcontainers image (gets port from TestContainers)
16+
17+
private final Path samplesPath; // Location where sample files are stored for this AEM target type.
18+
19+
private AemTargetType(Path samplesPath) {
20+
this.samplesPath = samplesPath;
21+
}
22+
23+
/**
24+
* Returns the path to the samples directory for this AEM target type.
25+
*
26+
* @return Path to the samples directory.
27+
*/
28+
public Path samplesPath(String filename) {
29+
return this.samplesPath.resolve(filename);
30+
}
31+
}
32+

rest-services/it.tests/src/test/java/com/_4point/aem/docservices/rest_services/it_tests/TestUtils.java

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package com._4point.aem.docservices.rest_services.it_tests;
22

3-
import static org.hamcrest.CoreMatchers.containsString;
3+
import static org.hamcrest.Matchers.*;
44
import static org.hamcrest.MatcherAssert.assertThat;
5-
import static org.junit.jupiter.api.Assertions.assertAll;
6-
import static org.junit.jupiter.api.Assertions.assertFalse;
7-
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
import static org.junit.jupiter.api.Assertions.*;
86

97
import java.io.IOException;
108
import java.io.InputStream;
11-
import java.net.URISyntaxException;
129
import java.nio.charset.StandardCharsets;
1310
import java.nio.file.Files;
1411
import java.nio.file.Path;
@@ -31,13 +28,6 @@ public class TestUtils {
3128
public static final String TEST_USER = "admin";
3229
public static final String TEST_USER_PASSWORD = "admin";
3330

34-
public enum AemTargetType {
35-
LOCAL, // Running on local machine (assumes that the port is TEST_MACHINE_PORT)
36-
REMOTE_WINDOWS, // Running on remote Windows machine (assumes that machine name is TEST_MACHINE_NAME and port is TEST_MACHINE_PORT)
37-
REMOTE_LINUX, // Running on remote Linux machine (assumes that machine name is TEST_MACHINE_NAME and port is TEST_MACHINE_PORT)
38-
TESTCONTAINERS; // Running on local testcontainers image (gets port from TestContainers)
39-
}
40-
4131
// Set this to indicate the type of machine that AEM is running on:
4232
// The integration tests will run against an AEM instance running in a Docker container otherwise they will run against a local AEM instance.
4333
public static final AemTargetType AEM_TARGET_TYPE = AemTargetType.LOCAL;
@@ -54,7 +44,7 @@ public enum AemTargetType {
5444
// * JSAFE not configured - Causes Assembler test to fail (should be fixed in latest AEM image)
5545
// * Sample XDP not deployed - Causes HTML5, PDF and Print rendering tests to fail (should be fixed in latest AEM image)
5646
// * GeneratePrintedOutput test AllArgs seems to want D:\FluentForms\Forms - Need to fix tests
57-
// * Generate HTLML5 test fails because proteted mode is on - Need to fix AEM image creation code to set this.
47+
// * Generate HTLML5 test fails because protected mode is on - Need to fix AEM image creation code to set this.
5848

5949
private static final String SAMPLE_FORM_PDF_NAME = "SampleForm.pdf";
6050
private static final String SAMPLE_FORM_XDP_NAME = "SampleForm.xdp";
@@ -64,31 +54,38 @@ public enum AemTargetType {
6454
private static final String SAMPLE_FORM_DATA_JSON_NAME = "SampleForm_data.json";
6555
private static final String SAMPLE_FORM_DATA_DOCX_NAME = "SampleForm.docx";
6656
private static final String SAMPLE_FORM_DDX_NAME = "SampleForm_DDX.xml";
67-
private static final ClassLoader classLoader = ClassLoader.getSystemClassLoader();
6857

69-
public static final Path SAMPLE_FORM_PDF = getPath(SAMPLE_FORM_PDF_NAME);
70-
public static final Path SAMPLE_FORM_WITH_DATA_PDF = getPath(SAMPLE_FORM_WITH_DATA_PDF_NAME);
71-
public static final Path SAMPLE_FORM_WITHOUT_DATA_PDF = getPath(SAMPLE_FORM_WITHOUT_DATA_PDF_NAME);
72-
public static final Path SAMPLE_FORM_XDP = getPath(SAMPLE_FORM_XDP_NAME);
73-
public static final Path SAMPLE_FORM_DATA_XML = getPath(SAMPLE_FORM_DATA_XML_NAME);
74-
public static final Path SAMPLE_FORM_DATA_JSON = getPath(SAMPLE_FORM_DATA_JSON_NAME);
75-
public final static Path SAMPLE_FORM_DOCX = getPath(SAMPLE_FORM_DATA_DOCX_NAME);
76-
public static final Path SAMPLE_FORM_DDX = getPath(SAMPLE_FORM_DDX_NAME);
58+
public static final Path REMOTE_SAMPLE_FORM_PDF = AEM_TARGET_TYPE.samplesPath(SAMPLE_FORM_PDF_NAME);
59+
public static final Path REMOTE_SAMPLE_FORM_WITH_DATA_PDF = AEM_TARGET_TYPE.samplesPath(SAMPLE_FORM_WITH_DATA_PDF_NAME);
60+
public static final Path REMOTE_SAMPLE_FORM_WITHOUT_DATA_PDF = AEM_TARGET_TYPE.samplesPath(SAMPLE_FORM_WITHOUT_DATA_PDF_NAME);
61+
public static final Path REMOTE_SAMPLE_FORM_XDP = AEM_TARGET_TYPE.samplesPath(SAMPLE_FORM_XDP_NAME);
62+
public static final Path REMOTE_SAMPLE_FORM_DATA_XML = AEM_TARGET_TYPE.samplesPath(SAMPLE_FORM_DATA_XML_NAME);
63+
public static final Path REMOTE_SAMPLE_FORM_DATA_JSON = AEM_TARGET_TYPE.samplesPath(SAMPLE_FORM_DATA_JSON_NAME);
64+
public final static Path REMOTE_SAMPLE_FORM_DOCX = AEM_TARGET_TYPE.samplesPath(SAMPLE_FORM_DATA_DOCX_NAME);
65+
public static final Path REMOTE_SAMPLE_FORM_DDX = AEM_TARGET_TYPE.samplesPath(SAMPLE_FORM_DDX_NAME);
66+
67+
public static final Path LOCAL_SAMPLE_FORM_PDF = AemTargetType.LOCAL.samplesPath(SAMPLE_FORM_PDF_NAME);
68+
public static final Path LOCAL_SAMPLE_FORM_WITH_DATA_PDF = AemTargetType.LOCAL.samplesPath(SAMPLE_FORM_WITH_DATA_PDF_NAME);
69+
public static final Path LOCAL_SAMPLE_FORM_WITHOUT_DATA_PDF = AemTargetType.LOCAL.samplesPath(SAMPLE_FORM_WITHOUT_DATA_PDF_NAME);
70+
public static final Path LOCAL_SAMPLE_FORM_XDP = AemTargetType.LOCAL.samplesPath(SAMPLE_FORM_XDP_NAME);
71+
public static final Path LOCAL_SAMPLE_FORM_DATA_XML = AemTargetType.LOCAL.samplesPath(SAMPLE_FORM_DATA_XML_NAME);
72+
public static final Path LOCAL_SAMPLE_FORM_DATA_JSON = AemTargetType.LOCAL.samplesPath(SAMPLE_FORM_DATA_JSON_NAME);
73+
public final static Path LOCAL_SAMPLE_FORM_DOCX = AemTargetType.LOCAL.samplesPath(SAMPLE_FORM_DATA_DOCX_NAME);
74+
public static final Path LOCAL_SAMPLE_FORM_DDX = AemTargetType.LOCAL.samplesPath(SAMPLE_FORM_DDX_NAME);
7775

7876
public static final Path RESOURCES_DIR = Paths.get("src", "test", "resources");
7977
public static final Path ACTUAL_RESULTS_DIR = RESOURCES_DIR.resolve("actualResults");
80-
public static final Path SERVER_FORMS_DIR = Paths.get("D:", "FluentForms", "Forms");
8178

8279
private static final boolean SAVE_RESULTS = false;
8380

84-
private static Path getPath(String name) {
85-
try {
86-
return Paths.get(classLoader.getResource(name).toURI());
87-
} catch (URISyntaxException e) {
88-
throw new IllegalStateException("getResource returned invalid URI. (This should never happen!)", e);
89-
}
90-
}
91-
81+
// private static Path getPath(String name) {
82+
// try {
83+
// return Paths.get(classLoader.getResource(name).toURI());
84+
// } catch (URISyntaxException e) {
85+
// throw new IllegalStateException("getResource returned invalid URI. (This should never happen!)", e);
86+
// }
87+
// }
88+
//
9289
public static String readEntityToString(Response result) {
9390
try {
9491
return IOUtils.toString((InputStream)result.getEntity(), StandardCharsets.UTF_8);

rest-services/it.tests/src/test/java/com/_4point/aem/docservices/rest_services/it_tests/client/af/RenderAdaptiveFormTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void testRenderAdaptiveFormPath() throws Exception {
9898
@Test
9999
void testRenderAdaptiveFormPathOrUrlDocument() throws Exception {
100100
PathOrUrl template = PathOrUrl.from(SAMPLE_AF_NAME);
101-
Document data = SimpleDocumentFactoryImpl.INSTANCE.create(TestUtils.SAMPLE_FORM_DATA_XML);
101+
Document data = SimpleDocumentFactoryImpl.INSTANCE.create(TestUtils.LOCAL_SAMPLE_FORM_DATA_XML);
102102
data.setContentTypeIfEmpty("application/xml");
103103

104104
Document result = underTest.renderAdaptiveForm(template, data);
@@ -115,7 +115,7 @@ void testRenderAdaptiveFormPathOrUrlDocument() throws Exception {
115115
@Test
116116
void testRenderAdaptiveFormStringDocument() throws Exception {
117117
String template = SAMPLE_AF_NAME;
118-
Document data = SimpleDocumentFactoryImpl.INSTANCE.create(TestUtils.SAMPLE_FORM_DATA_XML);
118+
Document data = SimpleDocumentFactoryImpl.INSTANCE.create(TestUtils.LOCAL_SAMPLE_FORM_DATA_XML);
119119
data.setContentTypeIfEmpty("application/xml");
120120

121121
Document result = underTest.renderAdaptiveForm(template, data);
@@ -132,7 +132,7 @@ void testRenderAdaptiveFormStringDocument() throws Exception {
132132
@Test
133133
void testRenderAdaptiveFormPathDocument() throws Exception {
134134
Path template = Paths.get(SAMPLE_AF_NAME);
135-
Document data = SimpleDocumentFactoryImpl.INSTANCE.create(TestUtils.SAMPLE_FORM_DATA_XML);
135+
Document data = SimpleDocumentFactoryImpl.INSTANCE.create(TestUtils.LOCAL_SAMPLE_FORM_DATA_XML);
136136
data.setContentTypeIfEmpty("application/xml");
137137

138138
Document result = underTest.renderAdaptiveForm(template, data);
@@ -149,7 +149,7 @@ void testRenderAdaptiveFormPathDocument() throws Exception {
149149
@Test
150150
void testRenderAdaptiveFormStringJsonDocument() throws Exception {
151151
String template = SAMPLE_JSON_AF_NAME;
152-
Document data = SimpleDocumentFactoryImpl.INSTANCE.create(TestUtils.SAMPLE_FORM_DATA_JSON);
152+
Document data = SimpleDocumentFactoryImpl.INSTANCE.create(TestUtils.LOCAL_SAMPLE_FORM_DATA_JSON);
153153
data.setContentTypeIfEmpty("application/json");
154154

155155
Document result = underTest.renderAdaptiveForm(template, data);

rest-services/it.tests/src/test/java/com/_4point/aem/docservices/rest_services/it_tests/client/assembler/AssembleDocumentsTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ void setUp() throws Exception {
7070
@DisplayName("Test AssembleDocuments() Happy Path.")
7171
void testAssembleDocuments() throws Exception {
7272
AssemblerResult assemblerResult = underTest.invoke()
73-
.add("File0.pdf", DOC_FACTORY.create(SAMPLE_FORM_WITHOUT_DATA_PDF))
74-
.add("File1.pdf", DOC_FACTORY.create(SAMPLE_FORM_WITHOUT_DATA_PDF).setContentType("application/pdf"))
75-
.executeOn(DOC_FACTORY.create(SAMPLE_FORM_DDX));
73+
.add("File0.pdf", DOC_FACTORY.create(LOCAL_SAMPLE_FORM_WITHOUT_DATA_PDF))
74+
.add("File1.pdf", DOC_FACTORY.create(LOCAL_SAMPLE_FORM_WITHOUT_DATA_PDF).setContentType("application/pdf"))
75+
.executeOn(DOC_FACTORY.create(LOCAL_SAMPLE_FORM_DDX));
7676

7777
Map<String, Document> resultDocuments = assemblerResult.getDocuments();
7878
validateResultMap(resultDocuments);
@@ -106,9 +106,9 @@ void testAssembleDocuments_withAllArgs() throws Exception {
106106
.setLogLevel(LogLevel.ALL)
107107
.setTakeOwnership(Boolean.FALSE)
108108
.setValidateOnly(Boolean.FALSE)
109-
.add("File0.pdf", DOC_FACTORY.create(SAMPLE_FORM_WITHOUT_DATA_PDF).setContentType("application/pdf"))
110-
.add("File1.pdf", DOC_FACTORY.create(SAMPLE_FORM_WITHOUT_DATA_PDF))
111-
.executeOn(DOC_FACTORY.create(SAMPLE_FORM_DDX));
109+
.add("File0.pdf", DOC_FACTORY.create(LOCAL_SAMPLE_FORM_WITHOUT_DATA_PDF).setContentType("application/pdf"))
110+
.add("File1.pdf", DOC_FACTORY.create(LOCAL_SAMPLE_FORM_WITHOUT_DATA_PDF))
111+
.executeOn(DOC_FACTORY.create(LOCAL_SAMPLE_FORM_DDX));
112112

113113
Map<String, Document> resultDocuments = assemblerResult.getDocuments();
114114
validateResultMap(resultDocuments);
@@ -117,12 +117,12 @@ void testAssembleDocuments_withAllArgs() throws Exception {
117117
@Test
118118
@DisplayName("Test testAssembleDocuments with bad data.")
119119
void testAssembleDocuments_BadData() throws Exception {
120-
Map<String, Object> sourceDocuments = Map.of("File0.pdf", DOC_FACTORY.create(SAMPLE_FORM_PDF),
121-
"File1.pdf", DOC_FACTORY.create(SAMPLE_FORM_PDF)
120+
Map<String, Object> sourceDocuments = Map.of("File0.pdf", DOC_FACTORY.create(LOCAL_SAMPLE_FORM_PDF),
121+
"File1.pdf", DOC_FACTORY.create(LOCAL_SAMPLE_FORM_PDF)
122122
);
123123
AssemblerOptionsSpecImpl assemblerOptionsSpecImpl = new AssemblerOptionsSpecImpl();
124124
assemblerOptionsSpecImpl.setLogLevel(LogLevel.ALL);
125-
AssemblerServiceException ex = assertThrows(AssemblerServiceException.class, ()->underTest.invoke(DOC_FACTORY.create(SAMPLE_FORM_DOCX), sourceDocuments, assemblerOptionsSpecImpl));
125+
AssemblerServiceException ex = assertThrows(AssemblerServiceException.class, ()->underTest.invoke(DOC_FACTORY.create(LOCAL_SAMPLE_FORM_DOCX), sourceDocuments, assemblerOptionsSpecImpl));
126126

127127
assertThat(ex, exceptionMsgContainsAll("Error while POSTing to server"));
128128
}
@@ -131,7 +131,7 @@ void testAssembleDocuments_BadData() throws Exception {
131131
@DisplayName("Test ToPdfA() Happy Path.")
132132
void testToPdfA() throws Exception {
133133
PDFAConversionResult result = underTest.toPDFA()
134-
.executeOn(DOC_FACTORY.create(SAMPLE_FORM_PDF));
134+
.executeOn(DOC_FACTORY.create(LOCAL_SAMPLE_FORM_PDF));
135135
Document pdfaDocument = result.getPDFADocument();
136136
Document conversionLog = result.getConversionLog();
137137
Document jobLog = result.getJobLog();
@@ -158,7 +158,7 @@ void testToPdfA_withAllArgs() throws Exception {
158158
.setRetainPDFFormState(true)
159159
.setSignatures(Signatures.ARCHIVE_ALWAYS)
160160
.setVerify(true)
161-
.executeOn(DOC_FACTORY.create(SAMPLE_FORM_PDF));
161+
.executeOn(DOC_FACTORY.create(LOCAL_SAMPLE_FORM_PDF));
162162
Document pdfaDocument = result.getPDFADocument();
163163
Document conversionLog = result.getConversionLog();
164164
Document jobLog = result.getJobLog();
@@ -177,7 +177,7 @@ void testAssembleDocuments_DocInfoDdx() throws Exception {
177177
+ " <DocumentInformation result=\"info\" source=\"doc1\"/>\n"
178178
+ "</DDX>\n";
179179

180-
Map<String, EitherDocumentOrDocumentList> inputDocs = Collections.singletonMap("doc1", EitherDocumentOrDocumentList.from(DOC_FACTORY.create(SAMPLE_FORM_PDF)));
180+
Map<String, EitherDocumentOrDocumentList> inputDocs = Collections.singletonMap("doc1", EitherDocumentOrDocumentList.from(DOC_FACTORY.create(LOCAL_SAMPLE_FORM_PDF)));
181181

182182
AssemblerResult result = underTest.invoke()
183183
.executeOn2(DOC_FACTORY.create(ddx.getBytes()), inputDocs);

0 commit comments

Comments
 (0)