Package org.apache.camel.quarkus.test
Class CamelQuarkusTestSupport
- java.lang.Object
-
- org.apache.camel.test.junit5.CamelTestSupport
-
- org.apache.camel.quarkus.test.CamelQuarkusTestSupport
-
- All Implemented Interfaces:
io.quarkus.test.junit.QuarkusTestProfile,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
public class CamelQuarkusTestSupport extends org.apache.camel.test.junit5.CamelTestSupport implements io.quarkus.test.junit.QuarkusTestProfileTheCamelTestSupportclass does not work on Quarkus. This class provides a replacement, which can be used in JVM mode. There are several differences betweenCamelTestSupportand 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.camel.CamelContextcontext
-
Constructor Summary
Constructors Constructor Description CamelQuarkusTestSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterAll(org.junit.jupiter.api.extension.ExtensionContext context)This method does nothing.voidafterEach(org.junit.jupiter.api.extension.ExtensionContext context)This method does nothing.voidafterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context)This method does nothing All necessary tasks are performed inBeforeEachCallback.beforeEach(QuarkusTestMethodContext)UsedoAfterEach(QuarkusTestMethodContext)instead of this method.voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context)This method does nothing.voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context)This method does nothing.protected voidbindToRegistry(org.apache.camel.spi.Registry registry)The same functionality asCamelTestSupport.bindToRegistry(Registry).org.apache.camel.CamelContextcontext()The same functionality asCamelTestSupport.context().protected org.apache.camel.CamelContextcreateCamelContext()Feel free to override this method for the sake of customizing the instance returned by this implementation.protected org.apache.camel.spi.RegistrycreateCamelRegistry()This method is not called on Camel Quarkus because the `CamelRegistry` is created and owned by Quarkus CDI container.protected voiddoAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context)Replacement ofafterAll(ExtensionContext)called fromAfterAllCallback.afterAll(QuarkusTestContext)protected voiddoAfterConstruct()Replacement ofbeforeAll(ExtensionContext)called fromAfterConstructCallback.afterConstruct(Object)Execution differs in case of @TestInstance(TestInstance.Lifecycle.PER_METHOD) in which case callback is called before each test (instead ofbeforeAll(ExtensionContext)).protected voiddoAfterEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context)Replacement ofafterEach(ExtensionContext)called fromAfterEachCallback.afterEach(QuarkusTestMethodContext)protected voiddoBeforeEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context)Replacement ofbeforeEach(ExtensionContext)called fromBeforeEachCallback.beforeEach(QuarkusTestMethodContext)protected voiddoPostSetup()Strategy to perform any post setup afterCamelContextis createdprotected voiddoPreSetup()Strategy to perform any pre setup, beforeCamelContextis createdprotected voiddoQuarkusCheck()Allows running of the CamelTestSupport child in the Quarkus application.protected voiddoStopCamelContext(org.apache.camel.CamelContext context, org.apache.camel.Service camelContextService)Internal disablement of the context stop functionality.(package private) voidinternalAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context)(package private) voidinternalBeforeAll(org.junit.jupiter.api.extension.ExtensionContext context)(package private) voidinternalBeforeEach(org.junit.jupiter.api.extension.ExtensionContext context)booleanisUseAdviceWith()Override when using advice with and return true.protected voidpostProcessTest()The same functionality asCamelTestSupport.postProcessTest().protected voidstartCamelContext()This method does nothing.protected voidstartRouteDefinitions()Helper method to start routeDefinitions (to be used with `adviceWith`).protected voidstopCamelContext()This method stops the Camel context.-
Methods inherited from class org.apache.camel.test.junit5.CamelTestSupport
applyCamelPostProcessor, assertExpression, assertMockEndpointsSatisfied, assertMockEndpointsSatisfied, assertPredicate, assertResolveLanguage, assertValidContext, beforeTestExecution, camelContextService, cleanupResources, consumer, createExchangeWithBody, createRouteBuilder, createRouteBuilders, debugAfter, debugBefore, deleteTestDirectory, disableJMX, doPostTearDown, doSetUp, doSpringBootCheck, enableJMX, fileUri, fileUri, fluentTemplate, getCamelContextService, getCurrentTestName, getMandatoryEndpoint, getMandatoryEndpoint, getMockEndpoint, getMockEndpoint, getRouteFilterExcludePattern, getRouteFilterIncludePattern, getShutdownTimeout, hasClassAnnotation, ignoreMissingLocationWithPropertiesComponent, isCreateCamelContextPerClass, isDumpRouteCoverage, isMockEndpoints, isMockEndpointsAndSkip, isUseDebugger, isUseRouteBuilder, replaceRouteFromWith, resetMocks, resolveMandatoryEndpoint, resolveMandatoryEndpoint, sendBodies, sendBody, sendBody, setCamelContextService, setUp, setupResources, setUseRouteBuilder, tearDown, template, testDirectory, testDirectory, testDirectory, testDirectory, testDirectory, testFile, timeTaken, useJmx, useOverridePropertiesWithPropertiesComponent
-
-
-
-
Method Detail
-
doAfterAll
protected void doAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context) throws ExceptionReplacement ofafterAll(ExtensionContext)called fromAfterAllCallback.afterAll(QuarkusTestContext)- Throws:
Exception
-
doAfterEach
protected void doAfterEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) throws ExceptionReplacement ofafterEach(ExtensionContext)called fromAfterEachCallback.afterEach(QuarkusTestMethodContext)- Throws:
Exception
-
doAfterConstruct
protected void doAfterConstruct() throws ExceptionReplacement ofbeforeAll(ExtensionContext)called fromAfterConstructCallback.afterConstruct(Object)Execution differs in case of @TestInstance(TestInstance.Lifecycle.PER_METHOD) in which case callback is called before each test (instead ofbeforeAll(ExtensionContext)).- Throws:
Exception
-
doBeforeEach
protected void doBeforeEach(io.quarkus.test.junit.callback.QuarkusTestMethodContext context) throws ExceptionReplacement ofbeforeEach(ExtensionContext)called fromBeforeEachCallback.beforeEach(QuarkusTestMethodContext)- Throws:
Exception
-
createCamelContext
protected org.apache.camel.CamelContext createCamelContext() throws ExceptionFeel 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.- Overrides:
createCamelContextin classorg.apache.camel.test.junit5.CamelTestSupport- Returns:
- The context from Quarkus CDI container
- Throws:
Exception- Overridden method has to throw the same Exception as superclass.
-
bindToRegistry
protected void bindToRegistry(org.apache.camel.spi.Registry registry) throws ExceptionThe same functionality asCamelTestSupport.bindToRegistry(Registry).- Overrides:
bindToRegistryin classorg.apache.camel.test.junit5.CamelTestSupport- Throws:
Exception
-
postProcessTest
protected void postProcessTest() throws ExceptionThe same functionality asCamelTestSupport.postProcessTest().- Overrides:
postProcessTestin classorg.apache.camel.test.junit5.CamelTestSupport- Throws:
Exception
-
context
public org.apache.camel.CamelContext context()
The same functionality asCamelTestSupport.context().- Overrides:
contextin classorg.apache.camel.test.junit5.CamelTestSupport
-
createCamelRegistry
protected final org.apache.camel.spi.Registry createCamelRegistry()
This method is not called on Camel Quarkus because the `CamelRegistry` is created and owned by Quarkus CDI container. If you need to customize the registry upon creation, you may want to overridecreateCamelContext()in the following way:@Override protected CamelContext createCamelContext() throws Exception { CamelContext ctx = super.createCamelContext(); Registry registry = ctx.getRegistry(); // do something with the registry... return ctx; }- Overrides:
createCamelRegistryin classorg.apache.camel.test.junit5.CamelTestSupport- Returns:
- Never returns any result. UnsupportedOperationException is thrown instead.
-
beforeAll
public final void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
This method does nothing. All necessary tasks are performed inBeforeEachCallback.beforeEach(QuarkusTestMethodContext)UsedoAfterConstruct()instead of this method.- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Overrides:
beforeAllin classorg.apache.camel.test.junit5.CamelTestSupport
-
beforeEach
public final void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws ExceptionThis method does nothing. All tasks are performed inBeforeEachCallback.beforeEach(QuarkusTestMethodContext)UsedoBeforeEach(QuarkusTestMethodContext)instead of this method.- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Overrides:
beforeEachin classorg.apache.camel.test.junit5.CamelTestSupport- Throws:
Exception
-
afterAll
public final void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
This method does nothing. All necessary tasks are performed inBeforeEachCallback.beforeEach(QuarkusTestMethodContext)UsedoAfterAll(QuarkusTestContext)instead of this method.- Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback- Overrides:
afterAllin classorg.apache.camel.test.junit5.CamelTestSupport
-
afterEach
public final void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws ExceptionThis method does nothing. All necessary tasks are performed inBeforeEachCallback.beforeEach(QuarkusTestMethodContext)UsedoAfterEach(QuarkusTestMethodContext)instead of this method.- Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback- Overrides:
afterEachin classorg.apache.camel.test.junit5.CamelTestSupport- Throws:
Exception
-
afterTestExecution
public final void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) throws ExceptionThis method does nothing All necessary tasks are performed inBeforeEachCallback.beforeEach(QuarkusTestMethodContext)UsedoAfterEach(QuarkusTestMethodContext)instead of this method.- Specified by:
afterTestExecutionin interfaceorg.junit.jupiter.api.extension.AfterTestExecutionCallback- Overrides:
afterTestExecutionin classorg.apache.camel.test.junit5.CamelTestSupport- Throws:
Exception
-
stopCamelContext
protected void stopCamelContext() throws ExceptionThis method stops the Camel context. Be aware that on of the limitation that Quarkus brings is that context can not be started (lifecycle f the context is bound to the application) .- Overrides:
stopCamelContextin classorg.apache.camel.test.junit5.CamelTestSupport- Throws:
Exception
-
doQuarkusCheck
protected final void doQuarkusCheck()
Allows running of the CamelTestSupport child in the Quarkus application. Method is not intended to be overridden.- Overrides:
doQuarkusCheckin classorg.apache.camel.test.junit5.CamelTestSupport
-
internalAfterAll
void internalAfterAll(io.quarkus.test.junit.callback.QuarkusTestContext context)
-
internalBeforeAll
void internalBeforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
-
internalBeforeEach
void internalBeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception- Throws:
Exception
-
doPreSetup
protected void doPreSetup() throws ExceptionStrategy to perform any pre setup, beforeCamelContextis createdBe aware that difference in lifecycle with Quarkus may require a special behavior. If this method is overridden, super.doPreSetup() has to be called.
- Overrides:
doPreSetupin classorg.apache.camel.test.junit5.CamelTestSupport- Throws:
Exception
-
doPostSetup
protected void doPostSetup() throws ExceptionStrategy to perform any post setup afterCamelContextis createdBe aware that difference in lifecycle with Quarkus may require a special behavior. If this method is overridden, super.doPostSetup() has to be called.
- Overrides:
doPostSetupin classorg.apache.camel.test.junit5.CamelTestSupport- Throws:
Exception
-
doStopCamelContext
protected final void doStopCamelContext(org.apache.camel.CamelContext context, org.apache.camel.Service camelContextService)Internal disablement of the context stop functionality.- Overrides:
doStopCamelContextin classorg.apache.camel.test.junit5.CamelTestSupport
-
startCamelContext
protected final void startCamelContext()
This method does nothing. The context starts together with Quarkus engine.- Overrides:
startCamelContextin classorg.apache.camel.test.junit5.CamelTestSupport
-
isUseAdviceWith
public boolean isUseAdviceWith()
Override when using advice with and return true. This helps knowing advice with is to be used. Important: Its important to execute methodstartRouteDefinitions()} manually from the unit test after you are done doing all the advice with.- Overrides:
isUseAdviceWithin classorg.apache.camel.test.junit5.CamelTestSupport- Returns:
- true if you use advice with in your unit tests.
-
-