Skip to content

Commit 4edf465

Browse files
committed
✨ Updated tests to provide easier test configuration based on AEM target
Some tests only work in certain scenarios, so the mecahnism I have added should make it easier to exclude tests that are just going to fail because of how AEM is configured.
1 parent 398f42e commit 4edf465

File tree

3 files changed

+73
-27
lines changed

3 files changed

+73
-27
lines changed

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,39 @@
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+
20+
/**
21+
* This singleton defines the AEM instance that is being used for the integration tests.
22+
*
23+
* Change the value of TestUtils.AEM_TARGET_TYPE in the TestUtils class to tell the tests what type of AEM instance we're testing against.
24+
*/
1825
public enum AemInstance {
19-
AEM_1(TestUtils.USE_TESTCONTAINERS); // Change parameter to false to disable TestContainers and use local AEM instance..,
26+
AEM_1(TestUtils.AEM_TARGET_TYPE); // Change parameter to false to disable TestContainers and use local AEM instance..,
2027

2128
private static final String LOCALHOST = "localhost";
2229

2330
// These tests require an AEM container image with AEM forms installed. Since AEM is proprietary, it is not possible to obtain this
2431
// through public images. By default, this uses a private image hosted in the 4PointSolutions-PS GitHub organization. If you are not
2532
// part of that prg, you will have to supply your own image.
2633
private static final String AEM_IMAGE_NAME = "ghcr.io/4pointsolutions-ps/aem:aem65sp21";
34+
private final TestUtils.AemTargetType targetType;
2735
private final GenericContainer<?> aemContainer;
2836
private final AtomicBoolean preparedForTests = new AtomicBoolean(false);
2937

30-
private AemInstance(boolean useTestContainers) {
31-
this(useTestContainers ? new GenericContainer<>(DockerImageName.parse(AEM_IMAGE_NAME))
38+
@SuppressWarnings("resource")
39+
private AemInstance(TestUtils.AemTargetType targetType) {
40+
this(targetType, targetType == AemTargetType.TESTCONTAINERS ? new GenericContainer<>(DockerImageName.parse(AEM_IMAGE_NAME))
3241
.withReuse(true)
3342
.withExposedPorts(4502)
3443
: null);
3544
}
3645

37-
private AemInstance(GenericContainer<?> aemContainer) {
46+
private AemInstance(TestUtils.AemTargetType targetType, GenericContainer<?> aemContainer) {
47+
this.targetType = targetType;
3848
this.aemContainer = aemContainer;
3949
if (aemContainer != null) {
4050
aemContainer.start();
41-
4251
}
4352
}
4453

@@ -86,14 +95,37 @@ public static void deploySampleFiles(Integer mappedPort) {
8695
System.out.println("Sample files deployed.");
8796
}
8897

98+
/**
99+
* Host name where AEM is running
100+
*
101+
* @return
102+
*/
89103
public String aemHost() {
90-
return aemContainer != null ? LOCALHOST : TestUtils.TEST_MACHINE_NAME;
104+
return switch (targetType) {
105+
case LOCAL, TESTCONTAINERS -> LOCALHOST;
106+
case REMOTE_WINDOWS, REMOTE_LINUX -> TestUtils.TEST_MACHINE_NAME;
107+
};
91108
}
92109

110+
/**
111+
* Port where AEM is running.
112+
*
113+
* @return
114+
*/
93115
public Integer aemPort() {
94-
return aemContainer != null ? aemContainer.getMappedPort(4502) : Integer.parseInt(TestUtils.TEST_MACHINE_PORT_STR) ;
116+
return switch (targetType) {
117+
case LOCAL, REMOTE_WINDOWS, REMOTE_LINUX -> Integer.parseInt(TestUtils.TEST_MACHINE_PORT_STR);
118+
case TESTCONTAINERS -> aemContainer.getMappedPort(4502);
119+
};
95120
}
96121

122+
public Boolean isLinux() {
123+
return switch (targetType) {
124+
case LOCAL -> !System.getProperty("os.name").toLowerCase().contains("windows"); // Treat MAC as Linux
125+
case REMOTE_WINDOWS -> false;
126+
case REMOTE_LINUX, TESTCONTAINERS -> true;
127+
};
128+
}
97129
/**
98130
* Is AEM running locally or remotely?
99131
*

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,30 @@ public class TestUtils {
3131
public static final String TEST_USER = "admin";
3232
public static final String TEST_USER_PASSWORD = "admin";
3333

34-
// Set this to true to use TestContainers for the integration tests.
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+
41+
// Set this to indicate the type of machine that AEM is running on:
3542
// The integration tests will run against an AEM instance running in a Docker container otherwise they will run against a local AEM instance.
36-
public static final boolean USE_TESTCONTAINERS = false;
37-
// Status of TestContainers support.
43+
public static final AemTargetType AEM_TARGET_TYPE = AemTargetType.LOCAL;
44+
// Status of LOCAL AEM Target support.
3845
// AEM Integration test issues:
39-
// * Sample Adaptive Form not deployed - Causes AF Rendering test to fail
40-
// * JSAFE not configured - Causes Assembler test to fail
41-
// * Sample XDP not deployed - Causes HTML5, PDF and Print rendering tests to fail
42-
// * GeneratePrintedOutput test AllArgs seems to want D:\FluentForms\Forms - Need to fix tests
43-
// * Reader Extensions not configured - Causes Reader Extensions test to fail
46+
// * Sample JSON Adaptive Form not deployed - Causes JSON AF Rendering test to fail
47+
// * Sample XDP not copied to target file system - Causes GeneratePdfOututTest "For mWindows Machine" rendering test failures
48+
// * Reader Extensions not configured - Causes Reader Extensions (Secure Document) tests to fail
4449
// * OpenOffice not installed - causes GeneratePdf tests to fail
4550
//
46-
// Tests that pass:
47-
// * DataCacheService Tests
48-
// * GeneratePrintedOutput Form Doc tests
49-
// * GeneratePdfOutput Form Doc tests
50-
// * Import Data tests
51-
// * RenderPdfForm Form Doc tests
52-
// * Export Data tests
53-
// * ConvertPdfToXDP tests
51+
// Status of TestContainers support.
52+
// AEM Integration test issues (in addition to those above)::
53+
// * Sample Adaptive Form not deployed - Causes AF Rendering test to fail (should be fixed in latest AEM image)
54+
// * JSAFE not configured - Causes Assembler test to fail (should be fixed in latest AEM image)
55+
// * Sample XDP not deployed - Causes HTML5, PDF and Print rendering tests to fail (should be fixed in latest AEM image)
56+
// * 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.
5458

5559
private static final String SAMPLE_FORM_PDF_NAME = "SampleForm.pdf";
5660
private static final String SAMPLE_FORM_XDP_NAME = "SampleForm.xdp";
@@ -93,6 +97,7 @@ public static String readEntityToString(Response result) {
9397
}
9498
}
9599

100+
@SuppressWarnings("unused")
96101
public static void validatePdfResult(byte[] pdfBytes, String testResultFilename, boolean dynamic, boolean interactive, boolean hasRights)
97102
throws IOException, Exception, PdfException {
98103
if (SAVE_RESULTS == true) {

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import org.junit.jupiter.api.DisplayName;
1313
import org.junit.jupiter.api.Tag;
1414
import org.junit.jupiter.api.Test;
15+
import org.junit.jupiter.api.condition.EnabledIf;
16+
import org.junit.jupiter.api.condition.EnabledOnOs;
17+
import org.junit.jupiter.api.condition.OS;
1518

1619
import com._4point.aem.docservices.rest_services.client.jersey.JerseyRestClient;
1720
import com._4point.aem.docservices.rest_services.client.output.RestServicesOutputServiceAdapter;
@@ -121,7 +124,9 @@ void testGeneratePdfOutput_JustFormIssue15() throws Exception {
121124

122125

123126
@Test
124-
@DisplayName("Test generatePdfOutput() Just Form. From Windows Machine")
127+
@EnabledOnOs(OS.WINDOWS)
128+
@EnabledIf("targetIsLinux")
129+
@DisplayName("Test generatePdfOutput() Just Form with Linux Path. From Windows Machine")
125130
void testGeneratePdfOutput_JustForm() throws Exception {
126131
// Path formPath = Paths.get("/home/aem_user/u000/AEM/Forms/RUNTIME/Invoices/EN/Invoice_GB_PD.xdp");
127132
URL formPath = new URL("file:/home/aem_user/u000/AEM/Forms/RUNTIME/Invoices/EN/Invoice_GB_PD.xdp");
@@ -134,7 +139,9 @@ void testGeneratePdfOutput_JustForm() throws Exception {
134139
}
135140

136141
@Test
137-
@DisplayName("Test generatePdfOutput() Just Form. From Windows Machine")
142+
@EnabledOnOs(OS.WINDOWS)
143+
@EnabledIf("targetIsLinux")
144+
@DisplayName("Test generatePdfOutput() Just Form with Linux ContentRoot. From Windows Machine")
138145
void testGeneratePdfOutput_JustFormContentRoot() throws Exception {
139146
Path contentPath = Paths.get("\\","home", "aem_user", "u000","AEM","Forms","RUNTIME","Invoices","EN");
140147
Path formPath = Paths.get("Invoice_GB_PD.xdp");
@@ -146,6 +153,8 @@ void testGeneratePdfOutput_JustFormContentRoot() throws Exception {
146153

147154
// TestUtils.validatePdfResult(pdfResult.getInlineData(), "GeneratePdfOutput_JustFormDocIssue15.pdf", false, false, false);
148155
}
149-
150-
156+
157+
boolean targetIsLinux() {
158+
return AemInstance.AEM_1.isLinux();
159+
}
151160
}

0 commit comments

Comments
 (0)