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

commit dddb0bf49e387cf9900f6f3f0e8ea19af02e68d7
Author: Otavio Rodolfo Piske <angusyo...@gmail.com>
AuthorDate: Wed May 22 13:13:24 2024 +0200

    CAMEL-20785: move enableAutoMocking and make reusable
---
 .../apache/camel/test/junit5/CamelTestSupport.java  | 16 +---------------
 .../test/junit5/util/CamelContextTestHelper.java    | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 15 deletions(-)

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 ed1143855c1..a445b28e65b 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
@@ -37,7 +37,6 @@ import org.apache.camel.Service;
 import org.apache.camel.builder.AdviceWith;
 import org.apache.camel.builder.AdviceWithRouteBuilder;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.InterceptSendToMockEndpointStrategy;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.model.Model;
@@ -446,7 +445,7 @@ public abstract class CamelTestSupport
         setupTemplates();
 
         // enable auto mocking if enabled
-        enableAutoMocking();
+        CamelContextTestHelper.enableAutoMocking(context, isMockEndpoints(), 
isMockEndpointsAndSkip());
 
         // configure properties component (mandatory for testing)
         configurePropertiesComponent();
@@ -523,19 +522,6 @@ public abstract class CamelTestSupport
         }
     }
 
-    private void enableAutoMocking() {
-        final String pattern = isMockEndpoints();
-        if (pattern != null) {
-            context.getCamelContextExtension()
-                    .registerEndpointCallback(new 
InterceptSendToMockEndpointStrategy(pattern));
-        }
-        final String mockAndSkipPattern = isMockEndpointsAndSkip();
-        if (mockAndSkipPattern != null) {
-            context.getCamelContextExtension()
-                    .registerEndpointCallback(new 
InterceptSendToMockEndpointStrategy(mockAndSkipPattern, true));
-        }
-    }
-
     private void replaceFromEndpoints() throws Exception {
         for (final Map.Entry<String, String> entry : fromEndpoints.entrySet()) 
{
             AdviceWith.adviceWith(context.getRouteDefinition(entry.getKey()), 
context, new AdviceWithRouteBuilder() {
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 6c9fb220e39..73e341af417 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
@@ -22,11 +22,14 @@ import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.RouteConfigurationsBuilder;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.ServiceStatus;
+import org.apache.camel.component.mock.InterceptSendToMockEndpointStrategy;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.debugger.DefaultDebugger;
 import org.apache.camel.spi.Breakpoint;
+import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spi.Registry;
+import org.apache.camel.test.junit5.JunitPropertiesSource;
 import org.apache.camel.test.junit5.TestSupport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -118,4 +121,22 @@ public final class CamelContextTestHelper {
             throw new NoSuchEndpointException(String.format("MockEndpoint %s 
does not exist.", uri));
         }
     }
+
+    /**
+     * Enables auto mocking
+     *
+     * @param context
+     * @param pattern
+     * @param mockAndSkipPattern
+     */
+    public static void enableAutoMocking(CamelContext context, String pattern, 
String mockAndSkipPattern) {
+        if (pattern != null) {
+            context.getCamelContextExtension()
+                    .registerEndpointCallback(new 
InterceptSendToMockEndpointStrategy(pattern));
+        }
+        if (mockAndSkipPattern != null) {
+            context.getCamelContextExtension()
+                    .registerEndpointCallback(new 
InterceptSendToMockEndpointStrategy(mockAndSkipPattern, true));
+        }
+    }
 }

Reply via email to