This is an automated email from the ASF dual-hosted git repository.

orpiske 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 382fac09bc0 CAMEL-20843: further split the CamelTestSupport 
responsibilities
382fac09bc0 is described below

commit 382fac09bc045dff149ee267aa5fceff91b6ae4d
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Thu Jun 6 11:39:02 2024 +0200

    CAMEL-20843: further split the CamelTestSupport responsibilities
    
    - Move the legacy test/context setup methods to the AbstractTestSupport
    - Moved most of the helper logic to the TestSupport
    - Cleaned up one affected test
    - Added documentation and comments
    - Deprecated a few more methods
---
 .../camel/component/pubnub/PubNubTestBase.java     |   2 +
 .../camel/test/junit5/AbstractTestSupport.java     | 362 +++++++++++++++++++
 .../apache/camel/test/junit5/CamelTestSupport.java | 402 ++-------------------
 .../camel/test/junit5/CommonTestSupport.java       |  40 ++
 .../test/junit5/TestExecutionConfiguration.java    |  14 +-
 .../org/apache/camel/test/junit5/TestSupport.java  | 119 ++++++
 .../test/junit5/util/CamelContextTestHelper.java   |   9 +
 .../camel/test/main/junit5/CamelMainExtension.java |   6 +-
 .../spring/junit5/CamelAnnotationsHandler.java     |   4 +-
 9 files changed, 570 insertions(+), 388 deletions(-)

diff --git 
a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubTestBase.java
 
b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubTestBase.java
index d9861e06f42..b47e03252f9 100644
--- 
a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubTestBase.java
+++ 
b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/PubNubTestBase.java
@@ -39,11 +39,13 @@ public class PubNubTestBase extends CamelTestSupport {
 
     private WireMockServer wireMockServer = new 
WireMockServer(options().port(port));
 
+    @Override
     protected void setupResources() {
         wireMockServer.start();
         WireMock.configureFor("localhost", wireMockServer.port());
     }
 
+    @Override
     protected void cleanupResources() {
         wireMockServer.stop();
         pubnub.destroy();
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
new file mode 100644
index 00000000000..e20e0e6c0c6
--- /dev/null
+++ 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/AbstractTestSupport.java
@@ -0,0 +1,362 @@
+/*
+ * 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;
+
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.Service;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.spi.PropertiesComponent;
+import org.apache.camel.support.EndpointHelper;
+
+/**
+ * Base test class, mostly made of legacy setup methods. This is intended for 
internal use.
+ */
+public abstract class AbstractTestSupport implements CommonTestSupport {
+    protected final TestExecutionConfiguration testConfigurationBuilder;
+    protected final CamelContextConfiguration camelContextConfiguration;
+    protected volatile ModelCamelContext context;
+    protected volatile ProducerTemplate template;
+    protected volatile FluentProducerTemplate fluentTemplate;
+    protected volatile ConsumerTemplate consumer;
+
+    protected AbstractTestSupport() {
+        testConfigurationBuilder = new TestExecutionConfiguration();
+        camelContextConfiguration = new CamelContextConfiguration();
+    }
+
+    protected AbstractTestSupport(TestExecutionConfiguration 
testConfigurationBuilder,
+                                  CamelContextConfiguration 
camelContextConfiguration) {
+        this.testConfigurationBuilder = testConfigurationBuilder;
+        this.camelContextConfiguration = camelContextConfiguration;
+    }
+
+    /**
+     * Strategy to set up resources, before {@link CamelContext} is created. 
This is meant to be used by resources that
+     * must be available before the context is created. Do not use this as a 
replacement for tasks that can be handled
+     * using JUnit's annotations.
+     */
+    protected void setupResources() throws Exception {
+        // noop
+    }
+
+    /**
+     * Strategy to cleanup resources, after {@link CamelContext} is stopped
+     */
+    protected void cleanupResources() throws Exception {
+        // noop
+    }
+
+    /**
+     * Use the RouteBuilder or not
+     *
+     * @deprecated Use the accessors from {@link #testConfiguration()} method
+     * @return     <tt>true</tt> then {@link CamelContext} will be auto 
started, <tt>false</tt> then
+     *             {@link CamelContext} will <b>not</b> be auto started (you 
will have to start it manually)
+     */
+    @Deprecated(since = "4.7.0")
+    public boolean isUseRouteBuilder() {
+        return testConfigurationBuilder.useRouteBuilder();
+    }
+
+    @Deprecated(since = "4.7.0")
+    public void setUseRouteBuilder(boolean useRouteBuilder) {
+        testConfigurationBuilder.withUseRouteBuilder(useRouteBuilder);
+    }
+
+    /**
+     * Whether to dump route coverage stats at the end of the test.
+     * <p/>
+     * This allows tooling or manual inspection of the stats, so you can 
generate a route trace diagram of which EIPs
+     * have been in use and which have not. Similar concepts as a code 
coverage report.
+     * <p/>
+     * You can also turn on route coverage globally via setting JVM system 
property
+     * <tt>CamelTestRouteCoverage=true</tt>.
+     *
+     * @deprecated Use the accessors from {@link #testConfiguration()} method
+     * @return     <tt>true</tt> to write route coverage status in an xml file 
in the
+     *             <tt>target/camel-route-coverage</tt> directory after the 
test has finished.
+     */
+    @Deprecated(since = "4.7.0")
+    public boolean isDumpRouteCoverage() {
+        return testConfigurationBuilder.isDumpRouteCoverage();
+    }
+
+    /**
+     * 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
+     * takes place. This helps by ensuring the advice with has been property 
setup before the {@link CamelContext} is
+     * started
+     * <p/>
+     * <b>Important:</b> It's important to start {@link CamelContext} manually 
from the unit test after you are done
+     * doing all the advice with.
+     *
+     * @deprecated Use the accessors from {@link #testConfiguration()} method
+     * @return     <tt>true</tt> if you use advice with in your unit tests.
+     */
+    @Deprecated(since = "4.7.0")
+    public boolean isUseAdviceWith() {
+        return testConfigurationBuilder.isUseAdviceWith();
+    }
+
+    /**
+     * Tells whether {@link CamelContext} should be setup per test or per 
class. DO NOT USE.
+     * <p/>
+     * By default it will be setup/teardown per test method. This method 
returns <code>true</code> when the camel test
+     * class is annotated with @TestInstance(TestInstance.Lifecycle.PER_CLASS).
+     * <p/>
+     * <b>Important:</b> Use this with care as the {@link CamelContext} will 
carry over state from previous tests, such
+     * as endpoints, components etc. So you cannot use this in all your tests.
+     * <p/>
+     *
+     * @deprecated Use the accessors from {@link #testConfiguration()} method
+     * @return     <tt>true</tt> per class, <tt>false</tt> per test.
+     */
+    @Deprecated(since = "4.7.0")
+    protected final boolean isCreateCamelContextPerClass() {
+        return testConfigurationBuilder.isCreateCamelContextPerClass();
+    }
+
+    /**
+     * Override to enable auto mocking endpoints based on the pattern.
+     * <p/>
+     * Return <tt>*</tt> to mock all endpoints.
+     *
+     * @see        EndpointHelper#matchEndpoint(CamelContext, String, String)
+     * @deprecated Use the accessors from {@link #camelContextConfiguration()} 
method
+     */
+    @Deprecated(since = "4.7.0")
+    public String isMockEndpoints() {
+        return camelContextConfiguration().mockEndpoints();
+    }
+
+    /**
+     * Override to enable auto mocking endpoints based on the pattern, and 
<b>skip</b> sending to original endpoint.
+     * <p/>
+     * Return <tt>*</tt> to mock all endpoints.
+     *
+     * @see        EndpointHelper#matchEndpoint(CamelContext, String, String)
+     * @deprecated Use the accessors from {@link #camelContextConfiguration()} 
method
+     */
+    @Deprecated(since = "4.7.0")
+    public String isMockEndpointsAndSkip() {
+        return camelContextConfiguration().mockEndpointsAndSkip();
+    }
+
+    /**
+     * To replace from routes
+     *
+     * @param      routeId
+     * @param      fromEndpoint
+     * @deprecated              Use the accessors from {@link 
#camelContextConfiguration()} method
+     */
+    @Deprecated(since = "4.7.0")
+    public void replaceRouteFromWith(String routeId, String fromEndpoint) {
+        camelContextConfiguration.replaceRouteFromWith(routeId, fromEndpoint);
+    }
+
+    /**
+     * Used for filtering routes matching the given pattern, which follows the 
following rules:
+     * <p>
+     * - Match by route id - Match by route input endpoint uri
+     * <p>
+     * The matching is using exact match, by wildcard and regular expression.
+     * <p>
+     * For example to only include routes which starts with foo in their route 
id's, use: include=foo&#42; And to
+     * exclude routes which starts from JMS endpoints, use: exclude=jms:&#42;
+     * <p>
+     * Multiple patterns can be separated by comma, for example to exclude 
both foo and bar routes, use:
+     * exclude=foo&#42;,bar&#42;
+     * <p>
+     * Exclude takes precedence over include.
+     */
+    @Deprecated(since = "4.7.0")
+    public String getRouteFilterIncludePattern() {
+        return camelContextConfiguration.routeFilterIncludePattern();
+    }
+
+    /**
+     * Used for filtering routes matching the given pattern, which follows the 
following rules:
+     * <p>
+     * - Match by route id - Match by route input endpoint uri
+     * <p>
+     * The matching is using exact match, by wildcard and regular expression.
+     * <p>
+     * For example to only include routes which starts with foo in their route 
id's, use: include=foo&#42; And to
+     * exclude routes which starts from JMS endpoints, use: exclude=jms:&#42;
+     * <p>
+     * Multiple patterns can be separated by comma, for example to exclude 
both foo and bar routes, use:
+     * exclude=foo&#42;,bar&#42;
+     * <p>
+     * Exclude takes precedence over include.
+     */
+    @Deprecated(since = "4.7.0")
+    public String getRouteFilterExcludePattern() {
+        return camelContextConfiguration.routeFilterExcludePattern();
+    }
+
+    /**
+     * Override to enable debugger
+     * <p/>
+     * Is default <tt>false</tt>
+     *
+     * @deprecated Use the accessors from {@link #testConfiguration()} method
+     */
+    @Deprecated(since = "4.7.0")
+    public boolean isUseDebugger() {
+        return camelContextConfiguration.useDebugger();
+    }
+
+    @Deprecated(since = "4.7.0")
+    public Service getCamelContextService() {
+        return camelContextConfiguration.camelContextService();
+    }
+
+    @Deprecated(since = "4.7.0")
+    public Service camelContextService() {
+        return camelContextConfiguration.camelContextService();
+    }
+
+    /**
+     * Gets a reference to the CamelContext. Must not be used during test 
setup.
+     *
+     * @return A reference to the CamelContext
+     */
+    public CamelContext context() {
+        return context;
+    }
+
+    /**
+     * Sets the CamelContext. Used by the manager to override tests that try 
to access the context during setup. DO NOT
+     * USE.
+     *
+     * @param context
+     */
+    @Deprecated(since = "4.7.0")
+    public void setContext(ModelCamelContext context) {
+        this.context = context;
+    }
+
+    public ProducerTemplate template() {
+        return template;
+    }
+
+    public FluentProducerTemplate fluentTemplate() {
+        return fluentTemplate;
+    }
+
+    public ConsumerTemplate consumer() {
+        return consumer;
+    }
+
+    /**
+     * Allows a service to be registered a separate lifecycle service to start 
and stop the context; such as for Spring
+     * when the ApplicationContext is started and stopped, rather than 
directly stopping the CamelContext
+     */
+    public void setCamelContextService(Service service) {
+        camelContextConfiguration.withCamelContextService(service);
+    }
+
+    /**
+     * Whether JMX should be used during testing.
+     *
+     * @deprecated Use the methods {@link #testConfiguration()} to enable, 
disable or check JMX state.
+     * @return     <tt>false</tt> by default.
+     */
+    @Deprecated(since = "4.7.0")
+    protected boolean useJmx() {
+        return testConfigurationBuilder.isJmxEnabled();
+    }
+
+    /**
+     * Override this method to include and override properties with the Camel 
{@link PropertiesComponent}.
+     *
+     * @deprecated Use the accessors from {@link #camelContextConfiguration()} 
method
+     * @return     additional properties to add/override.
+     */
+    @Deprecated(since = "4.7.0")
+    protected Properties useOverridePropertiesWithPropertiesComponent() {
+        return 
camelContextConfiguration.useOverridePropertiesWithPropertiesComponent();
+    }
+
+    /**
+     * Whether to ignore missing locations with the {@link 
PropertiesComponent}. For example when unit testing you may
+     * want to ignore locations that are not available in the environment used 
for testing.
+     *
+     * @deprecated Use the accessors from {@link #camelContextConfiguration()} 
method
+     * @return     <tt>true</tt> to ignore, <tt>false</tt> to not ignore, and 
<tt>null</tt> to leave as configured on
+     *             the {@link PropertiesComponent}
+     */
+    @Deprecated(since = "4.7.0")
+    protected Boolean ignoreMissingLocationWithPropertiesComponent() {
+        return 
camelContextConfiguration.ignoreMissingLocationWithPropertiesComponent();
+    }
+
+    /**
+     * Gets the {@link CamelContextConfiguration} for the test
+     *
+     * @return the camel context configuration
+     */
+    @Override
+    public final CamelContextConfiguration camelContextConfiguration() {
+        return camelContextConfiguration;
+    }
+
+    /**
+     * Gets the {@link TestExecutionConfiguration} test execution 
configuration instance for the test
+     *
+     * @return the configuration instance for the test
+     */
+    @Override
+    public final TestExecutionConfiguration testConfiguration() {
+        return testConfigurationBuilder;
+    }
+
+    /**
+     * Disables the JMX agent. Must be called before the setup method.
+     *
+     * @deprecated Use the methods {@link #testConfiguration()} to enable, 
disable or check JMX state.
+     */
+    @Deprecated(since = "4.7.0")
+    protected void disableJMX() {
+        testConfigurationBuilder.withDisableJMX();
+    }
+
+    /**
+     * Enables the JMX agent. Must be called before the setup method.
+     *
+     * @deprecated Use the methods {@link #testConfiguration()} to enable, 
disable or check JMX state.
+     */
+    @Deprecated(since = "4.7.0")
+    protected void enableJMX() {
+        testConfigurationBuilder.withEnableJMX();
+    }
+
+    /**
+     * Whether route coverage is enabled
+     *
+     * @return true if enabled or false otherwise
+     */
+    protected boolean isRouteCoverageEnabled() {
+        return testConfigurationBuilder.isRouteCoverageEnabled();
+    }
+}
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 4c3d098f6ba..a2b8c2e7ed6 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
@@ -17,36 +17,24 @@
 package org.apache.camel.test.junit5;
 
 import java.util.Map;
-import java.util.Properties;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.ConsumerTemplate;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
-import org.apache.camel.Expression;
-import org.apache.camel.FluentProducerTemplate;
-import org.apache.camel.Message;
 import org.apache.camel.NoSuchEndpointException;
-import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
-import org.apache.camel.ProducerTemplate;
 import org.apache.camel.RoutesBuilder;
-import org.apache.camel.Service;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.model.ModelCamelContext;
 import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.spi.CamelBeanPostProcessor;
 import org.apache.camel.spi.Language;
-import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spi.Registry;
-import org.apache.camel.support.EndpointHelper;
 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.util.StopWatch;
-import org.apache.camel.util.StringHelper;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.TestInstance.Lifecycle;
@@ -61,7 +49,6 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.camel.test.junit5.util.ExtensionHelper.normalizeUri;
 import static 
org.apache.camel.test.junit5.util.ExtensionHelper.testStartHeader;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
@@ -70,43 +57,28 @@ import static 
org.junit.jupiter.api.Assertions.assertNotNull;
  * {@link org.apache.camel.ProducerTemplate} for use in the test case Do 
<tt>not</tt> use this class for Spring Boot
  * testing.
  */
-public abstract class CamelTestSupport
+public abstract class CamelTestSupport extends AbstractTestSupport
         implements BeforeEachCallback, AfterEachCallback, AfterAllCallback, 
BeforeAllCallback, BeforeTestExecutionCallback,
         AfterTestExecutionCallback {
-
-    /**
-     * JVM system property which can be set to true to turn on dumping route 
coverage statistics.
-     */
-    public static final String ROUTE_COVERAGE_ENABLED = 
"CamelTestRouteCoverage";
-
     private static final Logger LOG = 
LoggerFactory.getLogger(CamelTestSupport.class);
 
-    protected volatile ModelCamelContext context;
-    protected volatile ProducerTemplate template;
-    protected volatile FluentProducerTemplate fluentTemplate;
-    protected volatile ConsumerTemplate consumer;
     @RegisterExtension
     protected CamelTestSupport camelTestSupportExtension = this;
     private final StopWatch watch = new StopWatch();
     private String currentTestName;
 
-    private final TestExecutionConfiguration testConfigurationBuilder;
-    private final CamelContextConfiguration camelContextConfiguration;
-
     private CamelContextManager contextManager;
     private final ContextManagerFactory contextManagerFactory;
 
     protected CamelTestSupport(ContextManagerFactory contextManagerFactory) {
+        super();
         this.contextManagerFactory = contextManagerFactory;
 
-        testConfigurationBuilder = new TestExecutionConfiguration();
         testConfigurationBuilder.withJMX(useJmx())
                 .withUseRouteBuilder(isUseRouteBuilder())
                 .withUseAdviceWith(isUseAdviceWith())
                 .withDumpRouteCoverage(isDumpRouteCoverage());
 
-        camelContextConfiguration = new CamelContextConfiguration();
-
         camelContextConfiguration
                 .withCamelContextSupplier(this::createCamelContext)
                 .withRegistryBinder(this::bindToRegistry)
@@ -177,156 +149,6 @@ public abstract class CamelTestSupport
         contextManager.stop();
     }
 
-    /**
-     * Use the RouteBuilder or not
-     *
-     * @deprecated Use the accessors from {@link #testConfiguration()} method
-     * @return     <tt>true</tt> then {@link CamelContext} will be auto 
started, <tt>false</tt> then
-     *             {@link CamelContext} will <b>not</b> be auto started (you 
will have to start it manually)
-     */
-    @Deprecated(since = "4.7.0")
-    public boolean isUseRouteBuilder() {
-        return testConfigurationBuilder.useRouteBuilder();
-    }
-
-    @Deprecated(since = "4.7.0")
-    public void setUseRouteBuilder(boolean useRouteBuilder) {
-        testConfigurationBuilder.withUseRouteBuilder(useRouteBuilder);
-    }
-
-    /**
-     * Whether to dump route coverage stats at the end of the test.
-     * <p/>
-     * This allows tooling or manual inspection of the stats, so you can 
generate a route trace diagram of which EIPs
-     * have been in use and which have not. Similar concepts as a code 
coverage report.
-     * <p/>
-     * You can also turn on route coverage globally via setting JVM system 
property
-     * <tt>CamelTestRouteCoverage=true</tt>.
-     *
-     * @deprecated Use the accessors from {@link #testConfiguration()} method
-     * @return     <tt>true</tt> to write route coverage status in an xml file 
in the
-     *             <tt>target/camel-route-coverage</tt> directory after the 
test has finished.
-     */
-    @Deprecated(since = "4.7.0")
-    public boolean isDumpRouteCoverage() {
-        return false;
-    }
-
-    /**
-     * Override when using <a 
href="http://camel.apache.org/advicewith.html";>advice with</a> and return 
<tt>true</tt>.
-     * This helps knowing advice with is to be used, and {@link CamelContext} 
will not be started before the advice with
-     * takes place. This helps by ensuring the advice with has been property 
setup before the {@link CamelContext} is
-     * started
-     * <p/>
-     * <b>Important:</b> Its important to start {@link CamelContext} manually 
from the unit test after you are done
-     * doing all the advice with.
-     *
-     * @deprecated Use the accessors from {@link #testConfiguration()} method
-     * @return     <tt>true</tt> if you use advice with in your unit tests.
-     */
-    @Deprecated(since = "4.7.0")
-    public boolean isUseAdviceWith() {
-        return testConfigurationBuilder.isUseAdviceWith();
-    }
-
-    /**
-     * Tells whether {@link CamelContext} should be setup per test or per 
class.
-     * <p/>
-     * By default it will be setup/teardown per test method. This method 
returns <code>true</code> when the camel test
-     * class is annotated with @TestInstance(TestInstance.Lifecycle.PER_CLASS).
-     * <p/>
-     * <b>Important:</b> Use this with care as the {@link CamelContext} will 
carry over state from previous tests, such
-     * as endpoints, components etc. So you cannot use this in all your tests.
-     * <p/>
-     * Setting up {@link CamelContext} uses the {@link #doPreSetup()}, {@link 
#doSetUp()}, and {@link #doPostSetup()}
-     * methods in that given order.
-     *
-     * @deprecated Use the accessors from {@link #testConfiguration()} method
-     * @return     <tt>true</tt> per class, <tt>false</tt> per test.
-     */
-    @Deprecated(since = "4.7.0")
-    protected final boolean isCreateCamelContextPerClass() {
-        return testConfigurationBuilder.isCreateCamelContextPerClass();
-    }
-
-    /**
-     * Override to enable auto mocking endpoints based on the pattern.
-     * <p/>
-     * Return <tt>*</tt> to mock all endpoints.
-     *
-     * @see        EndpointHelper#matchEndpoint(CamelContext, String, String)
-     * @deprecated Use the accessors from {@link #camelContextConfiguration()} 
method
-     */
-    @Deprecated(since = "4.7.0")
-    public String isMockEndpoints() {
-        return camelContextConfiguration().mockEndpoints();
-    }
-
-    /**
-     * Override to enable auto mocking endpoints based on the pattern, and 
<b>skip</b> sending to original endpoint.
-     * <p/>
-     * Return <tt>*</tt> to mock all endpoints.
-     *
-     * @see        EndpointHelper#matchEndpoint(CamelContext, String, String)
-     * @deprecated Use the accessors from {@link #camelContextConfiguration()} 
method
-     */
-    @Deprecated(since = "4.7.0")
-    public String isMockEndpointsAndSkip() {
-        return camelContextConfiguration().mockEndpointsAndSkip();
-    }
-
-    /**
-     * To replace from routes
-     *
-     * @param      routeId
-     * @param      fromEndpoint
-     * @deprecated              Use the accessors from {@link 
#camelContextConfiguration()} method
-     */
-    @Deprecated(since = "4.7.0")
-    public void replaceRouteFromWith(String routeId, String fromEndpoint) {
-        camelContextConfiguration.replaceRouteFromWith(routeId, fromEndpoint);
-    }
-
-    /**
-     * Used for filtering routes matching the given pattern, which follows the 
following rules:
-     * <p>
-     * - Match by route id - Match by route input endpoint uri
-     * <p>
-     * The matching is using exact match, by wildcard and regular expression.
-     * <p>
-     * For example to only include routes which starts with foo in their route 
id's, use: include=foo&#42; And to
-     * exclude routes which starts from JMS endpoints, use: exclude=jms:&#42;
-     * <p>
-     * Multiple patterns can be separated by comma, for example to exclude 
both foo and bar routes, use:
-     * exclude=foo&#42;,bar&#42;
-     * <p>
-     * Exclude takes precedence over include.
-     */
-    @Deprecated(since = "4.7.0")
-    public String getRouteFilterIncludePattern() {
-        return camelContextConfiguration.routeFilterIncludePattern();
-    }
-
-    /**
-     * Used for filtering routes matching the given pattern, which follows the 
following rules:
-     * <p>
-     * - Match by route id - Match by route input endpoint uri
-     * <p>
-     * The matching is using exact match, by wildcard and regular expression.
-     * <p>
-     * For example to only include routes which starts with foo in their route 
id's, use: include=foo&#42; And to
-     * exclude routes which starts from JMS endpoints, use: exclude=jms:&#42;
-     * <p>
-     * Multiple patterns can be separated by comma, for example to exclude 
both foo and bar routes, use:
-     * exclude=foo&#42;,bar&#42;
-     * <p>
-     * Exclude takes precedence over include.
-     */
-    @Deprecated(since = "4.7.0")
-    public String getRouteFilterExcludePattern() {
-        return camelContextConfiguration.routeFilterExcludePattern();
-    }
-
     /**
      * Gets the name of the current test being executed.
      */
@@ -334,68 +156,6 @@ public abstract class CamelTestSupport
         return currentTestName;
     }
 
-    /**
-     * Override to enable debugger
-     * <p/>
-     * Is default <tt>false</tt>
-     *
-     * @deprecated Use the accessors from {@link #testConfiguration()} method
-     */
-    @Deprecated(since = "4.7.0")
-    public boolean isUseDebugger() {
-        return camelContextConfiguration.useDebugger();
-    }
-
-    @Deprecated(since = "4.7.0")
-    public Service getCamelContextService() {
-        return camelContextConfiguration.camelContextService();
-    }
-
-    @Deprecated(since = "4.7.0")
-    public Service camelContextService() {
-        return camelContextConfiguration.camelContextService();
-    }
-
-    /**
-     * Gets a reference to the CamelContext. Must not be used during test 
setup.
-     *
-     * @return A reference to the CamelContext
-     */
-    public CamelContext context() {
-        return context;
-    }
-
-    /**
-     * Sets the CamelContext. Used by the manager to override tests that try 
to access the context during setup. DO NOT
-     * USE.
-     *
-     * @param context
-     */
-    @Deprecated(since = "4.7.0")
-    public void setContext(ModelCamelContext context) {
-        this.context = context;
-    }
-
-    public ProducerTemplate template() {
-        return template;
-    }
-
-    public FluentProducerTemplate fluentTemplate() {
-        return fluentTemplate;
-    }
-
-    public ConsumerTemplate consumer() {
-        return consumer;
-    }
-
-    /**
-     * Allows a service to be registered a separate lifecycle service to start 
and stop the context; such as for Spring
-     * when the ApplicationContext is started and stopped, rather than 
directly stopping the CamelContext
-     */
-    public void setCamelContextService(Service service) {
-        camelContextConfiguration.withCamelContextService(service);
-    }
-
     /**
      * Common test setup. For internal use.
      *
@@ -432,7 +192,7 @@ public abstract class CamelTestSupport
     }
 
     /**
-     * Strategy to perform any post setup after {@link CamelContext} is 
created. This is for internal Camel usage.
+     * Strategy to perform any post-setup after {@link CamelContext} is 
created. This is for internal Camel usage.
      *
      * @deprecated Use {@link #setupResources()} instead
      */
@@ -482,10 +242,6 @@ public abstract class CamelTestSupport
         throw new UnsupportedOperationException("Do not use the doSetUp 
method");
     }
 
-    private boolean isRouteCoverageEnabled() {
-        return Boolean.parseBoolean(System.getProperty(ROUTE_COVERAGE_ENABLED, 
"false")) || isDumpRouteCoverage();
-    }
-
     /**
      * Common test tear down. For internal use.
      *
@@ -528,21 +284,6 @@ public abstract class CamelTestSupport
         // noop
     }
 
-    /**
-     * Strategy to set up resources, before {@link CamelContext} is created. 
This is meant to be used by resources that
-     * must be available before the context is created. Do not use this as a 
replacement for tasks that can be handled
-     * using JUnit's annotations.
-     */
-    protected void setupResources() throws Exception {
-    }
-
-    /**
-     * Strategy to cleanup resources, after {@link CamelContext} is stopped
-     */
-    protected void cleanupResources() throws Exception {
-        // noop
-    }
-
     /**
      * Returns the timeout to use when shutting down (unit in seconds).
      * <p/>
@@ -556,41 +297,6 @@ public abstract class CamelTestSupport
         return camelContextConfiguration.shutdownTimeout();
     }
 
-    /**
-     * Whether JMX should be used during testing.
-     *
-     * @deprecated Use the methods {@link #testConfiguration()} to enable, 
disable or check JMX state.
-     * @return     <tt>false</tt> by default.
-     */
-    @Deprecated(since = "4.7.0")
-    protected boolean useJmx() {
-        return testConfigurationBuilder.isJmxEnabled();
-    }
-
-    /**
-     * Override this method to include and override properties with the Camel 
{@link PropertiesComponent}.
-     *
-     * @deprecated Use the accessors from {@link #camelContextConfiguration()} 
method
-     * @return     additional properties to add/override.
-     */
-    @Deprecated(since = "4.7.0")
-    protected Properties useOverridePropertiesWithPropertiesComponent() {
-        return 
camelContextConfiguration.useOverridePropertiesWithPropertiesComponent();
-    }
-
-    /**
-     * Whether to ignore missing locations with the {@link 
PropertiesComponent}. For example when unit testing you may
-     * want to ignore locations that are not available in the environment used 
for testing.
-     *
-     * @deprecated Use the accessors from {@link #camelContextConfiguration()} 
method
-     * @return     <tt>true</tt> to ignore, <tt>false</tt> to not ignore, and 
<tt>null</tt> to leave as configured on
-     *             the {@link PropertiesComponent}
-     */
-    @Deprecated(since = "4.7.0")
-    protected Boolean ignoreMissingLocationWithPropertiesComponent() {
-        return 
camelContextConfiguration.ignoreMissingLocationWithPropertiesComponent();
-    }
-
     /**
      * Internal method. Do not use.
      *
@@ -624,11 +330,13 @@ public abstract class CamelTestSupport
         return ExtensionHelper.hasClassAnnotation(getClass(), names);
     }
 
+    @Deprecated(since = "4.7.0")
     protected void stopCamelContext() throws Exception {
         contextManager.stopCamelContext();
 
     }
 
+    @Deprecated(since = "4.7.0")
     protected void startCamelContext() throws Exception {
         contextManager.startCamelContext();
     }
@@ -724,17 +432,9 @@ public abstract class CamelTestSupport
      *                                 be resolved
      * @throws NoSuchEndpointException is the mock endpoint does not exist
      */
+    @Deprecated(since = "4.7.0")
     protected final MockEndpoint getMockEndpoint(String uri, boolean create) 
throws NoSuchEndpointException {
-        // look for existing mock endpoints that have the same queue name, and
-        // to
-        // do that we need to normalize uri and strip out query parameters and
-        // whatnot
-        final String normalizedUri = normalizeUri(uri);
-        // strip query
-        final String target = StringHelper.before(normalizedUri, "?", 
normalizedUri);
-
-        // lookup endpoints in registry and try to find it
-        return CamelContextTestHelper.lookupEndpoint(context, uri, create, 
target);
+        return TestSupport.getMockEndpoint(context, uri, create);
     }
 
     /**
@@ -743,11 +443,9 @@ public abstract class CamelTestSupport
      * @param endpointUri the URI of the endpoint to send to
      * @param body        the body for the message
      */
+    @Deprecated(since = "4.7.0")
     protected final void sendBody(String endpointUri, final Object body) {
-        template.send(endpointUri, exchange -> {
-            Message in = exchange.getIn();
-            in.setBody(body);
-        });
+        TestSupport.sendBody(template, endpointUri, body);
     }
 
     /**
@@ -757,14 +455,9 @@ public abstract class CamelTestSupport
      * @param body        the body for the message
      * @param headers     any headers to set on the message
      */
+    @Deprecated(since = "4.7.0")
     protected final void sendBody(String endpointUri, final Object body, final 
Map<String, Object> headers) {
-        template.send(endpointUri, exchange -> {
-            Message in = exchange.getIn();
-            in.setBody(body);
-            for (Map.Entry<String, Object> entry : headers.entrySet()) {
-                in.setHeader(entry.getKey(), entry.getValue());
-            }
-        });
+        TestSupport.sendBody(template, endpointUri, body, headers);
     }
 
     /**
@@ -773,16 +466,15 @@ public abstract class CamelTestSupport
      * @param endpointUri the endpoint URI to send to
      * @param bodies      the bodies to send, one per message
      */
-    @Deprecated
+    @Deprecated(since = "4.7.0")
     protected final void sendBodies(String endpointUri, Object... bodies) {
-        for (Object body : bodies) {
-            sendBody(endpointUri, body);
-        }
+        TestSupport.sendBodies(template, endpointUri, bodies);
     }
 
     /**
      * Creates an exchange with the given body
      */
+    @Deprecated(since = "4.7.0")
     protected final Exchange createExchangeWithBody(Object body) {
         return TestSupport.createExchangeWithBody(context, body);
     }
@@ -790,26 +482,18 @@ public abstract class CamelTestSupport
     /**
      * Asserts that the given language name and expression evaluates to the 
given value on a specific exchange
      */
+    @Deprecated(since = "4.7.0")
     protected final void assertExpression(Exchange exchange, String 
languageName, String expressionText, Object expectedValue) {
-        Language language = assertResolveLanguage(languageName);
-
-        Expression expression = language.createExpression(expressionText);
-        assertNotNull(expression, "No Expression could be created for text: " 
+ expressionText + " language: " + language);
-
-        TestSupport.assertExpression(expression, exchange, expectedValue);
+        TestSupport.assertExpression(context, exchange, languageName, 
expressionText, expectedValue);
     }
 
     /**
      * Asserts that the given language name and predicate expression evaluates 
to the expected value on the message
      * exchange
      */
+    @Deprecated(since = "4.7.0")
     protected final void assertPredicate(String languageName, String 
expressionText, Exchange exchange, boolean expected) {
-        Language language = assertResolveLanguage(languageName);
-
-        Predicate predicate = language.createPredicate(expressionText);
-        assertNotNull(predicate, "No Predicate could be created for text: " + 
expressionText + " language: " + language);
-
-        TestSupport.assertPredicate(predicate, exchange, expected);
+        TestSupport.assertPredicate(context, languageName, expressionText, 
exchange, expected);
     }
 
     /**
@@ -817,9 +501,7 @@ public abstract class CamelTestSupport
      */
     @Deprecated(since = "4.7.0")
     protected final Language assertResolveLanguage(String languageName) {
-        Language language = context.resolveLanguage(languageName);
-        assertNotNull(language, "Nog language found for name: " + 
languageName);
-        return language;
+        return TestSupport.assertResolveLanguage(context, languageName);
     }
 
     /**
@@ -834,35 +516,11 @@ public abstract class CamelTestSupport
     }
 
     protected final <T extends Endpoint> T getMandatoryEndpoint(String uri, 
Class<T> type) {
-        T endpoint = context.getEndpoint(uri, type);
-        assertNotNull(endpoint, "No endpoint found for uri: " + uri);
-        return endpoint;
+        return TestSupport.getMandatoryEndpoint(context(), uri, type);
     }
 
     protected final Endpoint getMandatoryEndpoint(String uri) {
-        Endpoint endpoint = context.getEndpoint(uri);
-        assertNotNull(endpoint, "No endpoint found for uri: " + uri);
-        return endpoint;
-    }
-
-    /**
-     * Disables the JMX agent. Must be called before the {@link #setUp()} 
method.
-     *
-     * @deprecated Use the methods {@link #testConfiguration()} to enable, 
disable or check JMX state.
-     */
-    @Deprecated(since = "4.7.0")
-    protected void disableJMX() {
-        testConfigurationBuilder.withDisableJMX();
-    }
-
-    /**
-     * Enables the JMX agent. Must be called before the {@link #setUp()} 
method.
-     *
-     * @deprecated Use the methods {@link #testConfiguration()} to enable, 
disable or check JMX state.
-     */
-    @Deprecated(since = "4.7.0")
-    protected void enableJMX() {
-        testConfigurationBuilder.withEnableJMX();
+        return TestSupport.getMandatoryEndpoint(context(), uri);
     }
 
     /**
@@ -885,22 +543,4 @@ public abstract class CamelTestSupport
             Exchange exchange, Processor processor, ProcessorDefinition<?> 
definition, String id, String label,
             long timeTaken) {
     }
-
-    /**
-     * Gets the {@link TestExecutionConfiguration} test execution 
configuration instance for the test
-     *
-     * @return the configuration instance for the test
-     */
-    public final TestExecutionConfiguration testConfiguration() {
-        return testConfigurationBuilder;
-    }
-
-    /**
-     * Gets the {@link CamelContextConfiguration} for the test
-     *
-     * @return the camel context configuration
-     */
-    public final CamelContextConfiguration camelContextConfiguration() {
-        return camelContextConfiguration;
-    }
 }
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
new file mode 100644
index 00000000000..9b3660fc18a
--- /dev/null
+++ 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CommonTestSupport.java
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+import org.apache.camel.CamelContext;
+
+/**
+ * A common interface for tests that use the CamelContext.
+ */
+public interface CommonTestSupport {
+
+    /**
+     * Gets the {@link CamelContextConfiguration} for the test
+     *
+     * @return the camel context configuration
+     */
+    CamelContextConfiguration camelContextConfiguration();
+
+    /**
+     * 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/TestExecutionConfiguration.java
 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestExecutionConfiguration.java
index 0ccf7023e0d..8614e27f469 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
@@ -18,6 +18,7 @@
 package org.apache.camel.test.junit5;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.test.junit5.util.CamelContextTestHelper;
 
 /**
  * This configuration class allows tweaking how the test itself configured and 
enable/disable features that affect its
@@ -75,11 +76,20 @@ public class TestExecutionConfiguration {
         return this;
     }
 
+    /**
+     * Whether route coverage is enabled
+     *
+     * @return true if enabled or false otherwise
+     */
     public boolean isRouteCoverageEnabled() {
-        return Boolean.parseBoolean(
-                System.getProperty(CamelTestSupport.ROUTE_COVERAGE_ENABLED, 
"false")) || isDumpRouteCoverage();
+        return 
CamelContextTestHelper.isRouteCoverageEnabled(isDumpRouteCoverage());
     }
 
+    /**
+     * 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/TestSupport.java
 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestSupport.java
index e80e511e34d..e558cd37776 100644
--- 
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestSupport.java
+++ 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TestSupport.java
@@ -23,6 +23,7 @@ import java.nio.file.Path;
 import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import java.util.function.IntConsumer;
 
@@ -32,19 +33,26 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Message;
+import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.Predicate;
+import org.apache.camel.ProducerTemplate;
 import org.apache.camel.Route;
 import org.apache.camel.builder.Builder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.builder.ValueBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.spi.Debugger;
 import org.apache.camel.spi.FactoryFinder;
+import org.apache.camel.spi.Language;
 import org.apache.camel.support.DefaultExchange;
 import org.apache.camel.support.PredicateAssertHelper;
+import org.apache.camel.test.junit5.util.CamelContextTestHelper;
+import org.apache.camel.util.StringHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.test.junit5.util.ExtensionHelper.normalizeUri;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -243,6 +251,19 @@ public final class TestSupport {
         return actualValue;
     }
 
+    /**
+     * Asserts that the given language name and expression evaluates to the 
given value on a specific exchange
+     */
+    public static void assertExpression(
+            CamelContext context, Exchange exchange, String languageName, 
String expressionText, Object expectedValue) {
+        Language language = assertResolveLanguage(context, languageName);
+
+        Expression expression = language.createExpression(expressionText);
+        assertNotNull(expression, "No Expression could be created for text: " 
+ expressionText + " language: " + language);
+
+        assertExpression(expression, exchange, expectedValue);
+    }
+
     /**
      * Asserts that a given list has a single element.
      */
@@ -379,6 +400,30 @@ public final class TestSupport {
         assertFalse(file.exists(), "File " + filename + " should not exist");
     }
 
+    /**
+     * Asserts that the language name can be resolved
+     */
+    @Deprecated(since = "4.7.0")
+    public static Language assertResolveLanguage(CamelContext context, String 
languageName) {
+        Language language = context.resolveLanguage(languageName);
+        assertNotNull(language, "No language found for name: " + languageName);
+        return language;
+    }
+
+    /**
+     * Asserts that the given language name and predicate expression evaluates 
to the expected value on the message
+     * exchange
+     */
+    public static void assertPredicate(
+            CamelContext context, String languageName, String expressionText, 
Exchange exchange, boolean expected) {
+        Language language = assertResolveLanguage(context, languageName);
+
+        Predicate predicate = language.createPredicate(expressionText);
+        assertNotNull(predicate, "No Predicate could be created for text: " + 
expressionText + " language: " + language);
+
+        assertPredicate(predicate, exchange, expected);
+    }
+
     // -----------------------------------------------------------------------
     // Other helpers, resolution, file, getRouteList
     // -----------------------------------------------------------------------
@@ -597,4 +642,78 @@ public final class TestSupport {
             Thread.sleep(timeUnit.toMillis(interval));
         }
     }
+
+    public static <T extends Endpoint> T getMandatoryEndpoint(CamelContext 
context, String uri, Class<T> type) {
+        T endpoint = context.getEndpoint(uri, type);
+        assertNotNull(endpoint, "No endpoint found for uri: " + uri);
+        return endpoint;
+    }
+
+    public static Endpoint getMandatoryEndpoint(CamelContext context, String 
uri) {
+        Endpoint endpoint = context.getEndpoint(uri);
+        assertNotNull(endpoint, "No endpoint found for uri: " + uri);
+        return endpoint;
+    }
+
+    public static void sendBody(
+            ProducerTemplate template, String endpointUri, final Object body, 
final Map<String, Object> headers) {
+        template.send(endpointUri, exchange -> {
+            Message in = exchange.getIn();
+            in.setBody(body);
+            for (Map.Entry<String, Object> entry : headers.entrySet()) {
+                in.setHeader(entry.getKey(), entry.getValue());
+            }
+        });
+    }
+
+    /**
+     * Sends a message to the given endpoint URI with the body value
+     *
+     * @param endpointUri the URI of the endpoint to send to
+     * @param body        the body for the message
+     */
+    public static void sendBody(ProducerTemplate template, String endpointUri, 
final Object body) {
+        template.send(endpointUri, exchange -> {
+            Message in = exchange.getIn();
+            in.setBody(body);
+        });
+    }
+
+    /**
+     * Sends a message to the given endpoint URI with the body value
+     *
+     * @param template    the producer template to use to send the messages
+     * @param endpointUri the URI of the endpoint to send to
+     * @param bodies      the bodies for the message
+     */
+    public static void sendBodies(ProducerTemplate template, String 
endpointUri, Object... bodies) {
+        for (Object body : bodies) {
+            sendBody(template, endpointUri, body);
+        }
+    }
+
+    /**
+     * Resolves the {@link MockEndpoint} using a URI of the form 
<code>mock:someName</code>, optionally creating it if
+     * it does not exist. This implementation will lookup existing mock 
endpoints and match on the mock queue name, eg
+     * mock:foo and mock:foo?retainFirst=5 would match as the queue name is 
foo.
+     *
+     * @param  uri                     the URI which typically starts with 
"mock:" and has some name
+     * @param  create                  whether to allow the endpoint to be 
created if it doesn't exist
+     * @return                         the mock endpoint or an {@link 
NoSuchEndpointException} is thrown if it could not
+     *                                 be resolved
+     * @throws NoSuchEndpointException is the mock endpoint does not exist
+     */
+    public static MockEndpoint getMockEndpoint(CamelContext context, String 
uri, boolean create)
+            throws NoSuchEndpointException {
+        // look for existing mock endpoints that have the same queue name, and
+        // to
+        // do that we need to normalize uri and strip out query parameters and
+        // whatnot
+        final String normalizedUri = normalizeUri(uri);
+        // strip query
+        final String target = StringHelper.before(normalizedUri, "?", 
normalizedUri);
+
+        // lookup endpoints in registry and try to find it
+        return CamelContextTestHelper.lookupEndpoint(context, uri, create, 
target);
+    }
 }
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 27057c068d1..710ac7c7f63 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
@@ -44,6 +44,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class CamelContextTestHelper {
+    /**
+     * JVM system property which can be set to true to turn on dumping route 
coverage statistics.
+     */
+    public static final String ROUTE_COVERAGE_ENABLED = 
"CamelTestRouteCoverage";
+
     private static final Logger LOG = 
LoggerFactory.getLogger(CamelContextTestHelper.class);
 
     public static CamelContext createCamelContext(Registry registry) throws 
Exception {
@@ -235,4 +240,8 @@ public final class CamelContextTestHelper {
     public static boolean isSkipAutoStartContext(TestExecutionConfiguration 
configuration) {
         return 
Boolean.parseBoolean(System.getProperty("skipStartingCamelContext")) || 
!configuration.autoStartContext();
     }
+
+    public static boolean isRouteCoverageEnabled(boolean legacyDumpCoverage) {
+        return Boolean.parseBoolean(System.getProperty(ROUTE_COVERAGE_ENABLED, 
"false")) || legacyDumpCoverage;
+    }
 }
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 17928ba28d6..0047b74c6ad 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
@@ -21,6 +21,7 @@ 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.test.junit5.util.CamelContextTestHelper;
 import org.apache.camel.util.StopWatch;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.TimeUtils;
@@ -33,7 +34,6 @@ import org.junit.jupiter.api.extension.ExtensionContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static 
org.apache.camel.test.junit5.CamelTestSupport.ROUTE_COVERAGE_ENABLED;
 import static org.apache.camel.test.junit5.TestSupport.isCamelDebugPresent;
 import static 
org.junit.jupiter.api.extension.ExtensionContext.Namespace.create;
 
@@ -162,14 +162,14 @@ final class CamelMainExtension
 
     /**
      * 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.CamelTestSupport#ROUTE_COVERAGE_ENABLED}.
+     * system property {@link 
org.apache.camel.test.junit5.util.CamelContextTestHelper#ROUTE_COVERAGE_ENABLED}.
      * <p/>
      * In case of {@code @Nested} test classes, the value is always extracted 
from the annotation of the outer class.
      *
      * @return {@code true} if the route coverage is enabled, {@code false} 
otherwise.
      */
     private boolean isRouteCoverageEnabled(ExtensionContext context) {
-        return 
"true".equalsIgnoreCase(System.getProperty(ROUTE_COVERAGE_ENABLED, "false"))
+        return CamelContextTestHelper.isRouteCoverageEnabled(false)
                 || 
context.getRequiredTestInstances().getAllInstances().get(0).getClass()
                         
.getAnnotation(CamelMainTest.class).dumpRouteCoverage();
     }
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 0db5f23738c..b01e1d13957 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
@@ -36,7 +36,7 @@ import org.apache.camel.spi.Debugger;
 import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spring.SpringCamelContext;
-import org.apache.camel.test.junit5.CamelTestSupport;
+import org.apache.camel.test.junit5.util.CamelContextTestHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.config.BeanPostProcessor;
@@ -122,7 +122,7 @@ public final class CamelAnnotationsHandler {
     public static void handleRouteCoverage(ConfigurableApplicationContext 
context, Class<?> testClass, Function testMethod)
             throws Exception {
         if (testClass.isAnnotationPresent(EnableRouteCoverage.class)) {
-            System.setProperty(CamelTestSupport.ROUTE_COVERAGE_ENABLED, 
"true");
+            System.setProperty(CamelContextTestHelper.ROUTE_COVERAGE_ENABLED, 
"true");
 
             CamelSpringTestHelper.doToSpringCamelContexts(context, new 
CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {
 

Reply via email to