Class CamelTestSupport

  • Direct Known Subclasses:
    ExchangeTestSupport

    @Deprecated
    public abstract class CamelTestSupport
    extends TestSupport
    Deprecated.
    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, instead use @RunWith(CamelSpringBootRunner.class).
    • Field Detail

      • ROUTE_COVERAGE_ENABLED

        public static final String ROUTE_COVERAGE_ENABLED
        Deprecated.
        JVM system property which can be set to true to turn on dumping route coverage statistics.
        See Also:
        Constant Field Values
      • context

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

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

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

        protected volatile org.apache.camel.ConsumerTemplate consumer
        Deprecated.
      • camelContextService

        protected volatile org.apache.camel.Service camelContextService
        Deprecated.
      • CAMEL_TEAR_DOWN_RULE

        public static final CamelTearDownRule CAMEL_TEAR_DOWN_RULE
        Deprecated.
    • Constructor Detail

      • CamelTestSupport

        public CamelTestSupport()
        Deprecated.
    • Method Detail

      • isUseRouteBuilder

        public boolean isUseRouteBuilder()
        Deprecated.
        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

        public void setUseRouteBuilder​(boolean useRouteBuilder)
        Deprecated.
      • isDumpRouteCoverage

        public boolean isDumpRouteCoverage()
        Deprecated.
        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

        public boolean isUseAdviceWith()
        Deprecated.
        Override when using advice with and return true. This helps knowing 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: Its 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

        public boolean isCreateCamelContextPerClass()
        Deprecated.
        Override to control whether CamelContext should be setup per test or per class.

        By default it will be setup/teardown per test (per test method). If you want to re-use CamelContext between test methods you can override this method and return true

        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.

        Setting up CamelContext uses the doPreSetup(), doSetUp(), and doPostSetup() methods in that given order.

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

        public String isMockEndpoints()
        Deprecated.
        Override to enable auto mocking endpoints based on the pattern.

        Return * to mock all endpoints.

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

        public String isMockEndpointsAndSkip()
        Deprecated.
        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

        public void replaceRouteFromWith​(String routeId,
                                         String fromEndpoint)
        Deprecated.
      • getRouteFilterIncludePattern

        public String getRouteFilterIncludePattern()
        Deprecated.
        Used for filtering routes 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

        public String getRouteFilterExcludePattern()
        Deprecated.
        Used for filtering routes 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

        public boolean isUseDebugger()
        Deprecated.
        Override to enable debugger

        Is default false

      • getCamelContextService

        public org.apache.camel.Service getCamelContextService()
        Deprecated.
      • camelContextService

        public org.apache.camel.Service camelContextService()
        Deprecated.
      • context

        public org.apache.camel.CamelContext context()
        Deprecated.
      • template

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

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

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

        public void setCamelContextService​(org.apache.camel.Service service)
        Deprecated.
        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
      • doPreSetup

        protected void doPreSetup()
                           throws Exception
        Deprecated.
        Strategy to perform any pre setup, before CamelContext is created
        Throws:
        Exception
      • doPostSetup

        protected void doPostSetup()
                            throws Exception
        Deprecated.
        Strategy to perform any post setup after CamelContext is created
        Throws:
        Exception
      • doSpringBootCheck

        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.
      • doPostTearDown

        protected void doPostTearDown()
                               throws Exception
        Deprecated.
        Strategy to perform any post action, after CamelContext is stopped
        Throws:
        Exception
      • setupResources

        protected void setupResources()
                               throws Exception
        Deprecated.
        Strategy to perform resources setup, before CamelContext is created
        Throws:
        Exception
      • cleanupResources

        protected void cleanupResources()
                                 throws Exception
        Deprecated.
        Strategy to perform resources cleanup, after CamelContext is stopped
        Throws:
        Exception
      • getShutdownTimeout

        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
      • useJmx

        protected boolean useJmx()
        Deprecated.
        Whether or not JMX should be used during testing.
        Returns:
        false by default.
      • isLazyLoadingTypeConverter

        @Deprecated
        protected boolean isLazyLoadingTypeConverter()
        Deprecated.
        Whether or not type converters should be lazy loaded (notice core converters is always loaded)
        Returns:
        false by default.
      • useOverridePropertiesWithPropertiesComponent

        protected Properties useOverridePropertiesWithPropertiesComponent()
        Deprecated.
        Override this method to include and override properties with the Camel PropertiesComponent.
        Returns:
        additional properties to add/override.
      • getCamelTestWatcher

        public CamelTestWatcher getCamelTestWatcher()
        Deprecated.
      • ignoreMissingLocationWithPropertiesComponent

        protected Boolean ignoreMissingLocationWithPropertiesComponent()
        Deprecated.
        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 you use for testing.
        Returns:
        true to ignore, false to not ignore, and null to leave as configured on the PropertiesComponent
      • postProcessTest

        protected void postProcessTest()
                                throws Exception
        Deprecated.
        Throws:
        Exception
      • applyCamelPostProcessor

        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

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

        protected void stopCamelContext()
                                 throws Exception
        Deprecated.
        Throws:
        Exception
      • startCamelContext

        protected void startCamelContext()
                                  throws Exception
        Deprecated.
        Throws:
        Exception
      • createCamelContext

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

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

        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
        Deprecated.
        Factory method which derived classes can use to create a RouteBuilder to define the routes for testing
        Throws:
        Exception
      • createRouteBuilders

        protected org.apache.camel.RoutesBuilder[] createRouteBuilders()
                                                                throws Exception
        Deprecated.
        Factory method which derived classes can use to create an array of RouteBuilders to define the routes for testing
        Throws:
        Exception
        See Also:
        createRouteBuilder()
      • resolveMandatoryEndpoint

        protected org.apache.camel.Endpoint resolveMandatoryEndpoint​(String uri)
        Deprecated.
        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

        protected <T extends org.apache.camel.Endpoint> T resolveMandatoryEndpoint​(String uri,
                                                                                   Class<T> endpointType)
        Deprecated.
        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 org.apache.camel.component.mock.MockEndpoint getMockEndpoint​(String uri)
        Deprecated.
        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

        protected 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 or not 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 exists
      • sendBody

        protected 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

        protected 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

        protected 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

        protected org.apache.camel.Exchange createExchangeWithBody​(Object body)
        Deprecated.
        Creates an exchange with the given body
      • assertExpression

        protected 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

        protected 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

        protected org.apache.camel.spi.Language assertResolveLanguage​(String languageName)
        Deprecated.
        Asserts that the language name can be resolved
      • assertMockEndpointsSatisfied

        protected void assertMockEndpointsSatisfied()
                                             throws InterruptedException
        Deprecated.
        Asserts that all the expectations of the Mock endpoints are valid
        Throws:
        InterruptedException
      • assertMockEndpointsSatisfied

        protected void assertMockEndpointsSatisfied​(long timeout,
                                                    TimeUnit unit)
                                             throws InterruptedException
        Deprecated.
        Asserts that all the expectations of the Mock endpoints are valid
        Throws:
        InterruptedException
      • resetMocks

        protected void resetMocks()
        Deprecated.
        Reset all Mock endpoints.
      • assertValidContext

        protected void assertValidContext​(org.apache.camel.CamelContext context)
        Deprecated.
      • getMandatoryEndpoint

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

        protected org.apache.camel.Endpoint getMandatoryEndpoint​(String uri)
        Deprecated.
      • disableJMX

        protected void disableJMX()
        Deprecated.
        Disables the JMX agent. Must be called before the setUp() method.
      • enableJMX

        protected void enableJMX()
        Deprecated.
        Enables the JMX agent. Must be called before the setUp() method.
      • debugBefore

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

        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.
        Single step debugs and Camel invokes this method after processing the given processor