Package org.apache.camel.test.junit5
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 Summary
FieldsFields inherited from class org.apache.camel.test.junit5.AbstractTestSupport
camelContextConfiguration, consumer, context, fluentTemplate, template, testConfigurationBuilder
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
CamelTestSupport
(ContextManagerFactory contextManagerFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterAll
(org.junit.jupiter.api.extension.ExtensionContext context) void
afterEach
(org.junit.jupiter.api.extension.ExtensionContext context) void
afterTestExecution
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
Deprecated.protected final void
assertExpression
(org.apache.camel.Exchange exchange, String languageName, String expressionText, Object expectedValue) Deprecated.protected final void
assertPredicate
(String languageName, String expressionText, org.apache.camel.Exchange exchange, boolean expected) Deprecated.protected final org.apache.camel.spi.Language
assertResolveLanguage
(String languageName) Deprecated.protected final void
assertValidContext
(org.apache.camel.CamelContext context) Deprecated.Use JUnit's assertions if neededvoid
beforeAll
(org.junit.jupiter.api.extension.ExtensionContext context) void
beforeEach
(org.junit.jupiter.api.extension.ExtensionContext context) void
beforeTestExecution
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
bindToRegistry
(org.apache.camel.spi.Registry registry) Allows binding custom beans to the CamelRegistry
.protected org.apache.camel.CamelContext
protected org.apache.camel.spi.Registry
Deprecated.protected final org.apache.camel.Exchange
createExchangeWithBody
(Object body) Deprecated.protected org.apache.camel.RoutesBuilder
Factory method which derived classes can use to create aRouteBuilder
to define the routes for testingprotected org.apache.camel.RoutesBuilder[]
Deprecated.This method will be made private.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.UseAbstractTestSupport.camelContextConfiguration()
to set an instance ofDebugBreakpoint
protected void
debugBefore
(org.apache.camel.Exchange exchange, org.apache.camel.Processor processor, org.apache.camel.model.ProcessorDefinition<?> definition, String id, String label) Deprecated.UseAbstractTestSupport.camelContextConfiguration()
to set an instance ofDebugBreakpoint
protected void
Deprecated.UseAbstractTestSupport.setupResources()
insteadprotected void
Deprecated.useAbstractTestSupport.cleanupResources()
instead.protected void
Deprecated.UseAbstractTestSupport.setupResources()
insteadprotected void
Deprecated.protected final void
doSetUp()
Deprecated.protected void
Deprecated.final String
Deprecated.Use JUnit's TestInfo class or theTestNameExtension
protected final org.apache.camel.Endpoint
protected final <T extends org.apache.camel.Endpoint>
TgetMandatoryEndpoint
(String uri, Class<T> type) protected final org.apache.camel.component.mock.MockEndpoint
getMockEndpoint
(String uri) Resolves the mandatory Mock endpoint using a URI of the formmock:someName
protected final org.apache.camel.component.mock.MockEndpoint
getMockEndpoint
(String uri, boolean create) Deprecated.protected int
Deprecated.use the accessors fromAbstractTestSupport.camelContextConfiguration()
protected boolean
hasClassAnnotation
(String... names) Deprecated.protected void
Deprecated.useAbstractTestSupport.setupResources()
or the JUnit's annotation instead of this methodprotected final org.apache.camel.Endpoint
Deprecated.Use the methods fromTestSupport
protected final <T extends org.apache.camel.Endpoint>
TresolveMandatoryEndpoint
(String uri, Class<T> endpointType) Deprecated.Use the methods fromTestSupport
protected final void
sendBodies
(String endpointUri, Object... bodies) Deprecated.protected final void
Deprecated.protected final void
Deprecated.final void
setUp()
Deprecated.UseAbstractTestSupport.setupResources()
insteadprotected void
Deprecated.protected void
Deprecated.final void
tearDown()
Deprecated.UseAbstractTestSupport.cleanupResources()
insteadlong
Deprecated.protected void
Deprecated.Methods inherited from class org.apache.camel.test.junit5.AbstractTestSupport
camelContextConfiguration, camelContextService, cleanupResources, consumer, context, disableJMX, enableJMX, fluentTemplate, getCamelContextService, getRouteFilterExcludePattern, getRouteFilterIncludePattern, ignoreMissingLocationWithPropertiesComponent, isCreateCamelContextPerClass, isDumpRouteCoverage, isMockEndpoints, isMockEndpointsAndSkip, isRouteCoverageEnabled, isUseAdviceWith, isUseDebugger, isUseRouteBuilder, replaceRouteFromWith, setCamelContextService, setContext, setupResources, setUseRouteBuilder, template, testConfiguration, useJmx, useOverridePropertiesWithPropertiesComponent
-
Field Details
-
testLoggerExtension
-
camelTestSupportExtension
-
-
Constructor Details
-
CamelTestSupport
-
CamelTestSupport
protected CamelTestSupport()
-
-
Method Details
-
afterTestExecution
public void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception - Specified by:
afterTestExecution
in interfaceorg.junit.jupiter.api.extension.AfterTestExecutionCallback
- Throws:
Exception
-
beforeTestExecution
public void beforeTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception - Specified by:
beforeTestExecution
in interfaceorg.junit.jupiter.api.extension.BeforeTestExecutionCallback
- Throws:
Exception
-
timeTaken
Deprecated. -
beforeEach
- Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
- Throws:
Exception
-
afterEach
- Specified by:
afterEach
in interfaceorg.junit.jupiter.api.extension.AfterEachCallback
- Throws:
Exception
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
afterAll
in interfaceorg.junit.jupiter.api.extension.AfterAllCallback
-
getCurrentTestName
Deprecated.Use JUnit's TestInfo class or theTestNameExtension
Gets the name of the current test being executed. -
setUp
Deprecated.UseAbstractTestSupport.setupResources()
insteadCommon test setup. For internal use.- Throws:
Exception
- if unable to setup the test
-
doPreSetup
Deprecated.UseAbstractTestSupport.setupResources()
insteadStrategy to perform any pre-setup, before theCamelContext
is created. This is for internal Camel usage.- Throws:
Exception
-
doPostSetup
Deprecated.UseAbstractTestSupport.setupResources()
insteadStrategy to perform any post-setup afterCamelContext
is created. This is for internal Camel usage.- Throws:
Exception
-
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.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.Temporary method for the child classes to modify the unsupported check. -
doSetUp
Deprecated.- Throws:
Exception
-
tearDown
Deprecated.UseAbstractTestSupport.cleanupResources()
insteadCommon test tear down. For internal use.- Throws:
Exception
- if unable to setup the test
-
doPostTearDown
Deprecated.useAbstractTestSupport.cleanupResources()
instead.Strategy to perform any post-action, afterCamelContext
is stopped. This is meant for internal Camel usage and should not be used by user classes.- Throws:
Exception
-
getShutdownTimeout
Deprecated.use the accessors fromAbstractTestSupport.camelContextConfiguration()
Returns the timeout to use when shutting down (unit in seconds). Will default use 10 seconds.- Returns:
- the timeout to use
-
postProcessTest
Deprecated.useAbstractTestSupport.setupResources()
or the JUnit's annotation instead of this methodInternal method. Do not use.- Throws:
Exception
-
applyCamelPostProcessor
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
Deprecated.Does this test class have any of the following annotations on the class-level. -
stopCamelContext
Deprecated.- Throws:
Exception
-
startCamelContext
Deprecated.- Throws:
Exception
-
createCamelContext
- Throws:
Exception
-
bindToRegistry
Allows binding custom beans to the CamelRegistry
.- Throws:
Exception
-
createCamelRegistry
@Deprecated(since="4.7.0") protected org.apache.camel.spi.Registry createCamelRegistry() throws ExceptionDeprecated.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
Factory method which derived classes can use to create aRouteBuilder
to define the routes for testing- Throws:
Exception
-
createRouteBuilders
@Deprecated(since="4.7.0") protected org.apache.camel.RoutesBuilder[] createRouteBuilders() throws ExceptionDeprecated.This method will be made private. Do not useFactory method which derived classes can use to create an array ofRouteBuilder
s 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 fromTestSupport
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 fromTestSupport
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
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
@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 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 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.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
@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 tobody
- the body for the messageheaders
- any headers to set on the message
-
sendBodies
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
@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 neededAsserts the validity of the context- Parameters:
context
-
-
getMandatoryEndpoint
-
getMandatoryEndpoint
-
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) Deprecated.UseAbstractTestSupport.camelContextConfiguration()
to set an instance ofDebugBreakpoint
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) Deprecated.UseAbstractTestSupport.camelContextConfiguration()
to set an instance ofDebugBreakpoint
Single step debugs and Camel invokes this method after processing the given processor. This method is NOOP.
-