Class 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.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

        camelContextService, camelTestSupportExtension, consumer, context, extra, fluentTemplate, ROUTE_COVERAGE_ENABLED, template
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void applyCamelPostProcessor()  
      protected void bindToRegistryAfterInjections​(org.apache.camel.spi.Registry registry)
      Override this method to bind custom beans to the Camel Registry like the method CamelTestSupport.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 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.
      protected org.apache.camel.CamelContext createCamelContext()  
      protected Class<?> getMainClass()
      Allows to specify the main class of the application to test if needed in order to simulate the same behavior as with Main(Class).
      protected String getPropertyPlaceholderFileName()
      Gives the file name of the property placeholder to use for the test.
      protected String getPropertyPlaceholderLocations()
      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
    • Constructor Detail

      • CamelMainTestSupport

        public CamelMainTestSupport()
    • 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 Exception
        Override this method to bind custom beans to the Camel Registry like the method CamelTestSupport.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 CustomGreetings could be created from the value of property name and is used to replace the bean of type Greetings automatically 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 non null value otherwise it uses the default property placeholder location corresponding to the file application.properties available 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 is com.company.SomeTest and this method has been overridden to return some-app.properties, then it assumes that the actual possible locations of the property placeholder are classpath:com/company/some-app.properties;optional=true,classpath:some-app.properties;optional=true which 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. null by 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 with Main(Class).
        Returns:
        the main class of the application to test if any. null by default indicating that there is no specific main class.
      • createCamelContext

        protected org.apache.camel.CamelContext createCamelContext()
                                                            throws Exception
        Overrides:
        createCamelContext in class org.apache.camel.test.junit5.CamelTestSupport
        Throws:
        Exception
      • applyCamelPostProcessor

        protected void applyCamelPostProcessor()
                                        throws Exception
        Overrides:
        applyCamelPostProcessor in class org.apache.camel.test.junit5.CamelTestSupport
        Throws:
        Exception