Class CamelQuarkusTestSupport

java.lang.Object
org.apache.camel.test.junit6.AbstractTestSupport
org.apache.camel.quarkus.test.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

public class CamelQuarkusTestSupport extends org.apache.camel.test.junit6.AbstractTestSupport implements io.quarkus.test.junit.QuarkusTestProfile
The 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 CamelContext in 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 CamelContext is 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.TestProfile to 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, BeforeTestExecutionCallback and AfterTestExecutionCallback) might not work correctly. See the documentation. Methods afterAll, afterEach, afterTestExecution, beforeAll and beforeEach are not executed anymore. You should use doAfterAll, doAfterConstruct, doAfterEach, doBeforeEach and doBeforeAll instead of them.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.quarkus.test.junit.QuarkusTestProfile

    io.quarkus.test.junit.QuarkusTestProfile.TestResourceEntry
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.apache.camel.CamelContext
     

    Fields inherited from class org.apache.camel.test.junit6.AbstractTestSupport

    camelContextConfiguration, consumer, fluentTemplate, template, testConfigurationBuilder
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    adviceRoute(String routeId, org.apache.camel.util.function.ThrowingConsumer<org.apache.camel.builder.AdviceWithRouteBuilder,Exception> advice)
    Helper method to apply AdviceWith to a route.
    protected void
    bindToRegistry(org.apache.camel.spi.Registry registry)
    The same functionality as CamelTestSupport.bindToRegistry(Registry).
    protected org.apache.camel.CamelContext
    Feel free to override this method for the sake of customizing the instance returned by this implementation.
    void
    configureContext(org.apache.camel.test.junit6.CamelContextConfiguration camelContextConfiguration)
     
    void
    configureTest(org.apache.camel.test.junit6.TestExecutionConfiguration testExecutionConfiguration)
     
    org.apache.camel.CamelContext
    The same functionality as AbstractTestSupport.context() .
    protected org.apache.camel.RoutesBuilder
     
    protected org.apache.camel.RoutesBuilder[]
    Deprecated.
    This method will be made private.
    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.
    Use AbstractTestSupport.camelContextConfiguration() to set an instance of
    invalid reference
    DebugBreakpoint
    protected void
    debugBefore(org.apache.camel.Exchange exchange, org.apache.camel.Processor processor, org.apache.camel.model.ProcessorDefinition<?> definition, String id, String label)
    Deprecated.
    Use AbstractTestSupport.camelContextConfiguration() to set an instance of
    invalid reference
    DebugBreakpoint
    protected void
    doAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context)
    Replacement of
    invalid reference
    #afterAll(ExtensionContext)
    called from AfterAllCallback.afterAll(QuarkusTestContext)
    protected void
    Replacement of
    invalid reference
    #beforeAll(ExtensionContext)
    called from 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 void
    doAfterEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context)
    Replacement of
    invalid reference
    #afterEach(ExtensionContext)
    called from AfterEachCallback.afterEach(QuarkusTestMethodContext)
    protected void
    doBeforeEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context)
    Replacement of
    invalid reference
    #beforeEach(ExtensionContext)
    called from BeforeEachCallback.beforeEach(QuarkusTestMethodContext)
    protected void
    Deprecated.
    protected void
    Deprecated.
    use AbstractTestSupport.cleanupResources() instead.
    protected void
    Deprecated.
    (package private) Set<String>
     
    final String
    Gets the name of the current test being executed.
    (package private) Set<String>
     
    protected final org.apache.camel.component.mock.MockEndpoint
    Resolves the mandatory Mock endpoint using a URI of the form mock:someName
    protected final org.apache.camel.component.mock.MockEndpoint
    getMockEndpoint(String uri, boolean create)
    Deprecated.
    (package private) void
     
    (package private) void
     
    (package private) void
     
    boolean
    Deprecated.
    While this method works, it has fundamental lifecycle limitations in Camel Quarkus due to the build-time context assembly.
    protected void
    Deprecated.
    (package private) void
    Restores routes to their original state by resetting outputs that were modified by AdviceWith.
    void
    Deprecated.
    Use AbstractTestSupport.setupResources() instead
    protected void
    Helper method to start routeDefinitions (to be used with `adviceWith`).
    void
    Deprecated.
    Use AbstractTestSupport.cleanupResources() instead
    long
    Deprecated.

    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, useOverridePropertiesWithPropertiesComponent

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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 of
      invalid reference
      #afterAll(ExtensionContext)
      called from AfterAllCallback.afterAll(QuarkusTestContext)
      Throws:
      Exception
    • doAfterEach

      protected void doAfterEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) throws Exception
      Replacement of
      invalid reference
      #afterEach(ExtensionContext)
      called from AfterEachCallback.afterEach(QuarkusTestMethodContext)
      Throws:
      Exception
    • doAfterConstruct

      protected void doAfterConstruct() throws Exception
      Replacement of
      invalid reference
      #beforeAll(ExtensionContext)
      called from 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 of
      invalid reference
      #beforeEach(ExtensionContext)
      called from BeforeEachCallback.beforeEach(QuarkusTestMethodContext)
      Throws:
      Exception
    • camelContextSupplier

      protected org.apache.camel.CamelContext camelContextSupplier() throws Exception
      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

      protected void bindToRegistry(org.apache.camel.spi.Registry registry) throws Exception
      The same functionality as CamelTestSupport.bindToRegistry(Registry).
      Throws:
      Exception
    • postProcessTest

      @Deprecated(since="3.15.0") protected void postProcessTest() throws Exception
      Deprecated.
      The same functionality as CamelTestSupport.postProcessTest() .
      Throws:
      Exception
    • context

      public org.apache.camel.CamelContext context()
      The same functionality as AbstractTestSupport.context() .
      Overrides:
      context in class org.apache.camel.test.junit6.AbstractTestSupport
    • timeTaken

      @Deprecated(since="3.15.0") public long timeTaken()
      Deprecated.
    • getCurrentTestName

      public final String getCurrentTestName()
      Gets the name of the current test being executed.
    • setUp

      @Deprecated(since="3.15.0") public void setUp() throws Exception
      Deprecated.
      Use AbstractTestSupport.setupResources() instead
      Common test setup. For internal use.
      Throws:
      Exception - if unable to setup the test
    • tearDown

      @Deprecated(since="3.15.0") public void tearDown() throws Exception
      Deprecated.
      Use AbstractTestSupport.cleanupResources() instead
      Common test tear down. For internal use.
      Throws:
      Exception - if unable to setup the test
    • doPostTearDown

      @Deprecated(since="3.15.0") protected void doPostTearDown() throws Exception
      Deprecated.
      use AbstractTestSupport.cleanupResources() instead.
      Strategy to perform any post-action, after CamelContext is stopped. This is meant for internal Camel usage and should not be used by user classes.
      Throws:
      Exception
    • createRouteBuilder

      protected org.apache.camel.RoutesBuilder createRouteBuilder() throws Exception
      Throws:
      Exception
    • createRouteBuilders

      @Deprecated(since="3.15.0") protected org.apache.camel.RoutesBuilder[] createRouteBuilders() throws Exception
      Deprecated.
      This method will be made private. Do not use
      Factory method which derived classes can use to create an array of RouteBuilders to define the routes for testing
      Throws:
      Exception
      See Also:
    • internalAfterAll

      void internalAfterAll()
    • internalBeforeAll

      void internalBeforeAll(CallbackUtil.MockExtensionContext context)
    • internalBeforeEach

      void internalBeforeEach(CallbackUtil.MockExtensionContext context) throws Exception
      Throws:
      Exception
    • doPreSetup

      @Deprecated(since="3.15.0") protected void doPreSetup() throws Exception
      Deprecated.
      Strategy to perform any pre setup, before the CamelContext is 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(since="3.15.0") protected void doPostSetup() throws Exception
      Deprecated.
      Strategy to perform any post setup after the CamelContext is 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(since="3.15.0") public boolean 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 in doBeforeEach(QuarkusTestMethodContext). Advice cleanup between tests and automatic route starting happen automatically regardless of which approach you use.
      Override when using advice with and return true.

      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

      Workaround for Auto-Starting Routes: If routes must not start (e.g., to avoid connection attempts), use autoStartup=false in your route definition or via properties (e.g., quarkus.camel.routes.auto-startup=false). When using this deprecated approach, you must manually call startRouteDefinitions() after applying advice.

      Recommended Approach: Instead of using this flag, apply advice in doBeforeEach(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 after doBeforeEach() completes. Note that the fundamental build-time limitation still applies.

      Overrides:
      isUseAdviceWith in class org.apache.camel.test.junit6.AbstractTestSupport
      Returns:
      true to suspend context during setup for applying advice. false to disable.
    • startRouteDefinitions

      protected void startRouteDefinitions() throws Exception
      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 in doBeforeEach(QuarkusTestMethodContext), route definitions are automatically started after doBeforeEach() 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 @BeforeEach methods 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 Exception
      Helper 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:

      1. Stops the route
      2. Applies the advice
      3. 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

      protected final org.apache.camel.component.mock.MockEndpoint getMockEndpoint(String uri)
      Resolves the mandatory Mock endpoint using a URI of the form mock: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 the MockEndpoint using a URI of the form mock: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 name
      create - whether to allow the endpoint to be created if it doesn't exist
      Returns:
      the mock endpoint or an NoSuchEndpointException is 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.
      Use AbstractTestSupport.camelContextConfiguration() to set an instance of
      invalid reference
      DebugBreakpoint
      Single 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.
      Use AbstractTestSupport.camelContextConfiguration() to set an instance of
      invalid reference
      DebugBreakpoint
      Single step debugs and Camel invokes this method after processing the given processor. This method is NOOP.
    • getCreatedRoutes

      Set<String> getCreatedRoutes()
    • getExistingComponents

      Set<String> 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:
      configureContext in interface org.apache.camel.test.junit6.ConfigurableContext
    • configureTest

      public void configureTest(org.apache.camel.test.junit6.TestExecutionConfiguration testExecutionConfiguration)
      Specified by:
      configureTest in interface org.apache.camel.test.junit6.ConfigurableTest