Skip to content

Commit 045cdde

Browse files
committed
[XEN-3155] add logging test for new configuration
1 parent c3a59e6 commit 045cdde

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

2repository/src/integrationTest/java/eu/xenit/docker/alfresco/test/LoggingTests.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package eu.xenit.docker.alfresco.test;
22

33
import java.io.IOException;
4+
import java.util.HashMap;
45
import java.util.HashSet;
56
import java.util.List;
67
import java.util.Map;
@@ -63,15 +64,17 @@ private boolean validateApplicationJsonLog(Stream<JsonNode> jsonNodes) {
6364
.allMatch(logLine -> REQ_APPLICATION_LOGGING_FIELDS.stream().allMatch(logLine::has));
6465
}
6566

66-
private void setupAlfrescoTestContainer(GenericContainer<?> alfContainer, boolean jsonLogging) {
67-
alfContainer
68-
.withExposedPorts(8080)
69-
.withEnv(Map.of(
67+
private void setupAlfrescoTestContainer(GenericContainer<?> alfContainer, boolean jsonLogging, Map<String, String> env) {
68+
Map<String, String> baseEnv = new HashMap<>(Map.of(
7069
"ACCESS_LOGGING", "false",
7170
"GLOBAL_legacy.transform.service.enabled", "false",
7271
"GLOBAL_local.transform.service.enabled", "false",
7372
"JSON_LOGGING", String.valueOf(jsonLogging)
74-
));
73+
));
74+
baseEnv.putAll(env);
75+
alfContainer
76+
.withExposedPorts(8080)
77+
.withEnv(baseEnv);
7578
}
7679

7780
private static DockerImageName getAlfrescoImageName() {
@@ -89,10 +92,16 @@ private boolean isJsonLogs(String logs) {
8992

9093
}
9194

95+
private boolean containsSpringDebugLog(String logLines) {
96+
return getJsonLogs(logLines).anyMatch(line -> {
97+
return line.get("severity").asText().equals("DEBUG") && line.get("loggerName").asText().contains("org.springframework");
98+
});
99+
}
100+
92101
@Test
93102
public void testNonJsonLogging() {
94103
try (GenericContainer<?> alfContainer = new GenericContainer<>(getAlfrescoImageName())) {
95-
setupAlfrescoTestContainer(alfContainer, false);
104+
setupAlfrescoTestContainer(alfContainer, false, Map.of());
96105
alfContainer.start();
97106

98107
// Let the logs accumulate
@@ -107,7 +116,7 @@ public void testNonJsonLogging() {
107116
@Test
108117
public void testJsonLogging() {
109118
try (GenericContainer<?> alfContainer = new GenericContainer<>(getAlfrescoImageName())) {
110-
setupAlfrescoTestContainer(alfContainer, true);
119+
setupAlfrescoTestContainer(alfContainer, true, Map.of());
111120
alfContainer.start();
112121

113122
// Let the logs accumulate
@@ -121,4 +130,21 @@ public void testJsonLogging() {
121130
Assert.assertTrue(validateApplicationJsonLog(jsonNodes));
122131
}
123132
}
133+
134+
@Test
135+
public void testLogLevelConfiguration() {
136+
try (GenericContainer<?> alfContainer = new GenericContainer<>(getAlfrescoImageName())) {
137+
// Start container with debug Spring, use json logging for easier parsing
138+
setupAlfrescoTestContainer(alfContainer, true, Map.of("LOG_LEVEL_org_springframework", "debug"));
139+
alfContainer.start();
140+
141+
// Accumulate some logs (make sure we get enough to catch some Spring logs)
142+
Awaitility.await().until(() -> alfContainer.getLogs().length() > 100);
143+
144+
String logs = alfContainer.getLogs();
145+
146+
// Now find log entries from Spring marked as Debug
147+
Assert.assertTrue(containsSpringDebugLog(logs));
148+
}
149+
}
124150
}

0 commit comments

Comments
 (0)