Class AbstractTestSupport

java.lang.Object
org.apache.camel.test.junit5.AbstractTestSupport
All Implemented Interfaces:
CommonTestSupport
Direct Known Subclasses:
CamelTestSupport

public abstract class AbstractTestSupport extends Object implements CommonTestSupport
Base test class, mostly made of legacy setup methods. This is intended for internal use.
  • Field Details

    • testConfigurationBuilder

      protected final TestExecutionConfiguration testConfigurationBuilder
    • camelContextConfiguration

      protected final CamelContextConfiguration camelContextConfiguration
    • context

      protected volatile org.apache.camel.model.ModelCamelContext context
    • template

      protected volatile org.apache.camel.ProducerTemplate template
    • fluentTemplate

      protected volatile org.apache.camel.FluentProducerTemplate fluentTemplate
    • consumer

      protected volatile org.apache.camel.ConsumerTemplate consumer
  • Constructor Details

  • Method Details

    • setupResources

      protected void setupResources() throws Exception
      Strategy to set up resources, before CamelContext is created. This is meant to be used by resources that must be available before the context is created. Do not use this as a replacement for tasks that can be handled using JUnit's annotations.
      Throws:
      Exception
    • cleanupResources

      protected void cleanupResources() throws Exception
      Strategy to cleanup resources, after CamelContext is stopped
      Throws:
      Exception
    • isUseRouteBuilder

      @Deprecated(since="4.7.0") public boolean isUseRouteBuilder()
      Deprecated.
      Use the accessors from testConfiguration() method
      Use the RouteBuilder or not
      Returns:
      true then CamelContext will be auto started, false then CamelContext will not be auto started (you will have to start it manually)
    • setUseRouteBuilder

      @Deprecated(since="4.7.0") public void setUseRouteBuilder(boolean useRouteBuilder)
      Deprecated.
    • isDumpRouteCoverage

      @Deprecated(since="4.7.0") public boolean isDumpRouteCoverage()
      Deprecated.
      Use the accessors from testConfiguration() method
      Whether to dump route coverage stats at the end of the test.

      This allows tooling or manual inspection of the stats, so you can generate a route trace diagram of which EIPs have been in use and which have not. Similar concepts as a code coverage report.

      You can also turn on route coverage globally via setting JVM system property CamelTestRouteCoverage=true.

      Returns:
      true to write route coverage status in an xml file in the target/camel-route-coverage directory after the test has finished.
    • isUseAdviceWith

      @Deprecated(since="4.7.0") public boolean isUseAdviceWith()
      Deprecated.
      Use the accessors from testConfiguration() method
      Override when using advice with and return true. This helps to know advice with is to be used, and CamelContext will not be started before the advice with takes place. This helps by ensuring the advice with has been property setup before the CamelContext is started

      Important: It's important to start CamelContext manually from the unit test after you are done doing all the advice with.

      Returns:
      true if you use advice with in your unit tests.
    • isCreateCamelContextPerClass

      @Deprecated(since="4.7.0") protected final boolean isCreateCamelContextPerClass()
      Deprecated.
      Use the accessors from testConfiguration() method
      Tells whether CamelContext should be setup per test or per class. DO NOT USE.

      By default it will be setup/teardown per test method. This method returns true when the camel test class is annotated with @TestInstance(TestInstance.Lifecycle.PER_CLASS).

      Important: Use this with care as the CamelContext will carry over state from previous tests, such as endpoints, components etc. So you cannot use this in all your tests.

      Returns:
      true per class, false per test.
    • isMockEndpoints

      @Deprecated(since="4.7.0") public String isMockEndpoints()
      Deprecated.
      Use the accessors from camelContextConfiguration() method
      Override to enable auto mocking endpoints based on the pattern.

      Return * to mock all endpoints.

      See Also:
      • EndpointHelper.matchEndpoint(CamelContext, String, String)
    • isMockEndpointsAndSkip

      @Deprecated(since="4.7.0") public String isMockEndpointsAndSkip()
      Deprecated.
      Use the accessors from camelContextConfiguration() method
      Override to enable auto mocking endpoints based on the pattern, and skip sending to original endpoint.

      Return * to mock all endpoints.

      See Also:
      • EndpointHelper.matchEndpoint(CamelContext, String, String)
    • replaceRouteFromWith

      @Deprecated(since="4.7.0") public void replaceRouteFromWith(String routeId, String fromEndpoint)
      Deprecated.
      Use the accessors from camelContextConfiguration() method
      To replace from routes
      Parameters:
      routeId -
      fromEndpoint -
    • getRouteFilterIncludePattern

      @Deprecated(since="4.7.0") public String getRouteFilterIncludePattern()
      Deprecated.
      Used for filtering routes matching the given pattern, which follows the following rules:

      - Match by route id - Match by route input endpoint uri

      The matching is using exact match, by wildcard and regular expression.

      For example to only include routes which starts with foo in their route id's, use: include=foo* And to exclude routes which starts from JMS endpoints, use: exclude=jms:*

      Multiple patterns can be separated by comma, for example to exclude both foo and bar routes, use: exclude=foo*,bar*

      Exclude takes precedence over include.

    • getRouteFilterExcludePattern

      @Deprecated(since="4.7.0") public String getRouteFilterExcludePattern()
      Deprecated.
      Used for filtering routes matching the given pattern, which follows the following rules:

      - Match by route id - Match by route input endpoint uri

      The matching is using exact match, by wildcard and regular expression.

      For example to only include routes which starts with foo in their route id's, use: include=foo* And to exclude routes which starts from JMS endpoints, use: exclude=jms:*

      Multiple patterns can be separated by comma, for example to exclude both foo and bar routes, use: exclude=foo*,bar*

      Exclude takes precedence over include.

    • isUseDebugger

      @Deprecated(since="4.7.0") public boolean isUseDebugger()
      Deprecated.
      Use the accessors from testConfiguration() method
      Override to enable debugger

      Is default false

    • getCamelContextService

      @Deprecated(since="4.7.0") public org.apache.camel.Service getCamelContextService()
      Deprecated.
    • camelContextService

      @Deprecated(since="4.7.0") public org.apache.camel.Service camelContextService()
      Deprecated.
    • context

      public org.apache.camel.CamelContext context()
      Gets a reference to the CamelContext. Must not be used during test setup.
      Returns:
      A reference to the CamelContext
    • setContext

      @Deprecated(since="4.7.0") public void setContext(org.apache.camel.model.ModelCamelContext context)
      Deprecated.
      Sets the CamelContext. Used by the manager to override tests that try to access the context during setup. DO NOT USE.
      Parameters:
      context -
    • template

      public org.apache.camel.ProducerTemplate template()
    • fluentTemplate

      public org.apache.camel.FluentProducerTemplate fluentTemplate()
    • consumer

      public org.apache.camel.ConsumerTemplate consumer()
    • setCamelContextService

      public void setCamelContextService(org.apache.camel.Service service)
      Allows a service to be registered a separate lifecycle service to start and stop the context; such as for Spring when the ApplicationContext is started and stopped, rather than directly stopping the CamelContext
    • useJmx

      @Deprecated(since="4.7.0") protected boolean useJmx()
      Deprecated.
      Use the methods testConfiguration() to enable, disable or check JMX state.
      Whether JMX should be used during testing.
      Returns:
      false by default.
    • useOverridePropertiesWithPropertiesComponent

      @Deprecated(since="4.7.0") protected Properties useOverridePropertiesWithPropertiesComponent()
      Deprecated.
      Use the accessors from camelContextConfiguration() method
      Override this method to include and override properties with the Camel PropertiesComponent.
      Returns:
      additional properties to add/override.
    • ignoreMissingLocationWithPropertiesComponent

      @Deprecated(since="4.7.0") protected Boolean ignoreMissingLocationWithPropertiesComponent()
      Deprecated.
      Use the accessors from camelContextConfiguration() method
      Whether to ignore missing locations with the PropertiesComponent. For example when unit testing you may want to ignore locations that are not available in the environment used for testing.
      Returns:
      true to ignore, false to not ignore, and null to leave as configured on the PropertiesComponent
    • camelContextConfiguration

      public final CamelContextConfiguration camelContextConfiguration()
      Gets the CamelContextConfiguration for the test
      Specified by:
      camelContextConfiguration in interface CommonTestSupport
      Returns:
      the camel context configuration
    • testConfiguration

      public final TestExecutionConfiguration testConfiguration()
      Gets the TestExecutionConfiguration test execution configuration instance for the test
      Specified by:
      testConfiguration in interface CommonTestSupport
      Returns:
      the configuration instance for the test
    • disableJMX

      @Deprecated(since="4.7.0") protected void disableJMX()
      Deprecated.
      Use the methods testConfiguration() to enable, disable or check JMX state.
      Disables the JMX agent. Must be called before the setup method.
    • enableJMX

      @Deprecated(since="4.7.0") protected void enableJMX()
      Deprecated.
      Use the methods testConfiguration() to enable, disable or check JMX state.
      Enables the JMX agent. Must be called before the setup method.
    • isRouteCoverageEnabled

      @Deprecated(since="4.7.0") protected boolean isRouteCoverageEnabled()
      Deprecated.
      Use the methods testConfiguration() to enable or disable the route converage dumper
      Whether route coverage is enabled
      Returns:
      true if enabled or false otherwise