Class CamelQuarkusTestSupport
- All Implemented Interfaces:
io.quarkus.test.junit.QuarkusTestProfile,org.apache.camel.test.junit6.CommonTestSupport,org.apache.camel.test.junit6.ConfigurableContext,org.apache.camel.test.junit6.ConfigurableTest
CamelTestSupport class does not work on Quarkus. This class provides a replacement, which can be used in
JVM mode. Note that CamelQuarkusTestSupport DOES NOT work for native mode tests.
There are several differences between CamelTestSupport and this class.
- Starting and stopping
CamelContextin Camel Quarkus is generally bound to starting and stopping the application and this holds also when testing. - Starting and stopping the application under test (and thus also
CamelContextis under full control of Quarkus JUnit Extension. It prefers keeping the application up and running unless it is told to do otherwise. - Hence normally the application under test is started only once for all test classes of the given Maven/Gradle module.
- To force Quarkus JUnit Extension to restart the application (and thus also `CamelContext`) for a given test
class, you need to assign a unique
@io.quarkus.test.junit.TestProfileto that class. Check the Quarkus documentation for how you can do that. (Note that QuarkusTestResource has a similar effect.) - Camel Quarkus executes the production of beans during the build phase. Because all the tests are
build together, exclusion behavior is implemented into
CamelQuarkusTestSupport. If a producer of the specific type and name is used in one tests, the instance will be the same for the rest of the tests. - JUnit Jupiter callbacks
BeforeEachCallback,AfterEachCallback,AfterAllCallback,BeforeAllCallback,BeforeTestExecutionCallbackandAfterTestExecutionCallback) might not work correctly. See the documentation. MethodsafterAll,afterEach,afterTestExecution,beforeAllandbeforeEachare not executed anymore. You should usedoAfterAll,doAfterConstruct,doAfterEach,doBeforeEachanddoBeforeAllinstead of them.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.quarkus.test.junit.QuarkusTestProfile
io.quarkus.test.junit.QuarkusTestProfile.TestResourceEntry -
Field Summary
FieldsFields inherited from class org.apache.camel.test.junit6.AbstractTestSupport
camelContextConfiguration, consumer, fluentTemplate, template, testConfigurationBuilder -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidadviceRoute(String routeId, org.apache.camel.util.function.ThrowingConsumer<org.apache.camel.builder.AdviceWithRouteBuilder, Exception> advice) Helper method to apply AdviceWith to a route.protected voidbindToRegistry(org.apache.camel.spi.Registry registry) The same functionality asCamelTestSupport.bindToRegistry(Registry).protected org.apache.camel.CamelContextFeel free to override this method for the sake of customizing the instance returned by this implementation.voidconfigureContext(org.apache.camel.test.junit6.CamelContextConfiguration camelContextConfiguration) voidconfigureTest(org.apache.camel.test.junit6.TestExecutionConfiguration testExecutionConfiguration) org.apache.camel.CamelContextcontext()The same functionality asAbstractTestSupport.context().protected org.apache.camel.RoutesBuilderprotected org.apache.camel.RoutesBuilder[]Deprecated.This method will be made private.protected voiddebugAfter(org.apache.camel.Exchange exchange, org.apache.camel.Processor processor, org.apache.camel.model.ProcessorDefinition<?> definition, String id, String label, long timeTaken) Deprecated.UseAbstractTestSupport.camelContextConfiguration()to set an instance ofinvalid reference
DebugBreakpointprotected voiddebugBefore(org.apache.camel.Exchange exchange, org.apache.camel.Processor processor, org.apache.camel.model.ProcessorDefinition<?> definition, String id, String label) Deprecated.UseAbstractTestSupport.camelContextConfiguration()to set an instance ofinvalid reference
DebugBreakpointprotected voiddoAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context) Replacement ofcalled frominvalid reference
#afterAll(ExtensionContext)AfterAllCallback.afterAll(QuarkusTestContext)protected voidReplacement ofcalled frominvalid reference
#beforeAll(ExtensionContext)AfterConstructCallback.afterConstruct(Object)Execution differs in case of @TestInstance(TestInstance.Lifecycle.PER_METHOD). in which case a callback is invoked before each test (instead of).invalid reference
#beforeAll(ExtensionContext)protected voiddoAfterEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) Replacement ofcalled frominvalid reference
#afterEach(ExtensionContext)AfterEachCallback.afterEach(QuarkusTestMethodContext)protected voiddoBeforeEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) Replacement ofcalled frominvalid reference
#beforeEach(ExtensionContext)BeforeEachCallback.beforeEach(QuarkusTestMethodContext)protected voidDeprecated.protected voidDeprecated.useAbstractTestSupport.cleanupResources()instead.protected voidDeprecated.final StringGets the name of the current test being executed.protected final org.apache.camel.component.mock.MockEndpointgetMockEndpoint(String uri) Resolves the mandatory Mock endpoint using a URI of the formmock:someNameprotected final org.apache.camel.component.mock.MockEndpointgetMockEndpoint(String uri, boolean create) Deprecated.(package private) void(package private) void(package private) voidbooleanDeprecated.While this method works, it has fundamental lifecycle limitations in Camel Quarkus due to the build-time context assembly.protected voidDeprecated.(package private) voidRestores routes to their original state by resetting outputs that were modified by AdviceWith.voidsetUp()Deprecated.UseAbstractTestSupport.setupResources()insteadprotected voidHelper method to start routeDefinitions (to be used with `adviceWith`).voidtearDown()Deprecated.UseAbstractTestSupport.cleanupResources()insteadlongDeprecated.Methods inherited from class org.apache.camel.test.junit6.AbstractTestSupport
camelContextConfiguration, camelContextService, cleanupResources, consumer, disableJMX, enableJMX, fluentTemplate, getCamelContextService, getDumpRoute, getRouteFilterExcludePattern, getRouteFilterIncludePattern, ignoreMissingLocationWithPropertiesComponent, isAutoStartupExcludePatterns, isCreateCamelContextPerClass, isDumpRouteCoverage, isMockEndpoints, isMockEndpointsAndSkip, isRouteCoverageEnabled, isStubEndpoints, isUseDebugger, isUseRouteBuilder, replaceRouteFromWith, setCamelContextService, setContext, setupResources, setUseRouteBuilder, template, testConfiguration, useJmx, useOverridePropertiesWithPropertiesComponentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.quarkus.test.junit.QuarkusTestProfile
commandLineParameters, disableApplicationLifecycleObservers, disableGlobalTestResources, getConfigOverrides, getConfigProfile, getEnabledAlternatives, runMainMethod, tags, testResources
-
Field Details
-
context
@Inject protected org.apache.camel.CamelContext context
-
-
Constructor Details
-
CamelQuarkusTestSupport
public CamelQuarkusTestSupport()
-
-
Method Details
-
doAfterAll
protected void doAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context) throws Exception Replacement ofcalled frominvalid reference
#afterAll(ExtensionContext)AfterAllCallback.afterAll(QuarkusTestContext)- Throws:
Exception
-
doAfterEach
protected void doAfterEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) throws Exception Replacement ofcalled frominvalid reference
#afterEach(ExtensionContext)AfterEachCallback.afterEach(QuarkusTestMethodContext)- Throws:
Exception
-
doAfterConstruct
Replacement ofcalled frominvalid reference
#beforeAll(ExtensionContext)AfterConstructCallback.afterConstruct(Object)Execution differs in case of @TestInstance(TestInstance.Lifecycle.PER_METHOD). in which case a callback is invoked before each test (instead of).invalid reference
#beforeAll(ExtensionContext)- Throws:
Exception
-
doBeforeEach
protected void doBeforeEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) throws Exception Replacement ofcalled frominvalid reference
#beforeEach(ExtensionContext)BeforeEachCallback.beforeEach(QuarkusTestMethodContext)- Throws:
Exception
-
camelContextSupplier
Feel free to override this method for the sake of customizing the instance returned by this implementation. Do not create your own CamelContext instance, because there needs to exist just a single instance owned by Quarkus CDI container. There are checks in place that will make your tests fail if you do otherwise.- Returns:
- The context from Quarkus CDI container
- Throws:
Exception- Overridden method has to throw the same Exception as superclass.
-
bindToRegistry
The same functionality asCamelTestSupport.bindToRegistry(Registry).- Throws:
Exception
-
postProcessTest
Deprecated.The same functionality asCamelTestSupport.postProcessTest().- Throws:
Exception
-
context
public org.apache.camel.CamelContext context()The same functionality asAbstractTestSupport.context().- Overrides:
contextin classorg.apache.camel.test.junit6.AbstractTestSupport
-
timeTaken
Deprecated. -
getCurrentTestName
Gets the name of the current test being executed. -
setUp
Deprecated.UseAbstractTestSupport.setupResources()insteadCommon test setup. For internal use.- Throws:
Exception- if unable to setup the test
-
tearDown
Deprecated.UseAbstractTestSupport.cleanupResources()insteadCommon test tear down. For internal use.- Throws:
Exception- if unable to setup the test
-
doPostTearDown
Deprecated.useAbstractTestSupport.cleanupResources()instead.Strategy to perform any post-action, afterCamelContextis stopped. This is meant for internal Camel usage and should not be used by user classes.- Throws:
Exception
-
createRouteBuilder
- Throws:
Exception
-
createRouteBuilders
@Deprecated(since="3.15.0") protected org.apache.camel.RoutesBuilder[] createRouteBuilders() throws ExceptionDeprecated.This method will be made private. Do not useFactory method which derived classes can use to create an array ofRouteBuilders to define the routes for testing- Throws:
Exception- See Also:
-
internalAfterAll
void internalAfterAll() -
internalBeforeAll
-
internalBeforeEach
- Throws:
Exception
-
doPreSetup
Deprecated.Strategy to perform any pre setup, before theCamelContextis created.Be aware that difference in lifecycle with Quarkus may require special behavior. If this method is overridden, super.doPreSetup() must be called.
- Throws:
Exception
-
doPostSetup
Deprecated.Strategy to perform any post setup after theCamelContextis created.Be aware that difference in lifecycle with Quarkus may require special behavior. If this method is overridden, super.doPostSetup() must be called.
- Throws:
Exception
-
isUseAdviceWith
Deprecated.While this method works, it has fundamental lifecycle limitations in Camel Quarkus due to the build-time context assembly. The recommended approach is to apply advice indoBeforeEach(QuarkusTestMethodContext). Advice cleanup between tests and automatic route starting happen automatically regardless of which approach you use.Override when using advice with and returntrue. Advice Cleanup: AdviceWith modifications are automatically cleaned up between test methods. This ensures that advice applied in one test does not persist to subsequent tests, preventing interference between tests. Fundamental Limitation: In Camel Quarkus, the CamelContext is assembled at build time and shared across all tests in a module. Unlike standalone Camel or Spring Boot (where the context can be manually started in each test), you cannot replay the build steps to get a fresh context. This means:- Routes may have already auto-started before advice can be applied
- Routes that connect to external systems (Kafka, JMS, etc.) may briefly attempt to connect before being suspended
- The context cannot be fully recreated between tests without using different
@TestProfiles
autoStartup=falsein your route definition or via properties (e.g.,quarkus.camel.routes.auto-startup=false). When using this deprecated approach, you must manually callstartRouteDefinitions()after applying advice. Recommended Approach: Instead of using this flag, apply advice indoBeforeEach(QuarkusTestMethodContext). This approach is simpler and works reliably for both routes defined in the test class and global routes (YAML routes or RouteBuilder beans). Routes that aren't advised will be automatically started afterdoBeforeEach()completes. Note that the fundamental build-time limitation still applies.- Overrides:
isUseAdviceWithin classorg.apache.camel.test.junit6.AbstractTestSupport- Returns:
trueto suspend context during setup for applying advice.falseto disable.
-
startRouteDefinitions
Helper method to start routeDefinitions (to be used with `adviceWith`).Note: This method is only necessary when using the deprecated
isUseAdviceWith()approach. If you apply AdviceWith indoBeforeEach(QuarkusTestMethodContext), route definitions are automatically started afterdoBeforeEach()completes, so you don't need to call this method.When using
isUseAdviceWith() = true, you must still call this method manually after applying advice in your@BeforeEachmethods to start routes that weren't advised.- Throws:
Exception- if unable to start route definitions
-
adviceRoute
protected void adviceRoute(String routeId, org.apache.camel.util.function.ThrowingConsumer<org.apache.camel.builder.AdviceWithRouteBuilder, Exception> advice) throws ExceptionHelper method to apply AdviceWith to a route.This method should be used to advise routes that already exist in your application code (src/main/java), and NOT routes created via
createRouteBuilder()in your test class. Advising test-created routes can cause unpredictable behavior.This method handles the route lifecycle automatically:
- Stops the route
- Applies the advice
- Starts the route
You can use this when you need different advice per test method on existing routes
Example - advising existing application route:
@code @QuarkusTest public class MyRouteTest extends CamelQuarkusTestSupport {- Parameters:
routeId- the ID of the EXISTING route to advise (must be from application code, not test)advice- the AdviceWith configuration- Throws:
Exception- if unable to apply advice or manage route lifecycle- See Also:
-
getMockEndpoint
Resolves the mandatory Mock endpoint using a URI of the formmock:someName- Parameters:
uri- the URI which typically starts with "mock:" and has some name- Returns:
- the mandatory mock endpoint or an exception is thrown if it could not be resolved
-
getMockEndpoint
@Deprecated(since="3.15.0") protected final org.apache.camel.component.mock.MockEndpoint getMockEndpoint(String uri, boolean create) throws org.apache.camel.NoSuchEndpointException Deprecated.Resolves theMockEndpointusing a URI of the formmock:someName, 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.- Parameters:
uri- the URI which typically starts with "mock:" and has some namecreate- whether to allow the endpoint to be created if it doesn't exist- Returns:
- the mock endpoint or an
NoSuchEndpointExceptionis thrown if it could not be resolved - Throws:
org.apache.camel.NoSuchEndpointException- is the mock endpoint does not exist
-
debugBefore
@Deprecated(since="3.15.0") protected void debugBefore(org.apache.camel.Exchange exchange, org.apache.camel.Processor processor, org.apache.camel.model.ProcessorDefinition<?> definition, String id, String label) Deprecated.UseAbstractTestSupport.camelContextConfiguration()to set an instance ofinvalid reference
DebugBreakpointSingle step debugs and Camel invokes this method before entering the given processor. This method is NOOP. -
debugAfter
@Deprecated(since="3.15.0") protected void debugAfter(org.apache.camel.Exchange exchange, org.apache.camel.Processor processor, org.apache.camel.model.ProcessorDefinition<?> definition, String id, String label, long timeTaken) Deprecated.UseAbstractTestSupport.camelContextConfiguration()to set an instance ofinvalid reference
DebugBreakpointSingle step debugs and Camel invokes this method after processing the given processor. This method is NOOP. -
getCreatedRoutes
-
getExistingComponents
-
restoreOriginalRouteDefinitions
void restoreOriginalRouteDefinitions()Restores routes to their original state by resetting outputs that were modified by AdviceWith. This is called after each test to ensure advice doesn't persist across tests. -
configureContext
public void configureContext(org.apache.camel.test.junit6.CamelContextConfiguration camelContextConfiguration) - Specified by:
configureContextin interfaceorg.apache.camel.test.junit6.ConfigurableContext
-
configureTest
public void configureTest(org.apache.camel.test.junit6.TestExecutionConfiguration testExecutionConfiguration) - Specified by:
configureTestin interfaceorg.apache.camel.test.junit6.ConfigurableTest
-