Class CamelTestSupport
- java.lang.Object
-
- org.junit.Assert
-
- org.apache.camel.test.junit4.TestSupport
-
- org.apache.camel.test.junit4.CamelTestSupport
-
- Direct Known Subclasses:
ExchangeTestSupport
@Deprecated public abstract class CamelTestSupport extends TestSupport
Deprecated.A useful base class which creates aCamelContext
with some routes along with aProducerTemplate
for use in the test case Do not use this class for Spring Boot testing, instead use@RunWith(CamelSpringBootRunner.class)
.
-
-
Field Summary
Fields Modifier and Type Field Description static CamelTearDownRule
CAMEL_TEAR_DOWN_RULE
Deprecated.protected org.apache.camel.Service
camelContextService
Deprecated.protected org.apache.camel.ConsumerTemplate
consumer
Deprecated.protected org.apache.camel.model.ModelCamelContext
context
Deprecated.protected Properties
extra
Deprecated.protected org.apache.camel.FluentProducerTemplate
fluentTemplate
Deprecated.static String
ROUTE_COVERAGE_ENABLED
Deprecated.JVM system property which can be set to true to turn on dumping route coverage statistics.protected org.apache.camel.ProducerTemplate
template
Deprecated.-
Fields inherited from class org.apache.camel.test.junit4.TestSupport
log, LS
-
-
Constructor Summary
Constructors Constructor Description CamelTestSupport()
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
applyCamelPostProcessor()
Deprecated.Applies theCamelBeanPostProcessor
to this instance.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 exchangeprotected void
assertMockEndpointsSatisfied()
Deprecated.Asserts that all the expectations of the Mock endpoints are validprotected void
assertMockEndpointsSatisfied(long timeout, TimeUnit unit)
Deprecated.Asserts that all the expectations of the Mock endpoints are validprotected 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 exchangeprotected org.apache.camel.spi.Language
assertResolveLanguage(String languageName)
Deprecated.Asserts that the language name can be resolvedprotected void
assertValidContext(org.apache.camel.CamelContext context)
Deprecated.protected void
bindToRegistry(org.apache.camel.spi.Registry registry)
Deprecated.Allows to bind custom beans to the CamelRegistry
.org.apache.camel.Service
camelContextService()
Deprecated.protected void
cleanupResources()
Deprecated.Strategy to perform resources cleanup, afterCamelContext
is stoppedorg.apache.camel.ConsumerTemplate
consumer()
Deprecated.org.apache.camel.CamelContext
context()
Deprecated.protected org.apache.camel.CamelContext
createCamelContext()
Deprecated.protected org.apache.camel.spi.Registry
createCamelRegistry()
Deprecated.Override to use a customRegistry
.protected org.apache.camel.Exchange
createExchangeWithBody(Object body)
Deprecated.Creates an exchange with the given bodyprotected org.apache.camel.RoutesBuilder
createRouteBuilder()
Deprecated.Factory method which derived classes can use to create aRouteBuilder
to define the routes for testingprotected org.apache.camel.RoutesBuilder[]
createRouteBuilders()
Deprecated.Factory method which derived classes can use to create an array ofRouteBuilder
s to define the routes for testingprotected 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 processorprotected 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 processorprotected void
disableJMX()
Deprecated.Disables the JMX agent.protected void
doPostSetup()
Deprecated.Strategy to perform any post setup afterCamelContext
is createdprotected void
doPostTearDown()
Deprecated.Strategy to perform any post action, afterCamelContext
is stoppedprotected void
doPreSetup()
Deprecated.Strategy to perform any pre setup, beforeCamelContext
is createdprotected 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.protected void
enableJMX()
Deprecated.Enables the JMX agent.org.apache.camel.FluentProducerTemplate
fluentTemplate()
Deprecated.org.apache.camel.Service
getCamelContextService()
Deprecated.CamelTestWatcher
getCamelTestWatcher()
Deprecated.protected org.apache.camel.Endpoint
getMandatoryEndpoint(String uri)
Deprecated.protected <T extends org.apache.camel.Endpoint>
TgetMandatoryEndpoint(String uri, Class<T> type)
Deprecated.protected org.apache.camel.component.mock.MockEndpoint
getMockEndpoint(String uri)
Deprecated.Resolves the mandatory Mock endpoint using a URI of the formmock:someName
protected org.apache.camel.component.mock.MockEndpoint
getMockEndpoint(String uri, boolean create)
Deprecated.Resolves theMockEndpoint
using a URI of the formmock:someName
, optionally creating it if it does not exist.String
getRouteFilterExcludePattern()
Deprecated.Used for filtering routes routes matching the given pattern, which follows the following rules:String
getRouteFilterIncludePattern()
Deprecated.Used for filtering routes routes matching the given pattern, which follows the following rules:protected int
getShutdownTimeout()
Deprecated.Returns the timeout to use when shutting down (unit in seconds).protected boolean
hasClassAnnotation(String... names)
Deprecated.Does this test class have any of the following annotations on the class-level.protected Boolean
ignoreMissingLocationWithPropertiesComponent()
Deprecated.Whether to ignore missing locations with thePropertiesComponent
.boolean
isCreateCamelContextPerClass()
Deprecated.Override to control whetherCamelContext
should be setup per test or per class.boolean
isDumpRouteCoverage()
Deprecated.Whether to dump route coverage stats at the end of the test.protected boolean
isLazyLoadingTypeConverter()
Deprecated.String
isMockEndpoints()
Deprecated.Override to enable auto mocking endpoints based on the pattern.String
isMockEndpointsAndSkip()
Deprecated.Override to enable auto mocking endpoints based on the pattern, and skip sending to original endpoint.boolean
isUseAdviceWith()
Deprecated.Override when using advice with and return true.boolean
isUseDebugger()
Deprecated.Override to enable debuggerboolean
isUseRouteBuilder()
Deprecated.Use the RouteBuilder or notprotected void
postProcessTest()
Deprecated.void
replaceRouteFromWith(String routeId, String fromEndpoint)
Deprecated.protected void
resetMocks()
Deprecated.Reset all Mock endpoints.protected org.apache.camel.Endpoint
resolveMandatoryEndpoint(String uri)
Deprecated.Resolves a mandatory endpoint for the given URI or an exception is thrownprotected <T extends org.apache.camel.Endpoint>
TresolveMandatoryEndpoint(String uri, Class<T> endpointType)
Deprecated.Resolves a mandatory endpoint for the given URI and expected type or an exception is thrownprotected void
sendBodies(String endpointUri, Object... bodies)
Deprecated.Sends messages to the given endpoint for each of the specified bodiesprotected void
sendBody(String endpointUri, Object body)
Deprecated.Sends a message to the given endpoint URI with the body valueprotected 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 headersvoid
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 CamelContextvoid
setUp()
Deprecated.protected void
setupResources()
Deprecated.Strategy to perform resources setup, beforeCamelContext
is createdvoid
setUseRouteBuilder(boolean useRouteBuilder)
Deprecated.protected void
startCamelContext()
Deprecated.protected void
stopCamelContext()
Deprecated.void
tearDown()
Deprecated.org.apache.camel.ProducerTemplate
template()
Deprecated.protected boolean
useJmx()
Deprecated.Whether or not JMX should be used during testing.protected Properties
useOverridePropertiesWithPropertiesComponent()
Deprecated.Override this method to include and override properties with the CamelPropertiesComponent
.-
Methods inherited from class org.apache.camel.test.junit4.TestSupport
assertCollectionSize, assertCollectionSize, assertDirectoryEquals, assertDirectoryEquals, assertDirectoryExists, assertEndpointUri, assertExpression, assertFileExists, assertFileNotExists, assertInMessageBodyEquals, assertInMessageHeader, assertIsInstanceOf, assertListSize, assertListSize, assertMessageHeader, assertOneElement, assertOutMessageBodyEquals, assertOutMessageHeader, assertPredicate, assertPredicateDoesNotMatch, assertPredicateMatches, assertStringContains, body, bodyAs, createDirectory, createExchangeWithBody, deleteDirectory, deleteDirectory, exchangeProperty, getJavaMajorVersion, getRouteList, getTestMethodName, getTestName, header, isJava15, isJava16, isJava17, isJava18, isJava19, isJavaVendor, isPlatform, property, resolveMandatoryEndpoint, resolveMandatoryEndpoint, systemProperty, systemProperty
-
Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertThrows, assertThrows, assertTrue, assertTrue, fail, fail
-
-
-
-
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
-
extra
protected Properties extra
Deprecated.
-
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.
-
-
Method Detail
-
isUseRouteBuilder
public boolean isUseRouteBuilder()
Deprecated.Use the RouteBuilder or not- Returns:
- true then
CamelContext
will be auto started, false thenCamelContext
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, andCamelContext
will not be started before the advice with takes place. This helps by ensuring the advice with has been property setup before theCamelContext
is started Important: Its important to startCamelContext
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 whetherCamelContext
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-useCamelContext
between test methods you can override this method and return true Important: Use this with care as theCamelContext
will carry over state from previous tests, such as endpoints, components etc. So you cannot use this in all your tests. Setting upCamelContext
uses thedoPreSetup()
,doSetUp()
, anddoPostSetup()
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, beforeCamelContext
is created- Throws:
Exception
-
doPostSetup
protected void doPostSetup() throws Exception
Deprecated.Strategy to perform any post setup afterCamelContext
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, afterCamelContext
is stopped- Throws:
Exception
-
setupResources
protected void setupResources() throws Exception
Deprecated.Strategy to perform resources setup, beforeCamelContext
is created- Throws:
Exception
-
cleanupResources
protected void cleanupResources() throws Exception
Deprecated.Strategy to perform resources cleanup, afterCamelContext
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 CamelPropertiesComponent
.- Returns:
- additional properties to add/override.
-
getCamelTestWatcher
public CamelTestWatcher getCamelTestWatcher()
Deprecated.
-
ignoreMissingLocationWithPropertiesComponent
protected Boolean ignoreMissingLocationWithPropertiesComponent()
Deprecated.Whether to ignore missing locations with thePropertiesComponent
. 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
-
applyCamelPostProcessor
protected void applyCamelPostProcessor() throws Exception
Deprecated.Applies theCamelBeanPostProcessor
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.
-
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 CamelRegistry
.- Throws:
Exception
-
createCamelRegistry
protected org.apache.camel.spi.Registry createCamelRegistry() throws Exception
Deprecated.Override to use a customRegistry
.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 aRouteBuilder
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 ofRouteBuilder
s 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 formmock: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 theMockEndpoint
using a URI of the formmock: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 namecreate
- 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 tobody
- 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 tobody
- the body for the messageheaders
- 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 tobodies
- 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 thesetUp()
method.
-
enableJMX
protected void enableJMX()
Deprecated.Enables the JMX agent. Must be called before thesetUp()
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
-
-