Skip to content

Commit

Permalink
CAMEL-20785: move replaceFromEndpoints and make reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
orpiske committed May 22, 2024
1 parent 2cd43d1 commit 475fd39
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
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;
Expand Down Expand Up @@ -459,7 +457,7 @@ protected void doSetUp() throws Exception {

tryStartCamelContext();
} else {
replaceFromEndpoints();
CamelContextTestHelper.replaceFromEndpoints(context, fromEndpoints);
LOG.debug("Using route builder from the created context: {}", context);
}
LOG.debug("Routing Rules are: {}", context.getRoutes());
Expand All @@ -483,7 +481,7 @@ private void setupRoutes() throws Exception {

CamelContextTestHelper.setupRoutes(context, builders);

replaceFromEndpoints();
CamelContextTestHelper.replaceFromEndpoints(context, fromEndpoints);
}

private void tryStartCamelContext() throws Exception {
Expand Down Expand Up @@ -513,17 +511,6 @@ private void configurePropertiesComponent() {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.camel.test.junit5.util;

import java.util.Map;
import java.util.Properties;

import org.apache.camel.CamelContext;
Expand All @@ -25,11 +26,14 @@
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;
Expand Down Expand Up @@ -200,4 +204,21 @@ public static void startCamelContextOrService(CamelContext context, Service came
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());
}
});
}
}
}

0 comments on commit 475fd39

Please sign in to comment.