Class CamelMainTestSupport
java.lang.Object
org.apache.camel.test.junit5.AbstractTestSupport
org.apache.camel.test.junit5.CamelTestSupport
org.apache.camel.test.main.junit5.CamelMainTestSupport
- All Implemented Interfaces:
org.apache.camel.test.junit5.CommonTestSupport,org.apache.camel.test.junit5.ConfigurableContext,org.apache.camel.test.junit5.ConfigurableTest,org.junit.jupiter.api.extension.AfterTestExecutionCallback,org.junit.jupiter.api.extension.BeforeTestExecutionCallback,org.junit.jupiter.api.extension.Extension
public abstract class CamelMainTestSupport
extends org.apache.camel.test.junit5.CamelTestSupport
The base class of all the test classes that are meant to test a Camel Main application.
-
Field Summary
Fields inherited from class org.apache.camel.test.junit5.CamelTestSupport
camelTestSupportExtension, contextManagerExtension, testLoggerExtensionFields inherited from class org.apache.camel.test.junit5.AbstractTestSupport
camelContextConfiguration, consumer, context, fluentTemplate, template, testConfigurationBuilder -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbindToRegistryAfterInjections(org.apache.camel.spi.Registry registry) Deprecated.protected voidconfigure(org.apache.camel.main.MainConfigurationProperties configuration) Override this method to be able to configure the Camel for the test like a Camel Main application.protected org.apache.camel.CamelContextprotected Class<?> Allows specifying the main class of the application to test if needed to simulate the same behavior as withMain(Class).protected StringGives the file name of the property placeholder to use for the test.protected StringGives a comma separated list of the property placeholder locations to use for the test.Methods inherited from class org.apache.camel.test.junit5.CamelTestSupport
afterTestExecution, applyCamelPostProcessor, assertExpression, assertPredicate, assertResolveLanguage, assertValidContext, beforeTestExecution, bindToRegistry, configureContext, configureTest, createCamelRegistry, createExchangeWithBody, createRouteBuilder, createRouteBuilders, debugAfter, debugBefore, doPostSetup, doPostTearDown, doPreSetup, doQuarkusCheck, doSetUp, doSpringBootCheck, expression, getCurrentTestName, getMandatoryEndpoint, getMandatoryEndpoint, getMockEndpoint, getMockEndpoint, getShutdownTimeout, hasClassAnnotation, postProcessTest, resolveMandatoryEndpoint, resolveMandatoryEndpoint, sendBodies, sendBody, sendBody, setUp, startCamelContext, stopCamelContext, tearDown, timeTaken, unsupportedCheckMethods inherited from class org.apache.camel.test.junit5.AbstractTestSupport
camelContextConfiguration, camelContextService, cleanupResources, consumer, context, disableJMX, enableJMX, fluentTemplate, getCamelContextService, getDumpRoute, getRouteFilterExcludePattern, getRouteFilterIncludePattern, ignoreMissingLocationWithPropertiesComponent, isAutoStartupExcludePatterns, isCreateCamelContextPerClass, isDumpRouteCoverage, isMockEndpoints, isMockEndpointsAndSkip, isRouteCoverageEnabled, isStubEndpoints, isUseAdviceWith, isUseDebugger, isUseRouteBuilder, replaceRouteFromWith, setCamelContextService, setContext, setupResources, setUseRouteBuilder, template, testConfiguration, useJmx, useOverridePropertiesWithPropertiesComponent
-
Constructor Details
-
CamelMainTestSupport
public CamelMainTestSupport()
-
-
Method Details
-
configure
protected void configure(org.apache.camel.main.MainConfigurationProperties configuration) Override this method to be able to configure the Camel for the test like a Camel Main application.- Parameters:
configuration- the Global configuration for Camel Main.
-
bindToRegistryAfterInjections
@Deprecated protected void bindToRegistryAfterInjections(org.apache.camel.spi.Registry registry) throws Exception Deprecated.Override this method to bind custom beans to the CamelRegistrylike the methodCamelTestSupport.bindToRegistry(Registry)but after all possible injections and automatic binding have been done which for example allows to create the custom beans based on injected objects like properties but also allows to replace a bean automatically created and bound by Camel.In the next example, an instance of a custom bean of type
CustomGreetingscould be created from the value of propertynameand is used to replace the bean of typeGreetingsautomatically bound by Camel with the name myGreetings.class ReplaceBeanTest extends CamelMainTestSupport { @PropertyInject("name") String name; @Override protected void bindToRegistryAfterInjections(Registry registry) throws Exception { registry.bind("myGreetings", Greetings.class, new CustomGreetings(name)); } // Rest of the test class }- Parameters:
registry- the registry in which the custom beans are bound.- Throws:
Exception- if an error occurs while binding a custom bean.
-
getPropertyPlaceholderLocations
Gives a comma separated list of the property placeholder locations to use for the test. In case a property is defined at several property placeholder locations, the value of this property in the first property placeholder location according to the order in the list is used. In other words, the value of the properties defined in the first location of the property placeholder in the list takes precedence over the value of the properties of the following location of the property placeholder and so on.By default, it tries to get the inferred locations from the method
getPropertyPlaceholderFileName()in case it returns a nonnullvalue otherwise it uses the default property placeholder location corresponding to the fileapplication.propertiesavailable from the default package.- Returns:
- the property placeholder locations to use for the test.
-
getPropertyPlaceholderFileName
Gives the file name of the property placeholder to use for the test. This method assumes that the file is located either in the package of the test class or directly in the default package. In other words, if the test class iscom.company.SomeTestand this method has been overridden to returnsome-app.properties, then it assumes that the actual possible locations of the property placeholder areclasspath:com/company/some-app.properties;optional=true,classpath:some-app.properties;optional=truewhich means that for each property to find, it tries to get it first from the properties file of the same package if it exists and if it cannot be found, it tries to get it from the properties file with the same name but in the default package if it exists.Note: Since the properties files are declared as optional, no exception is raised if they are both absent.
- Returns:
- the file name of the property placeholder located in the same package as the test class or directly in
the default package.
nullby default.
-
getMainClass
Allows specifying the main class of the application to test if needed to simulate the same behavior as withMain(Class).- Returns:
- the main class of the application to test if any.
nullby default indicating that there is no specific main class.
-
createCamelContext
- Overrides:
createCamelContextin classorg.apache.camel.test.junit5.CamelTestSupport- Throws:
Exception
-