This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new d3a4c40c63b camel-test - Add option to dump routes (#16674)
d3a4c40c63b is described below
commit d3a4c40c63be6527483748e9b1b22962cbec5350
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Dec 31 14:18:19 2024 +0100
camel-test - Add option to dump routes (#16674)
* CAMEL-21274: camel-test - Add option to dump routes
---
.../src/main/docs/camel-report-maven-plugin.adoc | 2 +-
.../camel/test/junit5/AbstractTestSupport.java | 16 +++-
.../test/junit5/CamelContextConfiguration.java | 1 -
.../camel/test/junit5/CamelContextManager.java | 11 ++-
.../apache/camel/test/junit5/CamelTestSupport.java | 15 ++--
.../camel/test/junit5/CommonTestSupport.java | 1 -
.../camel/test/junit5/ConfigurableContext.java | 6 +-
.../apache/camel/test/junit5/ConfigurableTest.java | 6 +-
.../camel/test/junit5/ContextManagerExtension.java | 5 +-
.../camel/test/junit5/ContextManagerFactory.java | 2 +-
.../apache/camel/test/junit5/DebugBreakpoint.java | 1 -
.../camel/test/junit5/ExchangeTestSupport.java | 1 +
.../camel/test/junit5/JunitPropertiesSource.java | 2 +-
.../test/junit5/LegacyCamelContextManager.java | 15 +++-
.../test/junit5/TestExecutionConfiguration.java | 41 ++++++++-
.../camel/test/junit5/TestLoggerExtension.java | 5 +-
.../camel/test/junit5/TestNameExtension.java | 8 +-
.../camel/test/junit5/ThrottlingExecutor.java | 11 +--
.../test/junit5/TransientCamelContextManager.java | 15 +++-
.../test/junit5/util/CamelContextTestHelper.java | 37 +++++++-
.../util}/CamelRouteCoverageDumper.java | 2 +-
.../camel/test/junit5/util/ExtensionHelper.java | 6 +-
.../junit5/util/RouteCoverageDumperExtension.java | 4 +-
.../test/junit5/util/RouteDumperExtension.java | 50 +++++++++++
.../camel-test/camel-test-main-junit5/pom.xml | 7 +-
.../camel/test/main/junit5/CamelMainExtension.java | 46 +++++++++-
.../camel/test/main/junit5/CamelMainTest.java | 11 +++
.../test/main/junit5/annotation/DumpRouteTest.java | 65 ++++++++++++++
.../src/main/docs/test-spring-junit5.adoc | 5 +-
.../spring/junit5/CamelAnnotationsHandler.java | 99 +++++++++++++++++++---
.../junit5/CamelSpringBootExecutionListener.java | 10 ++-
.../test/spring/junit5/CamelSpringBootTest.java | 14 +--
.../junit5/CamelSpringTestContextLoader.java | 3 +-
...melSpringBootTest.java => EnableRouteDump.java} | 30 ++++---
.../test/spring/junit5/RouteDumpEventNotifier.java | 66 +++++++++++++++
...lSpringRouteProcessorDumpRouteCoverageTest.java | 1 +
...=> CamelSpringRouteProcessorDumpRouteTest.java} | 18 ++--
.../camel/impl/DefaultDumpRoutesStrategy.java | 24 +++---
38 files changed, 530 insertions(+), 132 deletions(-)
diff --git
a/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc
b/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc
index fd3202a8532..12a97453e5f 100644
---
a/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc
+++
b/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc
@@ -265,7 +265,7 @@ annotation to the test class if you are testing using
`camel-test-spring-junit5`
[source,java]
----
-@RunWith(CamelSpringBootRunner.class)
+@CamelSpringBootTest
@SpringBootTest(classes = SampleCamelApplication.class)
@EnableRouteCoverage
public class FooApplicationTest {
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/AbstractTestSupport.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/AbstractTestSupport.java
index d0687dba8e7..bc7dc2a391d 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/AbstractTestSupport.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/AbstractTestSupport.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import java.util.Properties;
@@ -101,6 +100,21 @@ public abstract class AbstractTestSupport implements
CommonTestSupport {
return testConfigurationBuilder.isDumpRouteCoverage();
}
+ /**
+ * Whether to dump route as XML or YAML
+ * <p/>
+ * This allows tooling or manual inspection of the tested routes.
+ * <p/>
+ * You can also turn on route dump globally via setting JVM system
property <tt>CamelTestRouteDump=xml</tt>.
+ *
+ * @deprecated Use the accessors from {@link #testConfiguration()} method
+ * @return <tt>xml</tt> or <tt>yaml</tt> to write route dump to the log
+ */
+ @Deprecated(since = "4.10.0")
+ public String getDumpRoute() {
+ return testConfigurationBuilder.getDumpRoute();
+ }
+
/**
* Override when using <a
href="http://camel.apache.org/advicewith.html">advice with</a> and return
<tt>true</tt>.
* This helps to know advice with is to be used, and {@link CamelContext}
will not be started before the advice with
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextConfiguration.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextConfiguration.java
index c5a202492ab..d80da3554b8 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextConfiguration.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextConfiguration.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import java.util.HashMap;
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextManager.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextManager.java
index d20a6f7b318..dfb1cf32d03 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextManager.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextManager.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import org.apache.camel.ConsumerTemplate;
@@ -117,11 +116,11 @@ public interface CamelContextManager {
/**
* Dumps the route coverage information
- *
- * @param clazz
- * @param currentTestName
- * @param time
- * @throws Exception
*/
void dumpRouteCoverage(Class<?> clazz, String currentTestName, long time)
throws Exception;
+
+ /**
+ * Dumps the route
+ */
+ void dumpRoute(Class<?> clazz, String currentTestName, String format)
throws Exception;
}
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
index 88966d5d193..6b93ab1a550 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
@@ -93,10 +93,15 @@ public abstract class CamelTestSupport extends
AbstractTestSupport
@Override
public void configureTest(TestExecutionConfiguration
testExecutionConfiguration) {
- testExecutionConfiguration.withJMX(useJmx())
+ boolean coverage =
CamelContextTestHelper.isRouteCoverageEnabled(isDumpRouteCoverage());
+ String dump = CamelContextTestHelper.getRouteDump(getDumpRoute());
+ boolean jmx = coverage || useJmx(); // route coverage requires JMX
+
+ testExecutionConfiguration.withJMX(jmx)
.withUseRouteBuilder(isUseRouteBuilder())
.withUseAdviceWith(isUseAdviceWith())
- .withDumpRouteCoverage(isDumpRouteCoverage());
+ .withDumpRouteCoverage(coverage)
+ .withDumpRoute(dump);
}
@Override
@@ -224,16 +229,16 @@ public abstract class CamelTestSupport extends
AbstractTestSupport
if (contextManager != null) {
contextManager.dumpRouteCoverage(getClass(),
testInfo.getDisplayName(), time);
+ String dump = CamelContextTestHelper.getRouteDump(getDumpRoute());
+ contextManager.dumpRoute(getClass(), testInfo.getDisplayName(),
dump);
} else {
LOG.warn(
"A context manager is required to dump the route coverage
for the Camel context but it's not available (it's null). "
- +
- "It's likely that the test is misconfigured!");
+ + "It's likely that the test is misconfigured!");
}
doPostTearDown();
cleanupResources();
-
}
/**
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CommonTestSupport.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CommonTestSupport.java
index d9f0a1e7530..498198492e4 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CommonTestSupport.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CommonTestSupport.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
/**
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ConfigurableContext.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ConfigurableContext.java
index 85f82066dd0..1af634a07b9 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ConfigurableContext.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ConfigurableContext.java
@@ -14,24 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
/**
* Indicates that the context used by the test is configurable
*/
public interface ConfigurableContext {
+
/**
* Configures the context used for the test execution
- *
- * @param camelContextConfiguration
*/
void configureContext(CamelContextConfiguration camelContextConfiguration);
/**
* Gets the {@link CamelContextConfiguration} for the test
- *
- * @return the camel context configuration
*/
CamelContextConfiguration camelContextConfiguration();
}
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ConfigurableTest.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ConfigurableTest.java
index d1885edcc8b..714cde35877 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ConfigurableTest.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ConfigurableTest.java
@@ -14,24 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
/**
* Indicates that the test is configurable
*/
public interface ConfigurableTest {
+
/**
* Configures the test execution
- *
- * @param testExecutionConfiguration
*/
void configureTest(TestExecutionConfiguration testExecutionConfiguration);
/**
* Gets the {@link TestExecutionConfiguration} test execution
configuration instance for the test
- *
- * @return the configuration instance for the test
*/
TestExecutionConfiguration testConfiguration();
}
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ContextManagerExtension.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ContextManagerExtension.java
index de46f3c3120..77ce67c17b4 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ContextManagerExtension.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ContextManagerExtension.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import org.apache.camel.impl.DefaultCamelContext;
@@ -28,8 +27,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class ContextManagerExtension
- implements BeforeEachCallback, AfterEachCallback, AfterAllCallback,
- BeforeAllCallback {
+ implements BeforeEachCallback, AfterEachCallback, AfterAllCallback,
BeforeAllCallback {
+
private static final Logger LOG =
LoggerFactory.getLogger(ContextManagerExtension.class);
private final TestExecutionConfiguration testConfigurationBuilder;
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ContextManagerFactory.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ContextManagerFactory.java
index 8d22eef2894..1419c425bd5 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ContextManagerFactory.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ContextManagerFactory.java
@@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
/**
* A factory class for creating context managers
*/
public class ContextManagerFactory {
+
/**
* Callback types
*/
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/DebugBreakpoint.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/DebugBreakpoint.java
index d32fa0e73d7..803d5a18737 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/DebugBreakpoint.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/DebugBreakpoint.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import org.apache.camel.Exchange;
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ExchangeTestSupport.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ExchangeTestSupport.java
index ecf85e5d42d..66c3878c4e4 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ExchangeTestSupport.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ExchangeTestSupport.java
@@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
* A base class for a test which requires a {@link
org.apache.camel.CamelContext} and a populated {@link Exchange}
*/
public abstract class ExchangeTestSupport extends CamelTestSupport {
+
protected Exchange exchange;
/**
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/JunitPropertiesSource.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/JunitPropertiesSource.java
index e52c4637891..045d9e43803 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/JunitPropertiesSource.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/JunitPropertiesSource.java
@@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import org.apache.camel.spi.PropertiesSource;
import org.junit.jupiter.api.extension.ExtensionContext;
class JunitPropertiesSource implements PropertiesSource {
+
private final ExtensionContext.Store globalStore;
JunitPropertiesSource(ExtensionContext.Store globalStore) {
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/LegacyCamelContextManager.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/LegacyCamelContextManager.java
index a2502b95479..c1d06cfa661 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/LegacyCamelContextManager.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/LegacyCamelContextManager.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import java.lang.reflect.Method;
@@ -34,6 +33,7 @@ import org.apache.camel.support.PluginHelper;
import org.apache.camel.test.junit5.util.CamelContextTestHelper;
import org.apache.camel.test.junit5.util.ExtensionHelper;
import org.apache.camel.test.junit5.util.RouteCoverageDumperExtension;
+import org.apache.camel.test.junit5.util.RouteDumperExtension;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,6 +45,7 @@ import static
org.apache.camel.test.junit5.TestSupport.isCamelDebugPresent;
* Camel 4.7.0
*/
public class LegacyCamelContextManager implements CamelContextManager {
+
private static final Logger LOG =
LoggerFactory.getLogger(LegacyCamelContextManager.class);
private static final ThreadLocal<LegacyCamelContextManager> INSTANCE = new
ThreadLocal<>();
@@ -369,8 +370,16 @@ public class LegacyCamelContextManager implements
CamelContextManager {
@Override
public void dumpRouteCoverage(Class<?> clazz, String currentTestName, long
time) throws Exception {
if (testConfigurationBuilder.isRouteCoverageEnabled()) {
- final RouteCoverageDumperExtension routeCoverageWrapper = new
RouteCoverageDumperExtension(context);
- routeCoverageWrapper.dumpRouteCoverage(clazz, currentTestName,
time);
+ RouteCoverageDumperExtension wrapper = new
RouteCoverageDumperExtension(context);
+ wrapper.dumpRouteCoverage(clazz, currentTestName, time);
+ }
+ }
+
+ @Override
+ public void dumpRoute(Class<?> clazz, String currentTestName, String
format) throws Exception {
+ if (format != null && !"false".equals(format)) {
+ RouteDumperExtension wrapper = new RouteDumperExtension(context);
+ wrapper.dumpRoute(clazz, currentTestName, format);
}
}
}
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestExecutionConfiguration.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestExecutionConfiguration.java
index 3c0b9e55ce0..2c8b7411548 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestExecutionConfiguration.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestExecutionConfiguration.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import org.apache.camel.CamelContext;
@@ -25,8 +24,10 @@ import
org.apache.camel.test.junit5.util.CamelContextTestHelper;
* execution environment.
*/
public class TestExecutionConfiguration {
+
private boolean jmx;
private boolean dumpRouteCoverage = false;
+ private String dumpRoute;
private boolean useAdviceWith = false;
private boolean createCamelContextPerClass = false;
private boolean useRouteBuilder = true;
@@ -55,6 +56,42 @@ public class TestExecutionConfiguration {
return this;
}
+ public String getDumpRoute() {
+ return dumpRoute;
+ }
+
+ /**
+ * Whether to dump the routes loaded into Camel for each test (dumped into
files in target/camel-route-dump).
+ * <p/>
+ * The routes can either be dumped into XML or YAML format.
+ * <p/>
+ * This allows tooling or manual inspection of the routes.
+ * <p/>
+ * You can also turn on route dump globally via setting JVM system
property <tt>CamelTestRouteDump=xml</tt>.
+ *
+ * @param dumpRoute <tt>xml</tt> or <tt>yaml</tt> format. The dumped
routes are stored in
+ * <tt>target/camel-route-dump</tt> directory after the
test has finished.
+ */
+ public TestExecutionConfiguration withDumpRoute(String dumpRoute) {
+ this.dumpRoute = dumpRoute;
+ return this;
+ }
+
+ /**
+ * Whether route dump is enabled
+ *
+ * @return true if enabled or false otherwise
+ */
+ public boolean isRouteDumpEnabled() {
+ String dump = CamelContextTestHelper.getRouteDump(getDumpRoute());
+ return dump == null || dump.isBlank();
+ }
+
+ /**
+ * Whether route coverage is enabled
+ *
+ * @return true if enabled or false otherwise
+ */
public boolean isDumpRouteCoverage() {
return dumpRouteCoverage;
}
@@ -87,8 +124,6 @@ public class TestExecutionConfiguration {
/**
* Whether to use advice with
- *
- * @return
*/
public boolean isUseAdviceWith() {
return useAdviceWith;
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestLoggerExtension.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestLoggerExtension.java
index 9a8332b45d5..b66f2228c95 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestLoggerExtension.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestLoggerExtension.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import java.lang.reflect.Method;
@@ -31,8 +30,8 @@ import static
org.apache.camel.test.junit5.util.ExtensionHelper.testEndFooter;
import static
org.apache.camel.test.junit5.util.ExtensionHelper.testStartHeader;
public class TestLoggerExtension
- implements BeforeEachCallback, AfterEachCallback,
BeforeTestExecutionCallback,
- AfterTestExecutionCallback {
+ implements BeforeEachCallback, AfterEachCallback,
BeforeTestExecutionCallback, AfterTestExecutionCallback {
+
private static final String START_TIME = "start time";
private String currentTestName;
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestNameExtension.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestNameExtension.java
index e7f62e73960..66c3129dbbc 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestNameExtension.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestNameExtension.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import org.junit.jupiter.api.extension.AfterEachCallback;
@@ -27,9 +26,8 @@ import org.junit.jupiter.api.extension.ExtensionContext;
* Helper utility to get the test name for legacy test. Do not use. Prefer to
use JUnit's TestInfo whenever possible.
*/
public class TestNameExtension
- implements BeforeEachCallback, AfterEachCallback,
BeforeTestExecutionCallback,
- AfterTestExecutionCallback {
- private static final String START_TIME = "start time";
+ implements BeforeEachCallback, AfterEachCallback,
BeforeTestExecutionCallback, AfterTestExecutionCallback {
+
private String currentTestName;
@Override
@@ -54,8 +52,6 @@ public class TestNameExtension
/**
* Ges the current test name
- *
- * @return the current test name
*/
public String getCurrentTestName() {
return currentTestName;
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ThrottlingExecutor.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ThrottlingExecutor.java
index 1afee21ee81..12ab40ecf29 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ThrottlingExecutor.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ThrottlingExecutor.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import java.util.ArrayList;
@@ -32,7 +31,6 @@ public final class ThrottlingExecutor {
private TimeUnit timeUnit;
private ThrottlingExecutor() {
-
}
public static ThrottlingExecutor slowly() {
@@ -41,32 +39,27 @@ public final class ThrottlingExecutor {
public ThrottlingExecutor repeat(int repetitions) {
this.repetitions = repetitions;
-
return this;
}
public ThrottlingExecutor beforeWait() throws InterruptedException {
Thread.sleep(timeUnit.toMillis(awaiting));
-
return this;
}
public ThrottlingExecutor awaiting(long awaiting, TimeUnit timeUnit) {
this.awaiting = awaiting;
this.timeUnit = timeUnit;
-
return this;
}
public ThrottlingExecutor beforeEach(IntConsumer beforeTask) {
beforeTasks.add(beforeTask);
-
return this;
}
public ThrottlingExecutor afterEach(IntConsumer afterTask) {
afterTasks.add(afterTask);
-
return this;
}
@@ -79,11 +72,9 @@ public final class ThrottlingExecutor {
public void execute() throws InterruptedException {
for (int i = 0; i < repetitions; i++) {
runTasks(beforeTasks, i);
-
Thread.sleep(timeUnit.toMillis(awaiting));
-
runTasks(afterTasks, i);
}
-
}
+
}
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TransientCamelContextManager.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TransientCamelContextManager.java
index 88661e778bb..c63cbd241b5 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TransientCamelContextManager.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TransientCamelContextManager.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5;
import java.lang.reflect.Method;
@@ -32,6 +31,7 @@ import org.apache.camel.support.PluginHelper;
import org.apache.camel.test.junit5.util.CamelContextTestHelper;
import org.apache.camel.test.junit5.util.ExtensionHelper;
import org.apache.camel.test.junit5.util.RouteCoverageDumperExtension;
+import org.apache.camel.test.junit5.util.RouteDumperExtension;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
import static org.apache.camel.test.junit5.TestSupport.isCamelDebugPresent;
public class TransientCamelContextManager implements CamelContextManager {
+
private static final Logger LOG =
LoggerFactory.getLogger(TransientCamelContextManager.class);
private final TestExecutionConfiguration testConfigurationBuilder;
@@ -281,8 +282,16 @@ public class TransientCamelContextManager implements
CamelContextManager {
@Override
public void dumpRouteCoverage(Class<?> clazz, String currentTestName, long
time) throws Exception {
if (testConfigurationBuilder.isRouteCoverageEnabled()) {
- final RouteCoverageDumperExtension routeCoverageWrapper = new
RouteCoverageDumperExtension(context);
- routeCoverageWrapper.dumpRouteCoverage(clazz, currentTestName,
time);
+ RouteCoverageDumperExtension wrapper = new
RouteCoverageDumperExtension(context);
+ wrapper.dumpRouteCoverage(clazz, currentTestName, time);
+ }
+ }
+
+ @Override
+ public void dumpRoute(Class<?> clazz, String currentTestName, String
format) throws Exception {
+ if (format != null && !"false".equals(format)) {
+ RouteDumperExtension wrapper = new RouteDumperExtension(context);
+ wrapper.dumpRoute(clazz, currentTestName, format);
}
}
}
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java
index 63fe6aff32a..db387bb98a4 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5.util;
import java.util.Map;
@@ -53,6 +52,11 @@ public final class CamelContextTestHelper {
*/
public static final String ROUTE_COVERAGE_ENABLED =
"CamelTestRouteCoverage";
+ /**
+ * JVM system property which can be set to true to turn on dumping routes
as xml or yaml
+ */
+ public static final String ROUTE_DUMP_ENABLED = "CamelTestRouteDump";
+
private static final Logger LOG =
LoggerFactory.getLogger(CamelContextTestHelper.class);
public static CamelContext createCamelContext(Registry registry) throws
Exception {
@@ -246,6 +250,35 @@ public final class CamelContextTestHelper {
}
public static boolean isRouteCoverageEnabled(boolean legacyDumpCoverage) {
- return Boolean.parseBoolean(System.getProperty(ROUTE_COVERAGE_ENABLED,
"false")) || legacyDumpCoverage;
+ // JVM system property take precedence
+ String p = System.getProperty(ROUTE_COVERAGE_ENABLED);
+ if (p != null) {
+ p = p.trim().toLowerCase();
+ boolean valid = "true".equals(p) || "false".equals(p);
+ if (!valid) {
+ throw new IllegalArgumentException("RouteCoverage must be:
true or false");
+ }
+ return Boolean.parseBoolean(p);
+ }
+ return legacyDumpCoverage;
+ }
+
+ public static String getRouteDump(String legacyDumpRoute) {
+ // JVM system property take precedence
+ String p = System.getProperty(ROUTE_DUMP_ENABLED);
+ if (p == null || p.isBlank()) {
+ p = legacyDumpRoute;
+ }
+ if (p != null) {
+ p = p.trim().toLowerCase();
+ if ("true".equals(p)) {
+ p = "xml"; // xml is default
+ }
+ boolean valid = "xml".equals(p) || "yaml".equals(p) ||
"false".equals(p);
+ if (!valid) {
+ throw new IllegalArgumentException("RouteDump must be: xml,
yaml, true, or false");
+ }
+ }
+ return p;
}
}
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/CamelRouteCoverageDumper.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelRouteCoverageDumper.java
similarity index 99%
rename from
components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/CamelRouteCoverageDumper.java
rename to
components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelRouteCoverageDumper.java
index e2e1aec49c3..1f458664f6e 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/CamelRouteCoverageDumper.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelRouteCoverageDumper.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.test;
+package org.apache.camel.test.junit5.util;
import java.io.ByteArrayInputStream;
import java.io.File;
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
index 4da9e782f44..a6f523ca664 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5.util;
import java.lang.annotation.Annotation;
@@ -28,8 +27,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class ExtensionHelper {
- private static final Logger LOG =
LoggerFactory.getLogger(ExtensionHelper.class);
+
public static final String SEPARATOR = "*".repeat(80);
+
+ private static final Logger LOG =
LoggerFactory.getLogger(ExtensionHelper.class);
+
private static final String SPRING_BOOT_TEST =
"org.springframework.boot.test.context.SpringBootTest";
private static final String QUARKUS_TEST =
"io.quarkus.test.junit.QuarkusTest";
private static final String CAMEL_QUARKUS_TEST =
"org.apache.camel.quarkus.test.CamelQuarkusTest";
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteCoverageDumperExtension.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteCoverageDumperExtension.java
index 6d0ac31a8d5..826c2b04ae3 100644
---
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteCoverageDumperExtension.java
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteCoverageDumperExtension.java
@@ -14,19 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.test.junit5.util;
import org.apache.camel.api.management.ManagedCamelContext;
import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
import org.apache.camel.model.ModelCamelContext;
-import org.apache.camel.test.CamelRouteCoverageDumper;
import org.apache.camel.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RouteCoverageDumperExtension {
+
private static final Logger LOG =
LoggerFactory.getLogger(RouteCoverageDumperExtension.class);
+
private final ModelCamelContext context;
public RouteCoverageDumperExtension(ModelCamelContext context) {
diff --git
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteDumperExtension.java
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteDumperExtension.java
new file mode 100644
index 00000000000..fbeac26921c
--- /dev/null
+++
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/RouteDumperExtension.java
@@ -0,0 +1,50 @@
+/*
+ * 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.test.junit5.util;
+
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.spi.DumpRoutesStrategy;
+import org.apache.camel.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RouteDumperExtension {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(RouteDumperExtension.class);
+
+ private final ModelCamelContext context;
+
+ public RouteDumperExtension(ModelCamelContext context) {
+ this.context = context;
+ }
+
+ public void dumpRoute(Class<?> testClass, String currentTestName, String
format) throws Exception {
+ LOG.debug("Dumping Route");
+
+ String className = testClass.getSimpleName();
+ String dir = "target/camel-route-dump";
+ String name = className + "-" + StringHelper.before(currentTestName,
"(") + "." + format;
+
+ DumpRoutesStrategy drs =
context.getCamelContextExtension().getContextPlugin(DumpRoutesStrategy.class);
+ drs.setOutput(dir + "/" + name);
+ drs.setInclude("*");
+ drs.setLog(false);
+ drs.setResolvePlaceholders(false);
+ drs.setUriAsParameters(true);
+ drs.dumpRoutes(format);
+ }
+}
diff --git a/components/camel-test/camel-test-main-junit5/pom.xml
b/components/camel-test/camel-test-main-junit5/pom.xml
index b0f2303fa9d..3b8ee137473 100644
--- a/components/camel-test/camel-test-main-junit5/pom.xml
+++ b/components/camel-test/camel-test-main-junit5/pom.xml
@@ -69,6 +69,11 @@
<artifactId>camel-xml-jaxb</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-yaml-io</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
diff --git
a/components/camel-test/camel-test-main-junit5/src/main/java/org/apache/camel/test/main/junit5/CamelMainExtension.java
b/components/camel-test/camel-test-main-junit5/src/main/java/org/apache/camel/test/main/junit5/CamelMainExtension.java
index 0047b74c6ad..316137eeba4 100644
---
a/components/camel-test/camel-test-main-junit5/src/main/java/org/apache/camel/test/main/junit5/CamelMainExtension.java
+++
b/components/camel-test/camel-test-main-junit5/src/main/java/org/apache/camel/test/main/junit5/CamelMainExtension.java
@@ -20,8 +20,9 @@ import org.apache.camel.RuntimeCamelException;
import org.apache.camel.api.management.ManagedCamelContext;
import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
import org.apache.camel.model.ModelCamelContext;
-import org.apache.camel.test.CamelRouteCoverageDumper;
+import org.apache.camel.spi.DumpRoutesStrategy;
import org.apache.camel.test.junit5.util.CamelContextTestHelper;
+import org.apache.camel.test.junit5.util.CamelRouteCoverageDumper;
import org.apache.camel.util.StopWatch;
import org.apache.camel.util.StringHelper;
import org.apache.camel.util.TimeUtils;
@@ -102,6 +103,7 @@ final class CamelMainExtension
LOG.info(SEPARATOR);
}
dumpRouteCoverageIfNeeded(context, time, currentTestName);
+ dumpRouteIfNeeded(context, currentTestName);
}
/**
@@ -160,6 +162,31 @@ final class CamelMainExtension
}
}
+ /**
+ * Dump the route for the given test if it is enabled.
+ */
+ private void dumpRouteIfNeeded(ExtensionContext context, String
currentTestName) throws Exception {
+ String dump = getRouteDump(context);
+ if (dump != null && !dump.isBlank()) {
+ final Class<?> requiredTestClass = context.getRequiredTestClass();
+ // In case of a {@code @Nested} test class, its name will be
prefixed by the name of its outer classes
+ String className =
requiredTestClass.getName().substring(requiredTestClass.getPackageName().length()
+ 1);
+ String dir = "target/camel-route-dump";
+ String ext = dump.toLowerCase();
+ String name = String.format("%s-%s.%s", className,
StringHelper.before(currentTestName, "("), ext);
+
+ final ModelCamelContext camelContext =
getContextStore(context).get(CONTEXT, CamelMainContext.class).context();
+ DumpRoutesStrategy drs =
camelContext.getCamelContextExtension().getContextPlugin(DumpRoutesStrategy.class);
+
+ drs.setOutput(dir + "/" + name);
+ drs.setInclude("*");
+ drs.setLog(false);
+ drs.setResolvePlaceholders(false);
+ drs.setUriAsParameters(true);
+ drs.dumpRoutes(dump);
+ }
+ }
+
/**
* Indicates whether the route coverage is enabled according to the given
extension context and the value of the
* system property {@link
org.apache.camel.test.junit5.util.CamelContextTestHelper#ROUTE_COVERAGE_ENABLED}.
@@ -174,6 +201,23 @@ final class CamelMainExtension
.getAnnotation(CamelMainTest.class).dumpRouteCoverage();
}
+ /**
+ * Indicates whether the route dump is enabled according to the given
extension context and the value of the system
+ * property {@link
org.apache.camel.test.junit5.util.CamelContextTestHelper#ROUTE_DUMP_ENABLED}.
+ * <p/>
+ * In case of {@code @Nested} test classes, the value is always extracted
from the annotation of the outer class.
+ *
+ * @return xml or yaml if the route dump is enabled, {@code null}
otherwise.
+ */
+ private String getRouteDump(ExtensionContext context) {
+ String dump = CamelContextTestHelper.getRouteDump(null);
+ if (dump == null) {
+ dump =
context.getRequiredTestInstances().getAllInstances().get(0).getClass()
+ .getAnnotation(CamelMainTest.class).dumpRoute();
+ }
+ return dump;
+ }
+
/**
* Indicates whether JMX should be used during testing according to the
given extension context.
* <p/>
diff --git
a/components/camel-test/camel-test-main-junit5/src/main/java/org/apache/camel/test/main/junit5/CamelMainTest.java
b/components/camel-test/camel-test-main-junit5/src/main/java/org/apache/camel/test/main/junit5/CamelMainTest.java
index c88d0234000..0751233fa6b 100644
---
a/components/camel-test/camel-test-main-junit5/src/main/java/org/apache/camel/test/main/junit5/CamelMainTest.java
+++
b/components/camel-test/camel-test-main-junit5/src/main/java/org/apache/camel/test/main/junit5/CamelMainTest.java
@@ -218,6 +218,17 @@ public @interface CamelMainTest {
*/
boolean dumpRouteCoverage() default false;
+ /**
+ * Whether to dump the routes loaded into Camel for each test (dumped into
files in target/camel-route-dump).
+ * <p/>
+ * The routes can either be dumped into XML or YAML format. Set this value
to either <tt>xml</tt> or <tt>yaml</tt>.
+ * <p/>
+ * This allows tooling or manual inspection of the routes.
+ * <p/>
+ * You can also turn on route dump globally via setting JVM system
property <tt>CamelTestRouteDump=xml</tt>.
+ */
+ String dumpRoute() default "";
+
/**
* Whether JMX should be used during testing.
*
diff --git
a/components/camel-test/camel-test-main-junit5/src/test/java/org/apache/camel/test/main/junit5/annotation/DumpRouteTest.java
b/components/camel-test/camel-test-main-junit5/src/test/java/org/apache/camel/test/main/junit5/annotation/DumpRouteTest.java
new file mode 100644
index 00000000000..5ea2874fdeb
--- /dev/null
+++
b/components/camel-test/camel-test-main-junit5/src/test/java/org/apache/camel/test/main/junit5/annotation/DumpRouteTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.test.main.junit5.annotation;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.main.MainConfigurationProperties;
+import org.apache.camel.test.main.junit5.CamelMainTest;
+import org.apache.camel.test.main.junit5.Configure;
+import org.apache.camel.test.main.junit5.common.MyConfiguration;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * A test class ensuring that the route can be dumped.
+ */
+@CamelMainTest(dumpRoute = "yaml")
+class DumpRouteTest {
+
+ @EndpointInject("mock:out")
+ MockEndpoint mock;
+
+ @EndpointInject("direct:in")
+ ProducerTemplate template;
+
+ @Configure
+ private void configure(MainConfigurationProperties configuration) { //NOPMD
+ // Add the configuration class
+ configuration.addConfiguration(MyConfiguration.class);
+ }
+
+ @Test
+ void shouldDumpTheRoute() throws Exception {
+ mock.expectedBodiesReceived("Hello Will!");
+ String result = template.requestBody((Object) null, String.class);
+ mock.assertIsSatisfied();
+ assertEquals("Hello Will!", result);
+ }
+
+ @Nested
+ class NestedTest {
+
+ @Test
+ void shouldSupportNestedTest() throws Exception {
+ shouldDumpTheRoute();
+ }
+ }
+}
diff --git
a/components/camel-test/camel-test-spring-junit5/src/main/docs/test-spring-junit5.adoc
b/components/camel-test/camel-test-spring-junit5/src/main/docs/test-spring-junit5.adoc
index 694d7b7a64a..67e7c1a8ce0 100644
---
a/components/camel-test/camel-test-spring-junit5/src/main/docs/test-spring-junit5.adoc
+++
b/components/camel-test/camel-test-spring-junit5/src/main/docs/test-spring-junit5.adoc
@@ -15,7 +15,8 @@ both the classic Spring XML files or Spring Boot.
== Testing Spring Boot
The recommended approach is to annotate the test class with
`org.apache.camel.test.spring.junit5.CamelSpringBootTest`.
-This replaces the Junit4 `@RunWith` annotation using `SpringRunner.class` or
`CamelSpringBootRunner.class`.
+This replaces the Junit4 `@RunWith` annotation using `SpringBootTest`.
+
To enable autoconfiguration of the Camel context and other Spring boot
auto-configurable components,
use the annotation
`org.springframework.boot.autoconfigure.EnableAutoConfiguration`.
The Spring test context may be specified in one of three ways:
@@ -25,7 +26,6 @@ The Spring test context may be specified in one of three ways:
* a class annotated with `SpringBootConfiguration` accessible in the package
of the test class or a parent package.
-
[source,java]
----
package com.foo;
@@ -204,6 +204,7 @@ The following annotations can be used with
`camel-spring-junit5` unit testing.
| `@CamelSpringTest` | Used for testing Camel with classic Spring XML (not
Spring Boot)
| `@DisableJmx` | Used for disabling JMX
| `@EnableRouteCoverage` | Enables dumping route coverage statistics. The
route coverage status is written as xml files in the
`target/camel-route-coverage` directory after the test has finished. See more
information at xref:manual::camel-report-maven-plugin.adoc[Camel Maven Report
Plugin].
+| `@EnableRouteDump` | Enables dumping route. The route dump is written as xml
or yaml files in the `target/camel-route-dump` directory after the test has
finished.
| `@ExcludeRoutes` | Indicates if certain route builder classes should be
excluded from package scan discovery
| `@MockEndpoints` | Auto-mocking of endpoints whose URIs match the provided
filter. For more information, see xref:manual::advice-with.adoc[Advice With].
| `@MockEndpointsAndSkip` | Auto-mocking of endpoints whose URIs match the
provided filter with the added provision that the endpoints are also skipped.
For more information, see xref:manual::advice-with.adoc[Advice With].
diff --git
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelAnnotationsHandler.java
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelAnnotationsHandler.java
index b01e1d13957..5c71eee4081 100644
---
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelAnnotationsHandler.java
+++
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelAnnotationsHandler.java
@@ -33,10 +33,10 @@ import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.debugger.DefaultDebugger;
import org.apache.camel.spi.Breakpoint;
import org.apache.camel.spi.Debugger;
+import org.apache.camel.spi.DumpRoutesStrategy;
import org.apache.camel.spi.EventNotifier;
import org.apache.camel.spi.PropertiesComponent;
import org.apache.camel.spring.SpringCamelContext;
-import org.apache.camel.test.junit5.util.CamelContextTestHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.BeanPostProcessor;
@@ -44,6 +44,8 @@ import
org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
import static org.apache.camel.test.junit5.TestSupport.isCamelDebugPresent;
+import static
org.apache.camel.test.junit5.util.CamelContextTestHelper.getRouteDump;
+import static
org.apache.camel.test.junit5.util.CamelContextTestHelper.isRouteCoverageEnabled;
public final class CamelAnnotationsHandler {
@@ -54,7 +56,6 @@ public final class CamelAnnotationsHandler {
/**
* Cleanup/restore global state to defaults / pre-test values after the
test setup is complete.
- *
*/
public static void cleanup() {
DefaultCamelContext.clearOptions();
@@ -91,6 +92,7 @@ public final class CamelAnnotationsHandler {
* @param testClass the test class being executed
*/
public static void handleDisableJmx(Class<?> testClass) {
+ boolean coverage =
isRouteCoverageEnabled(testClass.isAnnotationPresent(EnableRouteCoverage.class));
if (isCamelDebugPresent()) {
LOGGER.info("Enabling Camel JMX as camel-debug has been found in
the classpath.");
DefaultCamelContext.setDisableJmx(false);
@@ -102,7 +104,7 @@ public final class CamelAnnotationsHandler {
LOGGER.info("Enabling Camel JMX as DisableJmx annotation was
found and disableJmx is set to false.");
DefaultCamelContext.setDisableJmx(false);
}
- } else if (!testClass.isAnnotationPresent(EnableRouteCoverage.class)) {
+ } else if (!coverage) {
// route coverage need JMX so do not disable it by default
LOGGER.info(
"Disabling Camel JMX globally for tests by default. Use
the DisableJMX annotation to override the default setting.");
@@ -114,21 +116,21 @@ public final class CamelAnnotationsHandler {
}
/**
- * Handles disabling of JMX on Camel contexts based on {@link
EnableRouteCoverage}.
+ * Handles enabling route coverage based on {@link EnableRouteCoverage}.
*
* @param context the initialized Spring context
* @param testClass the test class being executed
*/
- public static void handleRouteCoverage(ConfigurableApplicationContext
context, Class<?> testClass, Function testMethod)
+ public static void handleRouteCoverageEnable(
+ ConfigurableApplicationContext context, Class<?> testClass,
Function testMethod)
throws Exception {
- if (testClass.isAnnotationPresent(EnableRouteCoverage.class)) {
- System.setProperty(CamelContextTestHelper.ROUTE_COVERAGE_ENABLED,
"true");
+ boolean enabled =
isRouteCoverageEnabled(testClass.isAnnotationPresent(EnableRouteCoverage.class));
+ if (enabled) {
CamelSpringTestHelper.doToSpringCamelContexts(context, new
CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {
-
@Override
public void execute(String contextName, SpringCamelContext
camelContext) throws Exception {
- LOGGER.info("Enabling RouteCoverage");
+ LOGGER.info("Enabling @RouteCoverage");
EventNotifier notifier = new
RouteCoverageEventNotifier(testClass.getName(), testMethod);
camelContext.addService(notifier, true);
camelContext.getManagementStrategy().addEventNotifier(notifier);
@@ -137,13 +139,44 @@ public final class CamelAnnotationsHandler {
}
}
+ /**
+ * Handles enabling route dump based on {@link EnableRouteDump}.
+ *
+ * @param context the initialized Spring context
+ * @param testClass the test class being executed
+ */
+ public static void handleRouteDumpEnable(ConfigurableApplicationContext
context, Class<?> testClass, Function testMethod)
+ throws Exception {
+ String format = null;
+ if (testClass.isAnnotationPresent(EnableRouteDump.class)) {
+ format = testClass.getAnnotation(EnableRouteDump.class).format();
+ }
+ format = getRouteDump(format);
+ if (format != null && !"false".equals(format) && !format.isBlank()) {
+ final String dump = format.toLowerCase();
+ CamelSpringTestHelper.doToSpringCamelContexts(context, new
CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {
+ @Override
+ public void execute(String contextName, SpringCamelContext
camelContext) throws Exception {
+ LOGGER.info("Enabling @EnableRouteDump");
+ RouteDumpEventNotifier notifier
+ = new RouteDumpEventNotifier(testClass.getName(),
testMethod, dump);
+ camelContext.addService(notifier, true);
+
camelContext.getManagementStrategy().addEventNotifier(notifier);
+ }
+ });
+ }
+ }
+
+ /**
+ * Dumps the route coverage after test is executed
+ */
public static void handleRouteCoverageDump(
ConfigurableApplicationContext context, Class<?> testClass,
Function<CamelSpringTestHelper.DoToSpringCamelContextsStrategy,
String> testMethod)
throws Exception {
- if (testClass.isAnnotationPresent(EnableRouteCoverage.class)) {
+ boolean enabled =
isRouteCoverageEnabled(testClass.isAnnotationPresent(EnableRouteCoverage.class));
+ if (enabled) {
CamelSpringTestHelper.doToSpringCamelContexts(context, new
CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {
-
@Override
public void execute(String contextName, SpringCamelContext
camelContext) throws Exception {
LOGGER.debug("Dumping RouteCoverage");
@@ -172,6 +205,50 @@ public final class CamelAnnotationsHandler {
}
}
+ /**
+ * Dumps the route after test is executed
+ */
+ public static void handleRouteDump(
+ ConfigurableApplicationContext context, Class<?> testClass,
+ Function<CamelSpringTestHelper.DoToSpringCamelContextsStrategy,
String> testMethod)
+ throws Exception {
+
+ String format = null;
+ if (testClass.isAnnotationPresent(EnableRouteDump.class)) {
+ format = testClass.getAnnotation(EnableRouteDump.class).format();
+ }
+ format = getRouteDump(format);
+ if (format != null && !"false".equals(format) && !format.isBlank()) {
+ final String dump = format.toLowerCase();
+ CamelSpringTestHelper.doToSpringCamelContexts(context, new
CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {
+ @Override
+ public void execute(String contextName, SpringCamelContext
camelContext) throws Exception {
+ LOGGER.debug("Dumping Route");
+
+ String testMethodName = testMethod.apply(this);
+ String dir = "target/camel-route-dump";
+ String name = String.format("%s-%s.%s",
testClass.getName(), testMethodName, dump);
+
+ DumpRoutesStrategy drs =
camelContext.getCamelContextExtension().getContextPlugin(DumpRoutesStrategy.class);
+ drs.setOutput(dir + "/" + name);
+ drs.setInclude("*");
+ drs.setLog(false);
+ drs.setResolvePlaceholders(false);
+ drs.setUriAsParameters(true);
+ drs.dumpRoutes(dump);
+
+ // turn off dumping one more time by removing the event
listener (which would dump as well when Camel is stopping)
+ // but this method was explicit invoked to dump such as
from afterTest callbacks from JUnit.
+ RouteDumpEventNotifier eventNotifier =
camelContext.hasService(RouteDumpEventNotifier.class);
+ if (eventNotifier != null) {
+
camelContext.getManagementStrategy().removeEventNotifier(eventNotifier);
+ camelContext.removeService(eventNotifier);
+ }
+ }
+ });
+ }
+ }
+
public static void handleProvidesBreakpoint(ConfigurableApplicationContext
context, Class<?> testClass) throws Exception {
Collection<Method> methods =
CamelSpringTestHelper.getAllMethods(testClass);
final List<Breakpoint> breakpoints = new LinkedList<>();
diff --git
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootExecutionListener.java
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootExecutionListener.java
index ce9af586dc3..45f22420d41 100644
---
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootExecutionListener.java
+++
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootExecutionListener.java
@@ -62,8 +62,7 @@ public class CamelSpringBootExecutionListener extends
AbstractTestExecutionListe
CamelAnnotationsHandler.handleUseOverridePropertiesWithPropertiesComponent(context,
testClass);
- // Post CamelContext(s) instantiation but pre CamelContext(s) start
- // setup
+ // Post CamelContext(s) instantiation but pre CamelContext(s) start
setup
CamelAnnotationsHandler.handleProvidesBreakpoint(context, testClass);
CamelAnnotationsHandler.handleShutdownTimeout(context, testClass);
CamelAnnotationsHandler.handleMockEndpoints(context, testClass);
@@ -98,8 +97,9 @@ public class CamelSpringBootExecutionListener extends
AbstractTestExecutionListe
// mark Camel to be startable again and start Camel
System.clearProperty(PROPERTY_SKIP_STARTING_CAMEL_CONTEXT);
- // route coverage need to know the test method
- CamelAnnotationsHandler.handleRouteCoverage(context, testClass, s ->
testName);
+ // route coverage/dump need to know the test method
+ CamelAnnotationsHandler.handleRouteCoverageEnable(context, testClass,
s -> testName);
+ CamelAnnotationsHandler.handleRouteDumpEnable(context, testClass, s ->
testName);
LOG.info("Initialized CamelSpringBootExecutionListener now ready to
start CamelContext");
CamelAnnotationsHandler.handleCamelContextStartup(context, testClass);
@@ -120,6 +120,8 @@ public class CamelSpringBootExecutionListener extends
AbstractTestExecutionListe
// even if spring application context is running (i.e. its not
// dirtied per test method)
CamelAnnotationsHandler.handleRouteCoverageDump(context,
testClass, s -> testName);
+ // also dump route as either xml or yaml
+ CamelAnnotationsHandler.handleRouteDump(context, testClass, s ->
testName);
}
}
}
diff --git
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootTest.java
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootTest.java
index bbe8e687b92..0fdcbb816ee 100644
---
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootTest.java
+++
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootTest.java
@@ -26,16 +26,18 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit.jupiter.SpringExtension;
+/**
+ * Camel Spring Boot unit test.
+ */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@ExtendWith(SpringExtension.class)
-@TestExecutionListeners(
- value = {
-
CamelSpringTestContextLoaderTestExecutionListener.class,
- CamelSpringBootExecutionListener.class,
- StopWatchTestExecutionListener.class
- },
+@TestExecutionListeners(value = {
+ CamelSpringTestContextLoaderTestExecutionListener.class,
+ CamelSpringBootExecutionListener.class,
+ StopWatchTestExecutionListener.class
+},
mergeMode =
TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
public @interface CamelSpringBootTest {
diff --git
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestContextLoader.java
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestContextLoader.java
index 9fa6c0e3c49..52a386212d3 100644
---
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestContextLoader.java
+++
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestContextLoader.java
@@ -145,7 +145,8 @@ public class CamelSpringTestContextLoader extends
AbstractContextLoader {
}
// Post CamelContext(s) instantiation but pre CamelContext(s) start
setup
- CamelAnnotationsHandler.handleRouteCoverage(context, testClass, s ->
getTestMethod().getName());
+ CamelAnnotationsHandler.handleRouteCoverageEnable(context, testClass,
s -> getTestMethod().getName());
+ CamelAnnotationsHandler.handleRouteDumpEnable(context, testClass, s ->
getTestMethod().getName());
CamelAnnotationsHandler.handleProvidesBreakpoint(context, testClass);
CamelAnnotationsHandler.handleShutdownTimeout(context, testClass);
CamelAnnotationsHandler.handleMockEndpoints(context, testClass);
diff --git
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootTest.java
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/EnableRouteDump.java
similarity index 62%
copy from
components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootTest.java
copy to
components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/EnableRouteDump.java
index bbe8e687b92..d56799b5527 100644
---
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootTest.java
+++
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/EnableRouteDump.java
@@ -18,25 +18,29 @@ package org.apache.camel.test.spring.junit5;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.springframework.test.context.TestExecutionListeners;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-
+/**
+ * Whether to dump the routes loaded into Camel for each test (dumped into
files in target/camel-route-dump).
+ * <p/>
+ * The routes can either be dumped into XML or YAML format.
+ * <p/>
+ * This allows tooling or manual inspection of the routes.
+ * <p/>
+ * You can also turn on route dump globally via setting JVM system property
<tt>CamelTestRouteDump=xml</tt>.
+ */
@Documented
+@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
-@ExtendWith(SpringExtension.class)
-@TestExecutionListeners(
- value = {
-
CamelSpringTestContextLoaderTestExecutionListener.class,
- CamelSpringBootExecutionListener.class,
- StopWatchTestExecutionListener.class
- },
- mergeMode =
TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
-public @interface CamelSpringBootTest {
+public @interface EnableRouteDump {
+
+ /**
+ * The format to dump as either xml or yaml. You can use false to turn of
route dump. Uses xml as default.
+ */
+ String format() default "xml";
}
diff --git
a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/RouteDumpEventNotifier.java
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/RouteDumpEventNotifier.java
new file mode 100644
index 00000000000..419575a3988
--- /dev/null
+++
b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/RouteDumpEventNotifier.java
@@ -0,0 +1,66 @@
+/*
+ * 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.test.spring.junit5;
+
+import java.util.function.Function;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.CamelEvent;
+import org.apache.camel.spi.CamelEvent.CamelContextStoppingEvent;
+import org.apache.camel.spi.DumpRoutesStrategy;
+import org.apache.camel.support.EventNotifierSupport;
+
+public class RouteDumpEventNotifier extends EventNotifierSupport {
+
+ private final String testClassName;
+ private final Function<RouteDumpEventNotifier, String> testMethodName;
+ private final String format;
+
+ public RouteDumpEventNotifier(String testClassName,
Function<RouteDumpEventNotifier, String> testMethodName,
+ String format) {
+ this.testClassName = testClassName;
+ this.testMethodName = testMethodName;
+ this.format = format;
+ setIgnoreCamelContextEvents(false);
+ setIgnoreExchangeEvents(true);
+ }
+
+ @Override
+ public boolean isEnabled(CamelEvent event) {
+ return event instanceof CamelContextStoppingEvent;
+ }
+
+ @Override
+ public void notify(CamelEvent event) throws Exception {
+ CamelContext context = ((CamelContextStoppingEvent)
event).getContext();
+ String testName = testMethodName.apply(this);
+
+ String dir = "target/camel-route-dump";
+ String ext = format.toLowerCase();
+ String name = String.format("%s-%s.%s", testClassName, testName, ext);
+
+ DumpRoutesStrategy drs =
context.getCamelContextExtension().getContextPlugin(DumpRoutesStrategy.class);
+
+ drs.setOutput(dir + "/" + name);
+ drs.setInclude("*");
+ drs.setLog(false);
+ drs.setResolvePlaceholders(false);
+ drs.setUriAsParameters(true);
+ drs.dumpRoutes(format);
+ }
+
+}
diff --git
a/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/spring/CamelSpringRouteProcessorDumpRouteCoverageTest.java
b/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/spring/CamelSpringRouteProcessorDumpRouteCoverageTest.java
index e49fa8da8ce..ab90870deba 100644
---
a/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/spring/CamelSpringRouteProcessorDumpRouteCoverageTest.java
+++
b/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/spring/CamelSpringRouteProcessorDumpRouteCoverageTest.java
@@ -43,6 +43,7 @@ public class CamelSpringRouteProcessorDumpRouteCoverageTest
extends CamelSpringP
assertEquals(JmxManagementStrategy.class,
camelContext.getManagementStrategy().getClass());
}
+ @Test
@Override
public void testRouteCoverage() {
camelContext.stop();
diff --git
a/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/spring/CamelSpringRouteProcessorDumpRouteCoverageTest.java
b/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/spring/CamelSpringRouteProcessorDumpRouteTest.java
similarity index 68%
copy from
components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/spring/CamelSpringRouteProcessorDumpRouteCoverageTest.java
copy to
components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/spring/CamelSpringRouteProcessorDumpRouteTest.java
index e49fa8da8ce..c7ea014eeda 100644
---
a/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/spring/CamelSpringRouteProcessorDumpRouteCoverageTest.java
+++
b/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/spring/CamelSpringRouteProcessorDumpRouteTest.java
@@ -18,37 +18,29 @@ package org.apache.camel.test.spring;
import java.io.File;
-import org.apache.camel.management.JmxManagementStrategy;
import org.apache.camel.test.junit5.TestSupport;
-import org.apache.camel.test.spring.junit5.EnableRouteCoverage;
+import org.apache.camel.test.spring.junit5.EnableRouteDump;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-@EnableRouteCoverage
-public class CamelSpringRouteProcessorDumpRouteCoverageTest extends
CamelSpringPlainTest {
+@EnableRouteDump
+public class CamelSpringRouteProcessorDumpRouteTest extends
CamelSpringPlainTest {
@BeforeAll
public static void prepareFiles() throws Exception {
- TestSupport.deleteDirectory("target/camel-route-coverage");
+ TestSupport.deleteDirectory("target/camel-route-dump");
}
- @Override
@Test
- public void testJmx() {
- // JMX is enabled with route coverage
- assertEquals(JmxManagementStrategy.class,
camelContext.getManagementStrategy().getClass());
- }
-
@Override
public void testRouteCoverage() {
camelContext.stop();
// there should be files
- String[] names = new File("target/camel-route-coverage").list();
+ String[] names = new File("target/camel-route-dump").list();
assertNotNull(names);
assertTrue(names.length > 0);
}
diff --git
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
index 06b52e63da8..78ab4a12684 100644
---
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
+++
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
@@ -88,19 +88,6 @@ public class DefaultDumpRoutesStrategy extends
ServiceSupport implements DumpRou
this.camelContext = camelContext;
}
- @Override
- protected void doStart() throws Exception {
- // output can be a filename, dir, or both
- String name = FileUtil.stripPath(output);
- if (name != null && name.contains(".")) {
- outputFileName = name;
- output = FileUtil.onlyPath(output);
- if (output == null || output.isEmpty()) {
- output = ".";
- }
- }
- }
-
public String getInclude() {
return include;
}
@@ -138,7 +125,16 @@ public class DefaultDumpRoutesStrategy extends
ServiceSupport implements DumpRou
}
public void setOutput(String output) {
- this.output = output;
+ String name = FileUtil.stripPath(output);
+ if (name != null && name.contains(".")) {
+ outputFileName = name;
+ this.output = FileUtil.onlyPath(output);
+ if (this.output == null || this.output.isEmpty()) {
+ this.output = ".";
+ }
+ } else {
+ this.output = name;
+ }
}
public boolean isUriAsParameters() {