This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 24e612c2462 Fixes #8640. Add route diagram dumping to
CamelQuarkusTestSupport
24e612c2462 is described below
commit 24e612c24628869bdde7154a0a304ce514e45a5d
Author: James Netherton <[email protected]>
AuthorDate: Thu Dec 3 16:46:15 2026 +0000
Fixes #8640. Add route diagram dumping to CamelQuarkusTestSupport
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../testing/camel-quarkus-test-support.adoc | 43 ++++++++++
.../user-guide/testing/camel-quarkus-test.adoc | 3 +
test-framework/camel-quarkus-junit/pom.xml | 10 +++
.../quarkus/test/CamelQuarkusTestSupport.java | 8 ++
.../test/junit6/patterns/DumpRouteTest.java | 98 ++++++++++++++++++++++
5 files changed, 162 insertions(+)
diff --git
a/docs/modules/ROOT/pages/user-guide/testing/camel-quarkus-test-support.adoc
b/docs/modules/ROOT/pages/user-guide/testing/camel-quarkus-test-support.adoc
index 588701e7c81..0d93bdaedbf 100644
--- a/docs/modules/ROOT/pages/user-guide/testing/camel-quarkus-test-support.adoc
+++ b/docs/modules/ROOT/pages/user-guide/testing/camel-quarkus-test-support.adoc
@@ -304,6 +304,49 @@ Advice modifications are automatically cleaned up between
test methods to preven
* Advice from one test doesn't affect subsequent tests
* Tests remain independent and can run in any order
+== Route dumps and route diagrams
+
+Override `getDumpRoute` to write the routes to files after each test method,
including the routes and advice of the test class.
+
+[cols="1,2,2"]
+|===
+| Format | Default folder | Required dependency
+
+| `png`
+| `target/camel-route-diagram`
+| `camel-quarkus-diagram`
+
+| `xml`
+| `target/camel-route-dump`
+| `camel-quarkus-xml-io-dsl`
+
+| `yaml`
+| `target/camel-route-dump`
+| `camel-quarkus-yaml-io`
+|===
+
+For example, to write PNG route diagrams:
+
+[source,java]
+----
+@QuarkusTest
+class RouteDiagramTest extends CamelQuarkusTestSupport {
+ @Override
+ public String getDumpRoute() {
+ return "png";
+ }
+
+ @Test
+ void dumpRouteDiagrams() {
+ }
+}
+----
+
+The `CamelTestRouteDump` system property sets the format for all tests, and
takes precedence over `getDumpRoute`.
+The `CamelTestRouteDumpDir` system property changes the folder.
+
+NOTE: Route diagrams are overwritten by each test method that dumps the same
routes.
+
== Limitations
=== Test lifecycle methods from `CamelTestSupport`
diff --git a/docs/modules/ROOT/pages/user-guide/testing/camel-quarkus-test.adoc
b/docs/modules/ROOT/pages/user-guide/testing/camel-quarkus-test.adoc
index 1d18b9c4c0a..84c80a96ef0 100644
--- a/docs/modules/ROOT/pages/user-guide/testing/camel-quarkus-test.adoc
+++ b/docs/modules/ROOT/pages/user-guide/testing/camel-quarkus-test.adoc
@@ -218,6 +218,9 @@ class GreetingTest {
| `isDumpRouteCoverage()`
| `dumpRouteCoverage`
+| `getDumpRoute()`
+| `dumpRoute` for `xml` and `yaml`, or `dumpRouteDiagramFolder` for `png`
+
| `doBeforeEach()`, `doAfterEach()`, `doAfterConstruct()`, `doAfterAll()`
| JUnit `@BeforeEach`, `@AfterEach`, `@BeforeAll`, `@AfterAll`
|===
diff --git a/test-framework/camel-quarkus-junit/pom.xml
b/test-framework/camel-quarkus-junit/pom.xml
index 18364e1f9ed..b893ef96b65 100644
--- a/test-framework/camel-quarkus-junit/pom.xml
+++ b/test-framework/camel-quarkus-junit/pom.xml
@@ -62,11 +62,21 @@
<artifactId>camel-quarkus-bean</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-diagram</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-management</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-xml-io-dsl</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
diff --git
a/test-framework/camel-quarkus-junit/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTestSupport.java
b/test-framework/camel-quarkus-junit/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTestSupport.java
index a920a486937..5eaf6e5958e 100644
---
a/test-framework/camel-quarkus-junit/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTestSupport.java
+++
b/test-framework/camel-quarkus-junit/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTestSupport.java
@@ -50,8 +50,10 @@ import org.apache.camel.test.junit6.CamelTestSupport;
import org.apache.camel.test.junit6.ContextManagerFactory;
import org.apache.camel.test.junit6.TestExecutionConfiguration;
import org.apache.camel.test.junit6.TestSupport;
+import org.apache.camel.test.junit6.util.CamelContextTestHelper;
import org.apache.camel.test.junit6.util.ExtensionHelper;
import org.apache.camel.test.junit6.util.RouteCoverageDumperExtension;
+import org.apache.camel.test.junit6.util.RouteDumperExtension;
import org.apache.camel.util.StopWatch;
import org.apache.camel.util.function.ThrowingConsumer;
import org.eclipse.microprofile.config.ConfigProvider;
@@ -282,6 +284,12 @@ public class CamelQuarkusTestSupport extends
AbstractTestSupport
ExtensionHelper.testEndFooter(getClass(), currentTestName, time);
}
+ // Dumped before the test routes are removed and advice is reverted,
so that the output includes them
+ String dumpRoute = CamelContextTestHelper.getRouteDump(getDumpRoute());
+ if (dumpRoute != null && !"false".equals(dumpRoute)) {
+ new RouteDumperExtension((ModelCamelContext)
context).dumpRoute(getClass(), currentTestName, dumpRoute);
+ }
+
if (testConfigurationBuilder.isCreateCamelContextPerClass()) {
// will tear down test specially in afterAll callback
return;
diff --git
a/test-framework/camel-quarkus-junit/src/test/java/org/apache/camel/quarkus/test/junit6/patterns/DumpRouteTest.java
b/test-framework/camel-quarkus-junit/src/test/java/org/apache/camel/quarkus/test/junit6/patterns/DumpRouteTest.java
new file mode 100644
index 00000000000..8efcf9cc188
--- /dev/null
+++
b/test-framework/camel-quarkus-junit/src/test/java/org/apache/camel/quarkus/test/junit6/patterns/DumpRouteTest.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.test.junit6.patterns;
+
+import java.io.File;
+import java.nio.file.Path;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.quarkus.test.CamelQuarkusTestSupport;
+import org.apache.camel.util.FileUtil;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import static org.apache.camel.test.junit6.TestSupport.assertFileExists;
+import static org.apache.camel.test.junit6.TestSupport.assertFileNotExists;
+
+@QuarkusTest
+@TestProfile(DumpRouteTest.class)
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+public class DumpRouteTest extends CamelQuarkusTestSupport {
+ private static final String DIAGRAM_FOLDER = "target/camel-route-diagram";
+ private static final String DUMP_FOLDER = "target/camel-route-dump";
+ private static final String ROUTE_ID = "dump-route";
+
+ private static String contextName;
+
+ private String format;
+
+ @Override
+ public String getDumpRoute() {
+ return format;
+ }
+
+ @BeforeAll
+ static void deleteFilesOfPreviousRuns() {
+ FileUtil.removeDir(new File(DIAGRAM_FOLDER));
+ FileUtil.removeDir(new File(DUMP_FOLDER));
+ }
+
+ // Runs before the diagram dump, to verify that the file name of the XML
dump is not reused for the diagrams
+ @Test
+ @Order(1)
+ void xml() {
+ format = "xml";
+ }
+
+ @Test
+ @Order(2)
+ void png() {
+ format = "png";
+ contextName = context.getName();
+ }
+
+ @Test
+ @Order(3)
+ void disabled() {
+ format = "false";
+ }
+
+ @AfterAll
+ static void checkFilesCreatedAfterTests() {
+ assertFileExists(Path.of(DUMP_FOLDER, "DumpRouteTest-xml.xml"));
+ assertFileExists(Path.of(DIAGRAM_FOLDER, ROUTE_ID + ".png"));
+ assertFileExists(Path.of(DIAGRAM_FOLDER, contextName +
"-topology.png"));
+ assertFileNotExists(Path.of(DUMP_FOLDER,
"DumpRouteTest-disabled.false"));
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:dumpRoute").routeId(ROUTE_ID).to("mock:dumpRoute");
+ }
+ };
+ }
+}