Package org.apache.camel.quarkus.test
Class CamelQuarkusTestSupport
java.lang.Object
org.apache.camel.test.junit6.AbstractTestSupport
org.apache.camel.quarkus.test.CamelQuarkusTestSupport
- All Implemented Interfaces:
io.quarkus.test.junit.QuarkusTestProfile,org.apache.camel.test.junit6.CommonTestSupport,org.apache.camel.test.junit6.ConfigurableContext,org.apache.camel.test.junit6.ConfigurableTest
public class CamelQuarkusTestSupport
extends org.apache.camel.test.junit6.AbstractTestSupport
implements io.quarkus.test.junit.QuarkusTestProfile
The
CamelTestSupport class does not work on Quarkus. This class provides a replacement, which can be used in
JVM mode. Note that CamelQuarkusTestSupport DOES NOT work for native mode tests.
There are several differences between CamelTestSupport and this class.
- Starting and stopping
CamelContextin Camel Quarkus is generally bound to starting and stopping the application and this holds also when testing. - Starting and stopping the application under test (and thus also
CamelContextis under full control of Quarkus JUnit Extension. It prefers keeping the application up and running unless it is told to do otherwise. - Hence normally the application under test is started only once for all test classes of the given Maven/Gradle module.
- To force Quarkus JUnit Extension to restart the application (and thus also `CamelContext`) for a given test
class, you need to assign a unique
@io.quarkus.test.junit.TestProfileto that class. Check the Quarkus documentation for how you can do that. (Note that QuarkusTestResource has a similar effect.) - Camel Quarkus executes the production of beans during the build phase. Because all the tests are
build together, exclusion behavior is implemented into
CamelQuarkusTestSupport. If a producer of the specific type and name is used in one tests, the instance will be the same for the rest of the tests. - JUnit Jupiter callbacks
BeforeEachCallback,AfterEachCallback,AfterAllCallback,BeforeAllCallback,BeforeTestExecutionCallbackandAfterTestExecutionCallback) might not work correctly. See the documentation. MethodsafterAll,afterEach,afterTestExecution,beforeAllandbeforeEachare not executed anymore. You should usedoAfterAll,doAfterConstruct,doAfterEach,doBeforeEachanddoBeforeAllinstead of them.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.quarkus.test.junit.QuarkusTestProfile
io.quarkus.test.junit.QuarkusTestProfile.TestResourceEntry -
Field Summary
FieldsFields inherited from class org.apache.camel.test.junit6.AbstractTestSupport
camelContextConfiguration, consumer, fluentTemplate, template, testConfigurationBuilder -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbindToRegistry(org.apache.camel.spi.Registry registry) The same functionality asCamelTestSupport.bindToRegistry(Registry).protected org.apache.camel.CamelContextFeel free to override this method for the sake of customizing the instance returned by this implementation.voidconfigureContext(org.apache.camel.test.junit6.CamelContextConfiguration camelContextConfiguration) voidconfigureTest(org.apache.camel.test.junit6.TestExecutionConfiguration testExecutionConfiguration) org.apache.camel.CamelContextcontext()The same functionality asAbstractTestSupport.context().(package private) CustomCamelContextConfigurationprotected org.apache.camel.RoutesBuilderFactory method which derived classes can use to create aRouteBuilderto define the routes for testingprotected org.apache.camel.RoutesBuilder[]Deprecated.This method will be made private.protected voiddebugAfter(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 ofinvalid reference
DebugBreakpointprotected voiddebugBefore(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 ofinvalid reference
DebugBreakpointprotected voiddoAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context) Replacement ofcalled frominvalid reference
#afterAll(ExtensionContext)AfterAllCallback.afterAll(QuarkusTestContext)protected voidReplacement ofcalled frominvalid reference
#beforeAll(ExtensionContext)AfterConstructCallback.afterConstruct(Object)Execution differs in case of @TestInstance(TestInstance.Lifecycle.PER_METHOD). in which case a callback is invoked before each test (instead of).invalid reference
#beforeAll(ExtensionContext)protected voiddoAfterEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) Replacement ofcalled frominvalid reference
#afterEach(ExtensionContext)AfterEachCallback.afterEach(QuarkusTestMethodContext)protected voiddoBeforeEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) Replacement ofcalled frominvalid reference
#beforeEach(ExtensionContext)BeforeEachCallback.beforeEach(QuarkusTestMethodContext)protected voidDeprecated.protected voidDeprecated.useAbstractTestSupport.cleanupResources()instead.protected voidDeprecated.final StringGets the name of the current test being executed.protected final org.apache.camel.component.mock.MockEndpointgetMockEndpoint(String uri) Resolves the mandatory Mock endpoint using a URI of the formmock:someNameprotected final org.apache.camel.component.mock.MockEndpointgetMockEndpoint(String uri, boolean create) Deprecated.(package private) void(package private) void(package private) voidbooleanDeprecated.protected voidDeprecated.voidsetUp()Deprecated.UseAbstractTestSupport.setupResources()insteadprotected voidHelper method to start routeDefinitions (to be used with `adviceWith`).voidtearDown()Deprecated.UseAbstractTestSupport.cleanupResources()instead(package private) CustomTestExecutionConfigurationlongDeprecated.Methods inherited from class org.apache.camel.test.junit6.AbstractTestSupport
camelContextConfiguration, camelContextService, cleanupResources, consumer, disableJMX, enableJMX, fluentTemplate, getCamelContextService, getDumpRoute, getRouteFilterExcludePattern, getRouteFilterIncludePattern, ignoreMissingLocationWithPropertiesComponent, isAutoStartupExcludePatterns, isCreateCamelContextPerClass, isDumpRouteCoverage, isMockEndpoints, isMockEndpointsAndSkip, isRouteCoverageEnabled, isStubEndpoints, isUseDebugger, isUseRouteBuilder, replaceRouteFromWith, setCamelContextService, setContext, setupResources, setUseRouteBuilder, template, testConfiguration, useJmx, useOverridePropertiesWithPropertiesComponentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.quarkus.test.junit.QuarkusTestProfile
commandLineParameters, disableApplicationLifecycleObservers, disableGlobalTestResources, getConfigOverrides, getConfigProfile, getEnabledAlternatives, runMainMethod, tags, testResources
-
Field Details
-
context
@Inject protected org.apache.camel.CamelContext context
-
-
Constructor Details
-
CamelQuarkusTestSupport
public CamelQuarkusTestSupport()
-
-
Method Details
-
contextConfiguration
CustomCamelContextConfiguration contextConfiguration() -
testConfigurationBuilder
CustomTestExecutionConfiguration testConfigurationBuilder() -
doAfterAll
protected void doAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context) throws Exception Replacement ofcalled frominvalid reference
#afterAll(ExtensionContext)AfterAllCallback.afterAll(QuarkusTestContext)- Throws:
Exception
-
doAfterEach
protected void doAfterEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) throws Exception Replacement ofcalled frominvalid reference
#afterEach(ExtensionContext)AfterEachCallback.afterEach(QuarkusTestMethodContext)- Throws:
Exception
-
doAfterConstruct
Replacement ofcalled frominvalid reference
#beforeAll(ExtensionContext)AfterConstructCallback.afterConstruct(Object)Execution differs in case of @TestInstance(TestInstance.Lifecycle.PER_METHOD). in which case a callback is invoked before each test (instead of).invalid reference
#beforeAll(ExtensionContext)- Throws:
Exception
-
doBeforeEach
protected void doBeforeEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) throws Exception Replacement ofcalled frominvalid reference
#beforeEach(ExtensionContext)BeforeEachCallback.beforeEach(QuarkusTestMethodContext)- Throws:
Exception
-
camelContextSupplier
Feel free to override this method for the sake of customizing the instance returned by this implementation. Do not create your own CamelContext instance, because there needs to exist just a single instance owned by Quarkus CDI container. There are checks in place that will make your tests fail if you do otherwise.- Returns:
- The context from Quarkus CDI container
- Throws:
Exception- Overridden method has to throw the same Exception as superclass.
-
bindToRegistry
The same functionality asCamelTestSupport.bindToRegistry(Registry).- Throws:
Exception
-
postProcessTest
Deprecated.The same functionality asCamelTestSupport.postProcessTest().- Throws:
Exception
-
context
public org.apache.camel.CamelContext context()The same functionality asAbstractTestSupport.context().- Overrides:
contextin classorg.apache.camel.test.junit6.AbstractTestSupport
-
timeTaken
Deprecated. -
getCurrentTestName
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
-
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, afterCamelContextis stopped. This is meant for internal Camel usage and should not be used by user classes.- Throws:
Exception
-
createRouteBuilder
Factory method which derived classes can use to create aRouteBuilderto define the routes for testing- Throws:
Exception
-
createRouteBuilders
@Deprecated(since="3.15.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 ofRouteBuilders to define the routes for testing- Throws:
Exception- See Also:
-
internalAfterAll
void internalAfterAll() -
internalBeforeAll
-
internalBeforeEach
- Throws:
Exception
-
doPreSetup
Deprecated.Strategy to perform any pre setup, before theCamelContextis created.Be aware that difference in lifecycle with Quarkus may require special behavior. If this method is overridden, super.doPreSetup() must be called.
- Throws:
Exception
-
doPostSetup
Deprecated.Strategy to perform any post setup after theCamelContextis created.Be aware that difference in lifecycle with Quarkus may require special behavior. If this method is overridden, super.doPostSetup() must be called.
- Throws:
Exception
-
isUseAdviceWith
Deprecated.Override when using advice with and returntrue. Important: You must execute methodstartRouteDefinitions()} manually from the unit test after you are done doing all the advice with.- Overrides:
isUseAdviceWithin classorg.apache.camel.test.junit6.AbstractTestSupport- Returns:
trueto apply advice to existing route(s).falseto disable advice.
-
startRouteDefinitions
Helper method to start routeDefinitions (to be used with `adviceWith`).- Throws:
Exception
-
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="3.15.0") protected final org.apache.camel.component.mock.MockEndpoint getMockEndpoint(String uri, boolean create) throws org.apache.camel.NoSuchEndpointException Deprecated.Resolves theMockEndpointusing 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
NoSuchEndpointExceptionis thrown if it could not be resolved - Throws:
org.apache.camel.NoSuchEndpointException- is the mock endpoint does not exist
-
debugBefore
@Deprecated(since="3.15.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 ofinvalid reference
DebugBreakpointSingle step debugs and Camel invokes this method before entering the given processor. This method is NOOP. -
debugAfter
@Deprecated(since="3.15.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 ofinvalid reference
DebugBreakpointSingle step debugs and Camel invokes this method after processing the given processor. This method is NOOP. -
getCreatedRoutes
-
configureContext
public void configureContext(org.apache.camel.test.junit6.CamelContextConfiguration camelContextConfiguration) - Specified by:
configureContextin interfaceorg.apache.camel.test.junit6.ConfigurableContext
-
configureTest
public void configureTest(org.apache.camel.test.junit6.TestExecutionConfiguration testExecutionConfiguration) - Specified by:
configureTestin interfaceorg.apache.camel.test.junit6.ConfigurableTest
-