Class CamelQuarkusTestSupport

java.lang.Object
org.apache.camel.test.junit5.CamelTestSupport
org.apache.camel.quarkus.test.CamelQuarkusTestSupport
All Implemented Interfaces:
io.quarkus.test.junit.QuarkusTestProfile, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.BeforeTestExecutionCallback, org.junit.jupiter.api.extension.Extension

public class CamelQuarkusTestSupport extends org.apache.camel.test.junit5.CamelTestSupport 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. 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
     
    (package private) Set<String>
     

    Fields inherited from class org.apache.camel.test.junit5.CamelTestSupport

    camelContextService, camelTestSupportExtension, consumer, extra, fluentTemplate, ROUTE_COVERAGE_ENABLED, template
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
    This method does nothing.
    final void
    afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
    This method does nothing.
    final void
    afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context)
    This method does nothing All necessary tasks are performed in BeforeEachCallback.beforeEach(QuarkusTestMethodContext) Use doAfterEach(QuarkusTestMethodContext) instead of this method.
    final void
    beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
    This method does nothing.
    final void
    beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
    This method does nothing.
    protected void
    bindToRegistry(org.apache.camel.spi.Registry registry)
    The same functionality as CamelTestSupport.bindToRegistry(Registry).
    org.apache.camel.CamelContext
    The same functionality as CamelTestSupport.context() .
    protected org.apache.camel.CamelContext
    Feel free to override this method for the sake of customizing the instance returned by this implementation.
    protected final org.apache.camel.spi.Registry
    This method is not called on Camel Quarkus because the `CamelRegistry` is created and owned by Quarkus CDI container.
    protected void
    doAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context)
    protected void
    Replacement of beforeAll(ExtensionContext) called from AfterConstructCallback.afterConstruct(Object) Execution differs in case of @TestInstance(TestInstance.Lifecycle.PER_METHOD) in which case callback is called before each test (instead of beforeAll(ExtensionContext)).
    protected void
    doAfterEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context)
    protected void
    doBeforeEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context)
    protected void
    Strategy to perform any post setup after CamelContext is created
    protected void
    Strategy to perform any pre setup, before CamelContext is created
    protected final void
    Allows running of the CamelTestSupport child in the Quarkus application.
    protected final void
    doStopCamelContext(org.apache.camel.CamelContext context, org.apache.camel.Service camelContextService)
    Internal disablement of the context stop functionality.
    (package private) void
    internalAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     
    (package private) void
    internalBeforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
    (package private) void
    internalBeforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
     
    boolean
    Override when using advice with and return true.
    protected void
    The same functionality as CamelTestSupport.postProcessTest() .
    void
    Method CamelTestSupport.setUp() is triggered via annotation BeforeEach.
    protected final void
    This method does nothing.
    protected void
    Helper method to start routeDefinitions (to be used with `adviceWith`).
    protected void
    This method stops the Camel context.
    void
    Method CamelTestSupport.tearDown() is triggered via annotation AfterEach.

    Methods inherited from class org.apache.camel.test.junit5.CamelTestSupport

    applyCamelPostProcessor, assertExpression, assertPredicate, assertResolveLanguage, assertValidContext, beforeTestExecution, camelContextService, cleanupResources, consumer, createExchangeWithBody, createRouteBuilder, createRouteBuilders, debugAfter, debugBefore, disableJMX, doPostTearDown, doSetUp, doSpringBootCheck, enableJMX, fluentTemplate, getCamelContextService, getCurrentTestName, getMandatoryEndpoint, getMandatoryEndpoint, getMockEndpoint, getMockEndpoint, getRouteFilterExcludePattern, getRouteFilterIncludePattern, getShutdownTimeout, hasClassAnnotation, ignoreMissingLocationWithPropertiesComponent, isCreateCamelContextPerClass, isDumpRouteCoverage, isMockEndpoints, isMockEndpointsAndSkip, isUseDebugger, isUseRouteBuilder, replaceRouteFromWith, resolveMandatoryEndpoint, resolveMandatoryEndpoint, sendBodies, sendBody, sendBody, setCamelContextService, setupResources, setUseRouteBuilder, template, timeTaken, 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
    • createdRoutes

      Set<String> createdRoutes
  • Constructor Details

    • CamelQuarkusTestSupport

      public CamelQuarkusTestSupport()
  • Method Details

    • doAfterAll

      protected void doAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context) throws Exception
      Throws:
      Exception
    • doAfterEach

      protected void doAfterEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) throws Exception
      Throws:
      Exception
    • doAfterConstruct

      protected void doAfterConstruct() throws Exception
      Replacement of beforeAll(ExtensionContext) called from AfterConstructCallback.afterConstruct(Object) Execution differs in case of @TestInstance(TestInstance.Lifecycle.PER_METHOD) in which case callback is called before each test (instead of beforeAll(ExtensionContext)).
      Throws:
      Exception
    • doBeforeEach

      protected void doBeforeEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) throws Exception
      Throws:
      Exception
    • createCamelContext

      protected org.apache.camel.CamelContext createCamelContext() 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.
      Overrides:
      createCamelContext in class org.apache.camel.test.junit5.CamelTestSupport
      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).
      Overrides:
      bindToRegistry in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • postProcessTest

      protected void postProcessTest() throws Exception
      The same functionality as CamelTestSupport.postProcessTest() .
      Overrides:
      postProcessTest in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • context

      public org.apache.camel.CamelContext context()
      The same functionality as CamelTestSupport.context() .
      Overrides:
      context in class org.apache.camel.test.junit5.CamelTestSupport
    • createCamelRegistry

      protected final org.apache.camel.spi.Registry createCamelRegistry()
      This method is not called on Camel Quarkus because the `CamelRegistry` is created and owned by Quarkus CDI container. If you need to customize the registry upon creation, you may want to override createCamelContext() in the following way:
       @Override
       protected CamelContext createCamelContext() throws Exception {
           CamelContext ctx = super.createCamelContext();
           Registry registry = ctx.getRegistry();
           // do something with the registry...
           return ctx;
       }
       
      Overrides:
      createCamelRegistry in class org.apache.camel.test.junit5.CamelTestSupport
      Returns:
      Never returns any result. UnsupportedOperationException is thrown instead.
    • beforeAll

      public final void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
      This method does nothing. All necessary tasks are performed in BeforeEachCallback.beforeEach(QuarkusTestMethodContext) Use doAfterConstruct() instead of this method.
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Overrides:
      beforeAll in class org.apache.camel.test.junit5.CamelTestSupport
    • beforeEach

      public final void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      This method does nothing. All tasks are performed in BeforeEachCallback.beforeEach(QuarkusTestMethodContext) Use doBeforeEach(QuarkusTestMethodContext) instead of this method.
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
      Overrides:
      beforeEach in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • afterAll

      public final void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
      This method does nothing. All necessary tasks are performed in BeforeEachCallback.beforeEach(QuarkusTestMethodContext) Use doAfterAll(QuarkusTestContext) instead of this method.
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
      Overrides:
      afterAll in class org.apache.camel.test.junit5.CamelTestSupport
    • afterEach

      public final void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      This method does nothing. All necessary tasks are performed in BeforeEachCallback.beforeEach(QuarkusTestMethodContext) Use doAfterEach(QuarkusTestMethodContext) instead of this method.
      Specified by:
      afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
      Overrides:
      afterEach in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • afterTestExecution

      public final void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      This method does nothing All necessary tasks are performed in BeforeEachCallback.beforeEach(QuarkusTestMethodContext) Use doAfterEach(QuarkusTestMethodContext) instead of this method.
      Specified by:
      afterTestExecution in interface org.junit.jupiter.api.extension.AfterTestExecutionCallback
      Overrides:
      afterTestExecution in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • setUp

      public void setUp() throws Exception
      Method CamelTestSupport.setUp() is triggered via annotation BeforeEach. Its execution is disabled (by using overriding method without any annotation) and is executed from BeforeEachCallback
      Overrides:
      setUp in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • tearDown

      public void tearDown() throws Exception
      Method CamelTestSupport.tearDown() is triggered via annotation AfterEach. Its execution is disabled (by using overriding method without any annotation) and is executed from AfterEachCallback
      Overrides:
      tearDown in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • stopCamelContext

      protected void stopCamelContext() throws Exception
      This method stops the Camel context. Be aware that on of the limitation that Quarkus brings is that context can not be started (lifecycle f the context is bound to the application) .
      Overrides:
      stopCamelContext in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • doQuarkusCheck

      protected final void doQuarkusCheck()
      Allows running of the CamelTestSupport child in the Quarkus application. Method is not intended to be overridden.
      Overrides:
      doQuarkusCheck in class org.apache.camel.test.junit5.CamelTestSupport
    • internalAfterAll

      void internalAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
    • internalBeforeAll

      void internalBeforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
    • internalBeforeEach

      void internalBeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Throws:
      Exception
    • doPreSetup

      protected void doPreSetup() throws Exception
      Strategy to perform any pre setup, before CamelContext is created

      Be aware that difference in lifecycle with Quarkus may require a special behavior. If this method is overridden, super.doPreSetup() has to be called.

      Overrides:
      doPreSetup in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • doPostSetup

      protected void doPostSetup() throws Exception
      Strategy to perform any post setup after CamelContext is created

      Be aware that difference in lifecycle with Quarkus may require a special behavior. If this method is overridden, super.doPostSetup() has to be called.

      Overrides:
      doPostSetup in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • doStopCamelContext

      protected final void doStopCamelContext(org.apache.camel.CamelContext context, org.apache.camel.Service camelContextService)
      Internal disablement of the context stop functionality.
      Overrides:
      doStopCamelContext in class org.apache.camel.test.junit5.CamelTestSupport
    • startCamelContext

      protected final void startCamelContext()
      This method does nothing. The context starts together with Quarkus engine.
      Overrides:
      startCamelContext in class org.apache.camel.test.junit5.CamelTestSupport
    • isUseAdviceWith

      public boolean isUseAdviceWith()
      Override when using advice with and return true. This helps knowing advice with is to be used.

      Important: Its important to 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.junit5.CamelTestSupport
      Returns:
      true if you use advice with in your unit tests.
    • startRouteDefinitions

      protected void startRouteDefinitions() throws Exception
      Helper method to start routeDefinitions (to be used with `adviceWith`).
      Throws:
      Exception