Class CamelMainTestSupport
- java.lang.Object
-
- org.apache.camel.test.junit5.CamelTestSupport
-
- org.apache.camel.test.main.junit5.CamelMainTestSupport
-
- All Implemented Interfaces:
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 abstract class CamelMainTestSupport extends org.apache.camel.test.junit5.CamelTestSupportThe base class of all the test classes that are meant to test a Camel Main application.
-
-
Constructor Summary
Constructors Constructor Description CamelMainTestSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidapplyCamelPostProcessor()protected voidbindToRegistryAfterInjections(org.apache.camel.spi.Registry registry)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.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.CamelContextcreateCamelContext()protected Class<?>getMainClass()Allows to specify the main class of the application to test if needed in order to simulate the same behavior as withMain(Class).protected StringgetPropertyPlaceholderFileName()Gives the file name of the property placeholder to use for the test.protected StringgetPropertyPlaceholderLocations()Gives a comma separated list of the property placeholder locations to use for the test.-
Methods inherited from class org.apache.camel.test.junit5.CamelTestSupport
afterAll, afterEach, afterTestExecution, assertExpression, assertMockEndpointsSatisfied, assertMockEndpointsSatisfied, assertPredicate, assertResolveLanguage, assertValidContext, beforeAll, beforeEach, beforeTestExecution, bindToRegistry, camelContextService, cleanupResources, consumer, context, createCamelRegistry, createExchangeWithBody, createRouteBuilder, createRouteBuilders, debugAfter, debugBefore, deleteTestDirectory, disableJMX, doPostSetup, doPostTearDown, doPreSetup, doSpringBootCheck, enableJMX, fileUri, fileUri, fluentTemplate, getCamelContextService, getCurrentTestName, getMandatoryEndpoint, getMandatoryEndpoint, getMockEndpoint, getMockEndpoint, getRouteFilterExcludePattern, getRouteFilterIncludePattern, getShutdownTimeout, hasClassAnnotation, ignoreMissingLocationWithPropertiesComponent, isCreateCamelContextPerClass, isDumpRouteCoverage, isMockEndpoints, isMockEndpointsAndSkip, isUseAdviceWith, isUseDebugger, isUseRouteBuilder, postProcessTest, replaceRouteFromWith, resetMocks, resolveMandatoryEndpoint, resolveMandatoryEndpoint, sendBodies, sendBody, sendBody, setCamelContextService, setUp, setupResources, setUseRouteBuilder, startCamelContext, stopCamelContext, tearDown, template, testDirectory, testDirectory, testDirectory, testDirectory, testDirectory, testFile, timeTaken, useJmx, useOverridePropertiesWithPropertiesComponent
-
-
-
-
Method Detail
-
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
protected void bindToRegistryAfterInjections(org.apache.camel.spi.Registry registry) throws ExceptionOverride 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
protected String 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
protected String 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
protected Class<?> getMainClass()
Allows to specify the main class of the application to test if needed in order 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
protected org.apache.camel.CamelContext createCamelContext() throws Exception- Overrides:
createCamelContextin classorg.apache.camel.test.junit5.CamelTestSupport- Throws:
Exception
-
-