You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2024/05/23 07:48:29 UTC
(camel) 11/11: CAMEL-20785: move replaceFromEndpoints and make reusable
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 03c3f9987eb0890867a9032467e3de41902040fc
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed May 22 13:48:25 2024 +0200
CAMEL-20785: move replaceFromEndpoints and make reusable
---
.../apache/camel/test/junit5/CamelTestSupport.java | 17 ++---------------
.../test/junit5/util/CamelContextTestHelper.java | 22 ++++++++++++++++++++++
2 files changed, 24 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 e4ac89e944a..cda6d716887 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
@@ -34,8 +34,6 @@ 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.AdviceWith;
-import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.DefaultCamelContext;
@@ -459,7 +457,7 @@ public abstract class CamelTestSupport
tryStartCamelContext();
} else {
- replaceFromEndpoints();
+ CamelContextTestHelper.replaceFromEndpoints(context, fromEndpoints);
LOG.debug("Using route builder from the created context: {}", context);
}
LOG.debug("Routing Rules are: {}", context.getRoutes());
@@ -483,7 +481,7 @@ public abstract class CamelTestSupport
CamelContextTestHelper.setupRoutes(context, builders);
- replaceFromEndpoints();
+ CamelContextTestHelper.replaceFromEndpoints(context, fromEndpoints);
}
private void tryStartCamelContext() throws Exception {
@@ -513,17 +511,6 @@ public abstract class CamelTestSupport
CamelContextTestHelper.configurePropertiesComponent(context, extra, new JunitPropertiesSource(globalStore), ignore);
}
- private void replaceFromEndpoints() throws Exception {
- for (final Map.Entry<String, String> entry : fromEndpoints.entrySet()) {
- AdviceWith.adviceWith(context.getRouteDefinition(entry.getKey()), context, new AdviceWithRouteBuilder() {
- @Override
- public void configure() {
- replaceFromWith(entry.getValue());
- }
- });
- }
- }
-
private boolean isRouteCoverageEnabled() {
return Boolean.parseBoolean(System.getProperty(ROUTE_COVERAGE_ENABLED, "false")) || isDumpRouteCoverage();
}
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 16a88ff0778..584860090f0 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
@@ -17,6 +17,7 @@
package org.apache.camel.test.junit5.util;
+import java.util.Map;
import java.util.Properties;
import org.apache.camel.CamelContext;
@@ -25,11 +26,14 @@ import org.apache.camel.RouteConfigurationsBuilder;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.Service;
import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.AdviceWith;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
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.model.Model;
+import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.spi.Breakpoint;
import org.apache.camel.spi.PropertiesComponent;
import org.apache.camel.spi.PropertiesSource;
@@ -208,4 +212,22 @@ public final class CamelContextTestHelper {
CamelContextTestHelper.startCamelContext(context);
}
}
+
+ /**
+ * Replaces the 'from' endpoints of the given context with the ones from the provided map
+ *
+ * @param context the context to have the 'from' endpoints replaced
+ * @param fromEndpoints the map with the new endpoint Uris
+ * @throws Exception
+ */
+ public static void replaceFromEndpoints(ModelCamelContext context, Map<String, String> fromEndpoints) throws Exception {
+ for (final Map.Entry<String, String> entry : fromEndpoints.entrySet()) {
+ AdviceWith.adviceWith(context.getRouteDefinition(entry.getKey()), context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() {
+ replaceFromWith(entry.getValue());
+ }
+ });
+ }
+ }
}