Skip to content

Commit 3fe7a39

Browse files
committed
feat: #260 Adding withDebugLogLevel() methods
Signed-off-by: Laurent Broudoux <[email protected]>
1 parent 308d98c commit 3fe7a39

File tree

6 files changed

+57
-4
lines changed

6 files changed

+57
-4
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,18 @@ TestResult testResult = testResultFuture.get();
336336
assertTrue(testResult.isSuccess());
337337
```
338338

339-
In addition, you can use the `getEventMessagesForTestCase()` method to retrieve the events received during the test.
339+
In addition, you can use the `getEventMessagesForTestCase()` method to retrieve the events received during the test.
340+
341+
### Troubleshooting
342+
343+
You can enable debug logs on the Microcks container by setting the debug log level and then retrieving the logs:
344+
345+
```java
346+
MicrocksContainer microcks = new MicrocksContainer("[...]"))
347+
.withDebugLogLevel()
348+
.start();
349+
microcks.getLogs();
350+
```
351+
352+
The same `.withDebugLogLevel()` method is available on also `MicrocksContainersEnsemble` for enabling debug logs
353+
on all contained Microcks containers.

src/main/java/io/github/microcks/testcontainers/MicrocksAsyncMinionContainer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ public MicrocksAsyncMinionContainer(Network network, DockerImageName imageName,
9393
}
9494

9595

96+
/**
97+
* Set the container logging level to DEBUG.
98+
* @return self
99+
*/
100+
public MicrocksAsyncMinionContainer withDebugLogLevel() {
101+
withEnv("QUARKUS_LOG_CONSOLE_LEVEL", "DEBUG");
102+
withEnv("QUARKUS_LOG_CATEGORY__IO_GITHUB_MICROCKS__LEVEL", "DEBUG");
103+
return self();
104+
}
105+
96106
/**
97107
* Connect the MicrocksAsyncMinionContainer to a Kafka server to allow Kafka messages mocking.
98108
* @param connection Connection details to a Kafka broker.

src/main/java/io/github/microcks/testcontainers/MicrocksContainer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ public MicrocksContainer(DockerImageName imageName) {
111111
waitingFor(Wait.forLogMessage(".*Started MicrocksApplication.*", 1));
112112
}
113113

114+
/**
115+
* Set the container logging level to DEBUG.
116+
* @return self
117+
*/
118+
public MicrocksContainer withDebugLogLevel() {
119+
withEnv("LOGGING_LEVEL_IO_GITHUB_MICROCKS", "DEBUG");
120+
return self();
121+
}
122+
114123
/**
115124
* Provide paths to artifacts that will be imported as primary or main ones within the Microcks container
116125
* once it will be started and healthy.

src/main/java/io/github/microcks/testcontainers/MicrocksContainersEnsemble.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public class MicrocksContainersEnsemble implements Startable {
5353
private MicrocksAsyncMinionContainer asyncMinion;
5454
private final MicrocksContainer microcks;
5555

56-
private final Map<String, String> postmanEnvVars = new HashMap();
57-
private final Map<String, String> asyncMinionEnvVars = new HashMap();
58-
private final Map<String, String> microcksEnvVars = new HashMap();
56+
private final Map<String, String> postmanEnvVars = new HashMap<>();
57+
private final Map<String, String> asyncMinionEnvVars = new HashMap<>();
58+
private final Map<String, String> microcksEnvVars = new HashMap<>();
5959

6060
/**
6161
* Build a new MicrocksContainersEnsemble with its base container image name as string. This image must
@@ -100,6 +100,17 @@ public MicrocksContainersEnsemble(Network network, DockerImageName image) {
100100
+ ":" + MicrocksAsyncMinionContainer.MICROCKS_ASYNC_MINION_HTTP_PORT);
101101
}
102102

103+
/**
104+
* Enable debug log level on MicrocksContainersEnsemble containers.
105+
* @return self
106+
*/
107+
public MicrocksContainersEnsemble withDebugLogLevel() {
108+
microcks.withDebugLogLevel();
109+
asyncMinionEnvVars.put("QUARKUS_LOG_CONSOLE_LEVEL", "DEBUG");
110+
asyncMinionEnvVars.put("QUARKUS_LOG_CATEGORY__IO_GITHUB_MICROCKS__LEVEL", "DEBUG");
111+
return this;
112+
}
113+
103114
/**
104115
* Add an environment variable to Postman runtime container.
105116
* @param key The env var name

src/test/java/io/github/microcks/testcontainers/MicrocksContainerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class MicrocksContainerTest {
6262
void testMockingFunctionality() throws Exception {
6363
try (
6464
MicrocksContainer microcks = new MicrocksContainer(IMAGE)
65+
.withDebugLogLevel()
6566
.withSnapshots("microcks-repository.json")
6667
.withMainArtifacts("apipastries-openapi.yaml", "sub dir/weather-forecast-openapi.yaml")
6768
.withMainRemoteArtifacts("https://raw.githubusercontent.com/microcks/microcks/master/samples/APIPastry-openapi.yaml")
@@ -73,6 +74,9 @@ void testMockingFunctionality() throws Exception {
7374

7475
testMockEndpoints(microcks);
7576
testMicrocksMockingFunctionality(microcks);
77+
78+
// Check that debug logs are present.
79+
assertTrue(microcks.getLogs().contains("DEBUG 1"));
7680
}
7781
}
7882

src/test/java/io/github/microcks/testcontainers/MicrocksContainersEnsembleTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,18 @@ void testAsyncFeatureSetup() {
156156
void testAsyncFeatureMockingFunctionality() throws Exception {
157157
try (
158158
MicrocksContainersEnsemble ensemble = new MicrocksContainersEnsemble(IMAGE)
159+
.withDebugLogLevel()
159160
.withMainArtifacts("pastry-orders-asyncapi.yml")
160161
.withAsyncFeature();
161162
) {
162163
ensemble.start();
163164
testMicrocksConfigRetrieval(ensemble.getMicrocksContainer().getHttpEndpoint());
164165

165166
testMicrocksAsyncMockingFunctionality(ensemble);
167+
168+
// Check that debug logs are present.
169+
assertTrue(ensemble.getMicrocksContainer().getLogs().contains("DEBUG 1"));
170+
assertTrue(ensemble.getAsyncMinionContainer().getLogs().contains("DEBUG ["));
166171
}
167172
}
168173

0 commit comments

Comments
 (0)