Skip to content

Commit

Permalink
CAMEL-20785: cleanup startCamelContext and make reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
orpiske committed May 22, 2024
1 parent 5ea7d60 commit 2cd43d1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -698,18 +698,7 @@ private static void doStopTemplates(
}

protected void startCamelContext() throws Exception {
if (camelContextService != null) {
camelContextService.start();
} else {
if (context instanceof DefaultCamelContext) {
DefaultCamelContext defaultCamelContext = (DefaultCamelContext) context;
if (!defaultCamelContext.isStarted()) {
defaultCamelContext.start();
}
} else {
context.start();
}
}
CamelContextTestHelper.startCamelContextOrService(context, camelContextService);
}

protected CamelContext createCamelContext() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.RouteConfigurationsBuilder;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.Service;
import org.apache.camel.ServiceStatus;
import org.apache.camel.component.mock.InterceptSendToMockEndpointStrategy;
import org.apache.camel.component.mock.MockEndpoint;
Expand Down Expand Up @@ -170,4 +171,33 @@ public static void configureIncludeExcludePatterns(CamelContext context, String
context.getCamelContextExtension().getContextPlugin(Model.class).setRouteFilterPattern(include, exclude);
}
}

/**
* Start the given context
* @param context the context to start
* @throws Exception
*/
public static void startCamelContext(CamelContext context) throws Exception {
if (context instanceof DefaultCamelContext defaultCamelContext) {
if (!defaultCamelContext.isStarted()) {
defaultCamelContext.start();
}
} else {
context.start();
}
}

/**
* Starts a CamelContext or a service managing the CamelContext. The service takes priority if provided.
* @param context the context to start
* @param camelContextService the service managing the CamelContext
* @throws Exception
*/
public static void startCamelContextOrService(CamelContext context, Service camelContextService) throws Exception {
if (camelContextService != null) {
camelContextService.start();
} else {
CamelContextTestHelper.startCamelContext(context);
}
}
}

0 comments on commit 2cd43d1

Please sign in to comment.