|
15 | 15 | import org.testcontainers.containers.GenericContainer; |
16 | 16 | import org.testcontainers.utility.DockerImageName; |
17 | 17 |
|
| 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 | + */ |
18 | 25 | 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.., |
20 | 27 |
|
21 | 28 | private static final String LOCALHOST = "localhost"; |
22 | 29 |
|
23 | 30 | // These tests require an AEM container image with AEM forms installed. Since AEM is proprietary, it is not possible to obtain this |
24 | 31 | // through public images. By default, this uses a private image hosted in the 4PointSolutions-PS GitHub organization. If you are not |
25 | 32 | // part of that prg, you will have to supply your own image. |
26 | 33 | private static final String AEM_IMAGE_NAME = "ghcr.io/4pointsolutions-ps/aem:aem65sp21"; |
| 34 | + private final TestUtils.AemTargetType targetType; |
27 | 35 | private final GenericContainer<?> aemContainer; |
28 | 36 | private final AtomicBoolean preparedForTests = new AtomicBoolean(false); |
29 | 37 |
|
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)) |
32 | 41 | .withReuse(true) |
33 | 42 | .withExposedPorts(4502) |
34 | 43 | : null); |
35 | 44 | } |
36 | 45 |
|
37 | | - private AemInstance(GenericContainer<?> aemContainer) { |
| 46 | + private AemInstance(TestUtils.AemTargetType targetType, GenericContainer<?> aemContainer) { |
| 47 | + this.targetType = targetType; |
38 | 48 | this.aemContainer = aemContainer; |
39 | 49 | if (aemContainer != null) { |
40 | 50 | aemContainer.start(); |
41 | | - |
42 | 51 | } |
43 | 52 | } |
44 | 53 |
|
@@ -86,14 +95,37 @@ public static void deploySampleFiles(Integer mappedPort) { |
86 | 95 | System.out.println("Sample files deployed."); |
87 | 96 | } |
88 | 97 |
|
| 98 | + /** |
| 99 | + * Host name where AEM is running |
| 100 | + * |
| 101 | + * @return |
| 102 | + */ |
89 | 103 | 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 | + }; |
91 | 108 | } |
92 | 109 |
|
| 110 | + /** |
| 111 | + * Port where AEM is running. |
| 112 | + * |
| 113 | + * @return |
| 114 | + */ |
93 | 115 | 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 | + }; |
95 | 120 | } |
96 | 121 |
|
| 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 | + } |
97 | 129 | /** |
98 | 130 | * Is AEM running locally or remotely? |
99 | 131 | * |
|
0 commit comments