Class CamelTestSupport

java.lang.Object
org.apache.camel.test.junit5.AbstractTestSupport
org.apache.camel.test.junit5.CamelTestSupport
All Implemented Interfaces:
CommonTestSupport, 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
Direct Known Subclasses:
EndpointUriFactoryTestSupport, ExchangeTestSupport

public abstract class CamelTestSupport extends AbstractTestSupport implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeTestExecutionCallback, org.junit.jupiter.api.extension.AfterTestExecutionCallback
A useful base class which creates a CamelContext with some routes along with a ProducerTemplate for use in the test case Do not use this class for Spring Boot testing.
  • Field Details

    • testLoggerExtension

      @RegisterExtension @Order(10) protected TestLoggerExtension testLoggerExtension
    • camelTestSupportExtension

      @RegisterExtension protected CamelTestSupport camelTestSupportExtension
  • Constructor Details

    • CamelTestSupport

      protected CamelTestSupport(ContextManagerFactory contextManagerFactory)
    • CamelTestSupport

      protected CamelTestSupport()
  • Method Details

    • afterTestExecution

      public void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterTestExecution in interface org.junit.jupiter.api.extension.AfterTestExecutionCallback
      Throws:
      Exception
    • beforeTestExecution

      public void beforeTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeTestExecution in interface org.junit.jupiter.api.extension.BeforeTestExecutionCallback
      Throws:
      Exception
    • timeTaken

      @Deprecated(since="4.7.0") public long timeTaken()
      Deprecated.
    • beforeEach

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
      Throws:
      Exception
    • afterEach

      public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
      Throws:
      Exception
    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
    • afterAll

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
    • getCurrentTestName

      @Deprecated(since="4.7.0") public final String getCurrentTestName()
      Deprecated.
      Use JUnit's TestInfo class or the TestNameExtension
      Gets the name of the current test being executed.
    • setUp

      @Deprecated(since="4.7.0") @BeforeEach public final void setUp() throws Exception
      Deprecated.
      Common test setup. For internal use.
      Throws:
      Exception - if unable to setup the test
    • doPreSetup

      @Deprecated(since="4.7.0") protected void doPreSetup() throws Exception
      Deprecated.
      Strategy to perform any pre-setup, before the CamelContext is created. This is for internal Camel usage.
      Throws:
      Exception
    • doPostSetup

      @Deprecated(since="4.7.0") protected void doPostSetup() throws Exception
      Deprecated.
      Strategy to perform any post-setup after CamelContext is created. This is for internal Camel usage.
      Throws:
      Exception
    • doSpringBootCheck

      @Deprecated(since="4.7.0") protected void doSpringBootCheck()
      Deprecated.
      Detects if this is a Spring-Boot test and throws an exception, as these base classes is not intended for testing Camel on Spring Boot. Use ExtensionHelper.hasClassAnnotation instead
    • doQuarkusCheck

      @Deprecated(since="4.7.0") protected void doQuarkusCheck()
      Deprecated.
      Detects if this is a Camel-quarkus test and throw an exception, as these base classes is not intended for testing Camel onQuarkus. Use ExtensionHelper.hasClassAnnotation instead.
    • unsupportedCheck

      @Deprecated(since="4.7.0") protected void unsupportedCheck()
      Deprecated.
      Temporary method for the child classes to modify the unsupported check.
    • doSetUp

      @Deprecated(since="4.7.0") protected final void doSetUp() throws Exception
      Deprecated.
      Throws:
      Exception
    • tearDown

      @Deprecated(since="4.7.0") @AfterEach public final void tearDown() throws Exception
      Common test tear down. For internal use.
      Throws:
      Exception - if unable to setup the test
    • doPostTearDown

      @Deprecated(since="4.7.0") protected void doPostTearDown() throws Exception
      Deprecated.
      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
    • getShutdownTimeout

      @Deprecated(since="4.7.0") protected int getShutdownTimeout()
      Deprecated.
      Returns the timeout to use when shutting down (unit in seconds).

      Will default use 10 seconds.

      Returns:
      the timeout to use
    • postProcessTest

      @Deprecated(since="4.7.0") protected void postProcessTest() throws Exception
      Deprecated.
      use AbstractTestSupport.setupResources() or the JUnit's annotation instead of this method
      Internal method. Do not use.
      Throws:
      Exception
    • applyCamelPostProcessor

      @Deprecated(since="4.7.0") protected void applyCamelPostProcessor() throws Exception
      Deprecated.
      Applies the CamelBeanPostProcessor to this instance.

      Derived classes using IoC / DI frameworks may wish to turn this into a NoOp such as for CDI we would just use CDI to inject this

      Throws:
      Exception
    • hasClassAnnotation

      @Deprecated protected boolean hasClassAnnotation(String... names)
      Deprecated.
      Does this test class have any of the following annotations on the class-level.
    • stopCamelContext

      @Deprecated(since="4.7.0") protected void stopCamelContext() throws Exception
      Deprecated.
      Throws:
      Exception
    • startCamelContext

      @Deprecated(since="4.7.0") protected void startCamelContext() throws Exception
      Deprecated.
      Throws:
      Exception
    • createCamelContext

      protected org.apache.camel.CamelContext createCamelContext() throws Exception
      Throws:
      Exception
    • bindToRegistry

      protected void bindToRegistry(org.apache.camel.spi.Registry registry) throws Exception
      Allows binding custom beans to the Camel Registry.
      Throws:
      Exception
    • createCamelRegistry

      @Deprecated(since="4.7.0") protected org.apache.camel.spi.Registry createCamelRegistry() throws Exception
      Deprecated.
      Override to use a custom Registry.

      However if you need to bind beans to the registry then this is possible already with the bind method on registry, and there is no need to override this method.

      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="4.7.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:
    • resolveMandatoryEndpoint

      @Deprecated(since="4.7.0") protected final org.apache.camel.Endpoint resolveMandatoryEndpoint(String uri)
      Deprecated.
      Use the methods from TestSupport
      Resolves a mandatory endpoint for the given URI or an exception is thrown
      Parameters:
      uri - the Camel URI to use to create or resolve an endpoint
      Returns:
      the endpoint
    • resolveMandatoryEndpoint

      @Deprecated(since="4.7.0") protected final <T extends org.apache.camel.Endpoint> T resolveMandatoryEndpoint(String uri, Class<T> endpointType)
      Deprecated.
      Use the methods from TestSupport
      Resolves a mandatory endpoint for the given URI and expected type or an exception is thrown
      Parameters:
      uri - the Camel URI to use to create or resolve an endpoint
      Returns:
      the endpoint
    • 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="4.7.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
    • sendBody

      @Deprecated(since="4.7.0") protected final void sendBody(String endpointUri, Object body)
      Deprecated.
      Sends a message to the given endpoint URI with the body value
      Parameters:
      endpointUri - the URI of the endpoint to send to
      body - the body for the message
    • sendBody

      @Deprecated(since="4.7.0") protected final void sendBody(String endpointUri, Object body, Map<String,Object> headers)
      Deprecated.
      Sends a message to the given endpoint URI with the body value and specified headers
      Parameters:
      endpointUri - the URI of the endpoint to send to
      body - the body for the message
      headers - any headers to set on the message
    • sendBodies

      @Deprecated(since="4.7.0") protected final void sendBodies(String endpointUri, Object... bodies)
      Deprecated.
      Sends messages to the given endpoint for each of the specified bodies
      Parameters:
      endpointUri - the endpoint URI to send to
      bodies - the bodies to send, one per message
    • createExchangeWithBody

      @Deprecated(since="4.7.0") protected final org.apache.camel.Exchange createExchangeWithBody(Object body)
      Deprecated.
      Creates an exchange with the given body
    • assertExpression

      @Deprecated(since="4.7.0") protected final void assertExpression(org.apache.camel.Exchange exchange, String languageName, String expressionText, Object expectedValue)
      Deprecated.
      Asserts that the given language name and expression evaluates to the given value on a specific exchange
    • assertPredicate

      @Deprecated(since="4.7.0") protected final void assertPredicate(String languageName, String expressionText, org.apache.camel.Exchange exchange, boolean expected)
      Deprecated.
      Asserts that the given language name and predicate expression evaluates to the expected value on the message exchange
    • assertResolveLanguage

      @Deprecated(since="4.7.0") protected final org.apache.camel.spi.Language assertResolveLanguage(String languageName)
      Deprecated.
      Asserts that the language name can be resolved
    • assertValidContext

      @Deprecated(since="4.7.0") protected final void assertValidContext(org.apache.camel.CamelContext context)
      Deprecated.
      Use JUnit's assertions if needed
      Asserts the validity of the context
      Parameters:
      context -
    • getMandatoryEndpoint

      protected final <T extends org.apache.camel.Endpoint> T getMandatoryEndpoint(String uri, Class<T> type)
    • getMandatoryEndpoint

      protected final org.apache.camel.Endpoint getMandatoryEndpoint(String uri)
    • debugBefore

      @Deprecated(since="4.7.0") protected void debugBefore(org.apache.camel.Exchange exchange, org.apache.camel.Processor processor, org.apache.camel.model.ProcessorDefinition<?> definition, String id, String label)
      Single step debugs and Camel invokes this method before entering the given processor. This method is NOOP.
    • debugAfter

      @Deprecated(since="4.7.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)
      Single step debugs and Camel invokes this method after processing the given processor. This method is NOOP.