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
    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
    Factory method which derived classes can use to create a RouteBuilder to define the routes for testing
    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.
    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.
    protected void
    Deprecated.
    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

    • contextConfiguration

      CustomCamelContextConfiguration contextConfiguration()
    • testConfigurationBuilder

      CustomTestExecutionConfiguration testConfigurationBuilder()
    • 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
      Factory method which derived classes can use to create a RouteBuilder to define the routes for testing
      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.
      Override when using advice with and return true.

      Important: You must execute method startRouteDefinitions()} manually from the unit test after you are done doing all the advice with.

      Overrides:
      isUseAdviceWith in class org.apache.camel.test.junit6.AbstractTestSupport
      Returns:
      true to apply advice to existing route(s). false to disable advice.
    • startRouteDefinitions

      protected void startRouteDefinitions() throws Exception
      Helper method to start routeDefinitions (to be used with `adviceWith`).
      Throws:
      Exception
    • 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()
    • 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